@@ -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+
938961implementation
939962
940963uses
@@ -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
958992class function TDECHashAuthentication.IsPasswordHash : Boolean;
959993begin
@@ -1656,4 +1690,22 @@ function TDECPasswordHash.IsValidPassword(Password : TBytes;
16561690 Result := false;
16571691end ;
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+
16591711end .
0 commit comments