ClpDsaValidationParameters.pas 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. { *********************************************************************************** }
  2. { * CryptoLib Library * }
  3. { * Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe * }
  4. { * Github Repository <https://github.com/Xor-el> * }
  5. { * Distributed under the MIT software license, see the accompanying file LICENSE * }
  6. { * or visit http://www.opensource.org/licenses/mit-license.php. * }
  7. { * Acknowledgements: * }
  8. { * * }
  9. { * Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring * }
  10. { * development of this library * }
  11. { * ******************************************************************************* * }
  12. (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
  13. unit ClpDsaValidationParameters;
  14. {$I CryptoLib.inc}
  15. interface
  16. uses
  17. ClpIDsaValidationParameters,
  18. ClpArrayUtils,
  19. ClpCryptoLibTypes;
  20. resourcestring
  21. SSeedNil = '"Seed" Cannot Be Nil';
  22. type
  23. TDsaValidationParameters = class(TInterfacedObject, IDsaValidationParameters)
  24. strict private
  25. var
  26. Fseed: TCryptoLibByteArray;
  27. Fcounter, FusageIndex: Int32;
  28. function GetCounter: Int32; virtual;
  29. function GetUsageIndex: Int32; virtual;
  30. function GetSeed: TCryptoLibByteArray; virtual;
  31. public
  32. constructor Create(const seed: TCryptoLibByteArray;
  33. counter: Int32); overload;
  34. constructor Create(const seed: TCryptoLibByteArray;
  35. counter, usageIndex: Int32); overload;
  36. function Equals(const other: IDsaValidationParameters): Boolean;
  37. reintroduce;
  38. function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
  39. {$ENDIF DELPHI}override;
  40. property counter: Int32 read GetCounter;
  41. property usageIndex: Int32 read GetUsageIndex;
  42. property seed: TCryptoLibByteArray read GetSeed;
  43. end;
  44. implementation
  45. { TDsaValidationParameters }
  46. constructor TDsaValidationParameters.Create(const seed: TCryptoLibByteArray;
  47. counter: Int32);
  48. begin
  49. Create(seed, counter, -1);
  50. end;
  51. constructor TDsaValidationParameters.Create(const seed: TCryptoLibByteArray;
  52. counter, usageIndex: Int32);
  53. begin
  54. Inherited Create();
  55. if (seed = Nil) then
  56. begin
  57. raise EArgumentNilCryptoLibException.CreateRes(@SSeedNil);
  58. end;
  59. Fseed := System.Copy(seed);
  60. Fcounter := counter;
  61. FusageIndex := usageIndex;
  62. end;
  63. function TDsaValidationParameters.Equals(const other
  64. : IDsaValidationParameters): Boolean;
  65. begin
  66. if other = Nil then
  67. begin
  68. result := False;
  69. Exit;
  70. end;
  71. if ((Self as IDsaValidationParameters) = other) then
  72. begin
  73. result := True;
  74. Exit;
  75. end;
  76. result := (counter = other.counter) and TArrayUtils.AreEqual(seed,
  77. other.seed);
  78. end;
  79. function TDsaValidationParameters.GetCounter: Int32;
  80. begin
  81. result := Fcounter;
  82. end;
  83. function TDsaValidationParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
  84. {$ENDIF DELPHI}
  85. begin
  86. result := counter xor TArrayUtils.GetArrayHashCode(seed);
  87. end;
  88. function TDsaValidationParameters.GetSeed: TCryptoLibByteArray;
  89. begin
  90. result := System.Copy(Fseed);
  91. end;
  92. function TDsaValidationParameters.GetUsageIndex: Int32;
  93. begin
  94. result := FusageIndex;
  95. end;
  96. end.