Skip to content

Commit 1e86332

Browse files
author
Markus Humm
committed
Added ValidAuthenticationHash and SetDefaultAuthenticationHashClass
In order to make upgrading from DEC 5.x easier.
1 parent a54d7f2 commit 1e86332

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Source/DECHashAuthentication.pas

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,29 @@ TDECHashAuthenticationClass = class of TDECHashAuthentication;
935935
/// </summary>
936936
TDECHashExtendedClass = class of TDECHashExtended;
937937

938+
/// <summary>
939+
/// Returns the passed class type if it is not nil. Otherwise the class type
940+
/// of the TFormat_Copy class is being returned.
941+
/// </summary>
942+
/// <param name="FormatClass">
943+
/// Class type of a formatting class like TFormat_HEX or nil, if no formatting
944+
/// is desired.
945+
/// </param>
946+
/// <returns>
947+
/// Passed class type or TFormat_Copy class type, depending on FormatClass
948+
/// parameter value.
949+
/// </returns>
950+
function ValidAuthenticationHash(HashClass: TDECHashClass): TDECHashAuthenticationClass;
951+
/// <summary>
952+
/// Defines which hash class to return by ValidAuthenticationHash if passing
953+
/// nil to that
954+
/// </summary>
955+
/// <param name="HashClass">
956+
/// Class type of a Hash class to return by ValidAuthenticationHash if
957+
/// passing nil to that one. This parameter should not be nil!
958+
/// </param>
959+
procedure SetDefaultAuthenticationHashClass(HashClass: TDECHashClass);
960+
938961
implementation
939962

940963
uses
@@ -954,6 +977,17 @@ implementation
954977
/// not supported.
955978
/// </summary>
956979
sCryptIDNotRegistered = 'No class for crypt ID %s registered';
980+
/// <summary>
981+
/// Exception message used when no default class has been defined
982+
/// </summary>
983+
sAuthHashNoDefault = 'No default authentication hash class has been registered';
984+
985+
var
986+
/// <summary>
987+
/// Hash class returned by ValidAuthenticationHash if nil is passed as
988+
/// parameter to it
989+
/// </summary>
990+
FDefaultAutheticationHashClass: TDECHashAuthenticationClass = nil;
957991

958992
class function TDECHashAuthentication.IsPasswordHash: Boolean;
959993
begin
@@ -1656,4 +1690,22 @@ function TDECPasswordHash.IsValidPassword(Password : TBytes;
16561690
Result := false;
16571691
end;
16581692

1693+
function ValidAuthenticationHash(HashClass: TDECHashClass): TDECHashAuthenticationClass;
1694+
begin
1695+
if Assigned(HashClass) then
1696+
Result := TDECHashAuthenticationClass(HashClass)
1697+
else
1698+
Result := FDefaultAutheticationHashClass;
1699+
1700+
if not Assigned(Result) then
1701+
raise EDECHashException.CreateRes(@sAuthHashNoDefault);
1702+
end;
1703+
1704+
procedure SetDefaultAuthenticationHashClass(HashClass: TDECHashClass);
1705+
begin
1706+
Assert(Assigned(HashClass), 'Do not set a nil default hash class!');
1707+
1708+
FDefaultAutheticationHashClass := TDECHashAuthenticationClass(HashClass);
1709+
end;
1710+
16591711
end.

0 commit comments

Comments
 (0)