This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.
Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.
Project: MD5 Message Digest Unit
Unit: PJMD5
Class: TPJMD5
Applies to: ~>1.0
class operator Equal(const D1, D2: TPJMD5Digest): Boolean;
class operator Equal(const D: TPJMD5Digest; const B: TBytes): Boolean;
class operator Equal(const B: TBytes; const D: TPJMD5Digest): Boolean;
class operator Equal(const D: TPJMD5Digest; const S: string): Boolean;
class operator Equal(const S: string; const D: TPJMD5Digest): Boolean;
TPJMD5Digest defines five overloads of the =
operator that permit TPJMD5Digest variables to be tested for equality with:
Two TPJMD5Digest records are considered equal if all elements of their LongWords array fields are the same.
var
D1, D2: TPJMD5Digest;
begin
D1 := TPJMD5.Calculate('Foo');
D2 := TPJMD5.Calculate('Foo');
Assert(D1 = D2);
Assert(D2 = D1);
end;
A TPJMD5Digest record is considered equal to a Unicode string if:
A
to F
are permitted) – andconst
S = 'd174ab98d277d9f5a5611c2c9f419d9f';
D: TPJMD5Digest = (
Bytes: (
$D1, $74, $AB, $98, $D2, $77, $D9, $F5,
$A5, $61, $1C, $2C, $9F, $41, $9D, $9F
)
);
begin
Assert(S = D);
Assert(D = S);
end;
A TPJMD5Digest record is considered equal to a TBytes array if:
const
D: TPJMD5Digest = (
Bytes: (
$D1, $74, $AB, $98, $D2, $77, $D9, $F5,
$A5, $61, $1C, $2C, $9F, $41, $9D, $9F
)
);
var
A: TBytes;
begin
A := TBytes.Create(
$D1, $74, $AB, $98, $D2, $77, $D9, $F5,
$A5, $61, $1C, $2C, $9F, $41, $9D, $9F
);
Assert(A = D);
Assert(D = A);
end;
Although a byte array with more than 16 elements can be assigned to a TPJMD5Digest, the two items do not compare equal:
var
D: TPJMD5Digest;
A: TBytes;
begin
A := TBytes.Create(
$D1, $74, $AB, $98, $D2, $77, $D9, $F5,
$A5, $61, $1C, $2C, $9F, $41, $9D, $9F,
$00, $FF // 18 elements
);
D := A;
Assert(not(D = A));
end;
This is because the “overflow” bytes from the byte array are discarded when assigning to the TPJMD5Digest record.