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:
- The string is 32 characters long -- and
- The string contains only valid hexadecimal characters (both upper and lower case letters
A
toF
are permitted) -- and - The sequence of bytes represented by the string is the same as the bytes of the TPJMD5Digest record's Bytes field.
const
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:
- The byte array has 16 elements -- and
- The bytes of the byte array are the same as those of the TPJMD5Digest record's Bytes field.
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.
- NotEqual operator overloads