Found the solution,

untyped var parameters expects a real variable so it "internally"
generates a pointer out of the address of the variable.

SHA1Buffer uses an untyped parameter, so, passing a pointer to it
makes it try to hash the pointer itself (and the rest of the memory
positioned exactly besides it, until data.size is meet).

The solution was to dereference the pointer :

SHA1Buffer(Data.Memory^, Data.Size); // damm little ^ !

Thanks !!

2011/3/5 Marco van de Voort <mar...@stack.nl>:
> In our previous episode, Jorge Aldo G. de F. Junior said:
>> Uses
>>       Classes,
>>       SHA1;
>>
>> Var
>>       Data : TMemoryStream;
>>       Hash : TSHA1Digest;
>>
>> Begin
>>       Data := TMemoryStream.Create;
>>       Data.LoadFromFile('test6.pas');
>
> Data.Position:=0;
>
>>       Hash := SHA1Buffer(Data.Memory, Data.Size);
>>       WriteLn(SHA1Print(Hash));
>>       Data.Free;
>> End.
>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to