[fpc-pascal] SHA1 of a TMemoryStream

Jorge Aldo G. de F. Junior jagfj80 at gmail.com
Sun Mar 6 02:18:18 CET 2011


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 <marcov at 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 at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



More information about the fpc-pascal mailing list