@@ -200,7 +200,7 @@ TFixedBytePadding = class abstract(TPadding)
200
200
// / <returns>
201
201
// / True, if block size is expected otherwise false.
202
202
// / </returns>
203
- class function IsBlockSizeValid (BlockSize: integer ): boolean ; virtual ; abstract ;
203
+ class function IsBlockSizeValid (BlockSize: Integer ): Boolean ; virtual ; abstract ;
204
204
205
205
// / <summary>
206
206
// / Calculated the length of the pad.
@@ -214,7 +214,7 @@ TFixedBytePadding = class abstract(TPadding)
214
214
// / <returns>
215
215
// / Length of padding.
216
216
// / </returns>
217
- class function GetPadLength (DataSize, BlockSize: integer ): integer ; virtual ; abstract ;
217
+ class function GetPadLength (DataSize, BlockSize: Integer ): Integer ; virtual ; abstract ;
218
218
219
219
// / <summary>
220
220
// / Retrieves the padding character used to fill up the last block(s).
@@ -228,8 +228,8 @@ TFixedBytePadding = class abstract(TPadding)
228
228
// / <returns>
229
229
// / The byte value used as padding
230
230
// / </returns>
231
- class function GetPaddingByte (PaddingLength : Integer;
232
- IsLastPaddingByte: boolean ): UInt8; virtual ; abstract ;
231
+ class function GetPaddingByte (PaddingLength : Integer;
232
+ IsLastPaddingByte : Boolean ): UInt8; virtual ; abstract ;
233
233
public
234
234
// / <summary>
235
235
// / Adds padding to the specified data, depending on the padding byte
@@ -244,7 +244,8 @@ TFixedBytePadding = class abstract(TPadding)
244
244
// / <returns>
245
245
// / The padded data following the algorithm implemented by the derrived class.
246
246
// / </returns>
247
- class function AddPadding (const Data: TBytes; BlockSize: Integer): TBytes; override;
247
+ class function AddPadding (const Data : TBytes;
248
+ BlockSize : Integer): TBytes; override;
248
249
249
250
// <summary>
250
251
// / Adds padding to the specified string, depending on the padding byte
@@ -263,7 +264,8 @@ TFixedBytePadding = class abstract(TPadding)
263
264
// / <remarks>
264
265
// / Call this method before starting encryption.
265
266
// / </remarks>
266
- class function AddPadding (const Data: string; BlockSize: Integer): string; override;
267
+ class function AddPadding (const Data : string;
268
+ BlockSize : Integer): string; override;
267
269
268
270
// <summary>
269
271
// / Adds padding to the specified raw byte string, depending on the padding
@@ -404,7 +406,7 @@ TPKCS7Padding = class(TFixedBytePadding)
404
406
// / Length of padding. Can not be zero. When the DataSize is a multiply of
405
407
// / the BlockSize the method returns the BlockSize.
406
408
// / </returns>
407
- class function GetPadLength (DataSize, BlockSize: integer ): integer ; override;
409
+ class function GetPadLength (DataSize, BlockSize: Integer ): Integer ; override;
408
410
409
411
// / <summary>
410
412
// / Check if block size is supported by the concerete padding algorithm.
@@ -415,7 +417,7 @@ TPKCS7Padding = class(TFixedBytePadding)
415
417
// / <returns>
416
418
// / True, if block size is in expected range of 1..255, otherwise false.
417
419
// / </returns>
418
- class function IsBlockSizeValid (BlockSize: integer ): boolean ; override;
420
+ class function IsBlockSizeValid (BlockSize: Integer ): Boolean ; override;
419
421
420
422
// / <summary>
421
423
// / Retrieves the padding character used to fill up the last block(s).
@@ -429,8 +431,8 @@ TPKCS7Padding = class(TFixedBytePadding)
429
431
// / <returns>
430
432
// / The byte value used as padding
431
433
// / </returns>
432
- class function GetPaddingByte (PaddingLength : Integer;
433
- IsLastPaddingByte: boolean ): UInt8; override;
434
+ class function GetPaddingByte (PaddingLength : Integer;
435
+ IsLastPaddingByte : Boolean ): UInt8; override;
434
436
end ;
435
437
436
438
// / <summary>
@@ -447,7 +449,7 @@ TPKCS5Padding = class(TPKCS7Padding)
447
449
// / <returns>
448
450
// / True, if block size is in expected range of 1..255, otherwise false.
449
451
// / </returns>
450
- class function IsBlockSizeValid (BlockSize: integer ): boolean ; override;
452
+ class function IsBlockSizeValid (BlockSize: Integer ): Boolean ; override;
451
453
end ;
452
454
453
455
// / <summary>
@@ -478,7 +480,7 @@ TANSI_X9_23_Padding = class(TFixedBytePadding)
478
480
// / Length of padding. Can be zero when the DataSize is a multiply of
479
481
// / the BlockSize.
480
482
// / </returns>
481
- class function GetPadLength (DataSize, BlockSize: integer ): integer ; override;
483
+ class function GetPadLength (DataSize, BlockSize: Integer ): Integer ; override;
482
484
483
485
// / <summary>
484
486
// / Check if block size is supported by the concerete padding algorithm.
@@ -489,7 +491,7 @@ TANSI_X9_23_Padding = class(TFixedBytePadding)
489
491
// / <returns>
490
492
// / True, if block size is > 0, otherwise false.
491
493
// / </returns>
492
- class function IsBlockSizeValid (BlockSize: integer ): boolean ; override;
494
+ class function IsBlockSizeValid (BlockSize: Integer ): Boolean ; override;
493
495
// / <summary>
494
496
// / Retrieves the padding character used to fill up the last block(s).
495
497
// / </summary>
@@ -502,8 +504,8 @@ TANSI_X9_23_Padding = class(TFixedBytePadding)
502
504
// / <returns>
503
505
// / The byte value used as padding
504
506
// / </returns>
505
- class function GetPaddingByte (PaddingLength : Integer;
506
- IsLastPaddingByte: boolean ): UInt8; override;
507
+ class function GetPaddingByte (PaddingLength : Integer;
508
+ IsLastPaddingByte : Boolean ): UInt8; override;
507
509
public
508
510
// / <summary>
509
511
// / Validates if the specified data contains valid padding as defined by
@@ -524,7 +526,7 @@ TANSI_X9_23_Padding = class(TFixedBytePadding)
524
526
// / here.
525
527
// / </returns>
526
528
class function HasValidPadding (const Data : TBytes;
527
- BlockSize : Integer): Boolean; override;
529
+ BlockSize : Integer): Boolean; override;
528
530
end ;
529
531
530
532
// ISO 10126 is smilar to ANSI X9.23 padding, but it uses a random padding
@@ -542,8 +544,8 @@ TISO10126Padding = class(TANSI_X9_23_Padding)
542
544
// / </param> /// <returns>
543
545
// / The byte value used as padding
544
546
// / </returns>
545
- class function GetPaddingByte (PaddingLength : Integer;
546
- IsLastPaddingByte: boolean ): UInt8; override;
547
+ class function GetPaddingByte (PaddingLength : Integer;
548
+ IsLastPaddingByte : Boolean ): UInt8; override;
547
549
end ;
548
550
549
551
TISO7816Padding = class (TFixedBytePadding)
@@ -561,7 +563,7 @@ TISO7816Padding = class(TFixedBytePadding)
561
563
// / Length of padding. Can not zero when the DataSize is a multiply of
562
564
// / the BlockSize.
563
565
// / </returns>
564
- class function GetPadLength (DataSize, BlockSize: integer ): integer ; override;
566
+ class function GetPadLength (DataSize, BlockSize: Integer ): Integer ; override;
565
567
public
566
568
// / <summary>
567
569
// / Adds padding to the specified data, depending on the padding byte
@@ -576,7 +578,8 @@ TISO7816Padding = class(TFixedBytePadding)
576
578
// / <returns>
577
579
// / The padded data following the algorithm implemented by the derrived class.
578
580
// / </returns>
579
- class function AddPadding (const Data: TBytes; BlockSize: Integer): TBytes; override;
581
+ class function AddPadding (const Data : TBytes;
582
+ BlockSize : Integer): TBytes; override;
580
583
581
584
// / <summary>
582
585
// / Validates if the specified data contains valid padding as defined by
@@ -618,7 +621,7 @@ implementation
618
621
DECUtil, DECRandom;
619
622
620
623
resourcestring
621
- sInvalidPadding = ' Invalid %0:s padding' ;
624
+ sInvalidPadding = ' Invalid %0:s padding' ;
622
625
sUnsupportedBlockSizeForPadding = ' Unsupported block size of %1:d for %0:s padding' ;
623
626
624
627
{ TFixedBytePadding }
@@ -632,7 +635,9 @@ class function TFixedBytePadding.AddPadding(const Data : TBytes;
632
635
if not IsBlockSizeValid(BlockSize) then
633
636
raise EDECCipherException.CreateResFmt(@sUnsupportedBlockSizeForPadding,
634
637
[ClassName, BlockSize]);
638
+
635
639
PadLength := GetPadLength(Length(Data), BlockSize);
640
+
636
641
SetLength(Result, Length(Data) + PadLength);
637
642
if Length(Data) > 0 then
638
643
Move(Data[0 ], Result[0 ], Length(Data));
@@ -723,12 +728,12 @@ class function TFixedBytePadding.RemovePadding(const Data : string;
723
728
class function TPKCS7Padding.GetPadLength (DataSize,
724
729
BlockSize: integer): integer;
725
730
begin
726
- result := BlockSize - (DataSize mod BlockSize);
731
+ Result := BlockSize - (DataSize mod BlockSize);
727
732
end ;
728
733
729
734
class function TPKCS7Padding.IsBlockSizeValid (BlockSize: integer): boolean;
730
735
begin
731
- result := (BlockSize > 0 ) and (BlockSize < 256 );
736
+ Result := (BlockSize > 0 ) and (BlockSize < 256 );
732
737
end ;
733
738
734
739
class function TPKCS7Padding.GetPaddingByte (PaddingLength: Integer;
@@ -741,14 +746,14 @@ class function TPKCS7Padding.GetPaddingByte(PaddingLength: Integer;
741
746
742
747
class function TPKCS5Padding.IsBlockSizeValid (BlockSize: integer): boolean;
743
748
begin
744
- result := BlockSize = 8 ;
749
+ Result := BlockSize = 8 ;
745
750
end ;
746
751
747
752
{ TANSI_X9_23_Padding }
748
753
749
754
class function TANSI_X9_23_Padding.IsBlockSizeValid (BlockSize: integer): boolean;
750
755
begin
751
- result := BlockSize > 0 ;
756
+ Result := BlockSize > 0 ;
752
757
end ;
753
758
754
759
class function TANSI_X9_23_Padding.GetPaddingByte (PaddingLength: Integer;
@@ -763,7 +768,7 @@ class function TANSI_X9_23_Padding.GetPaddingByte(PaddingLength: Integer;
763
768
class function TANSI_X9_23_Padding.GetPadLength (DataSize,
764
769
BlockSize: integer): integer;
765
770
begin
766
- result := DataSize mod BlockSize;
771
+ Result := DataSize mod BlockSize;
767
772
end ;
768
773
769
774
class function TANSI_X9_23_Padding.HasValidPadding (const Data: TBytes;
@@ -801,7 +806,7 @@ class function TISO10126Padding.GetPaddingByte(PaddingLength: Integer;
801
806
class function TISO7816Padding.GetPadLength (DataSize,
802
807
BlockSize: integer): integer;
803
808
begin
804
- result := DataSize mod BlockSize;
809
+ Result := DataSize mod BlockSize;
805
810
end ;
806
811
807
812
class function TISO7816Padding.AddPadding (const Data: TBytes;
@@ -813,10 +818,13 @@ class function TISO7816Padding.AddPadding(const Data: TBytes;
813
818
if not IsBlockSizeValid(BlockSize) then
814
819
raise EDECCipherException.CreateResFmt(@sUnsupportedBlockSizeForPadding,
815
820
[ClassName, BlockSize]);
821
+
816
822
PadLength := GetPadLength(Length(Data), BlockSize);
823
+
817
824
SetLength(Result, Length(Data) + PadLength);
818
825
if Length(Data) > 0 then
819
826
Move(Data[0 ], Result[0 ], Length(Data));
827
+
820
828
I := Length(Data);
821
829
Result[I] := $80 ;
822
830
for I := succ(Length(Data)) to High(Result) do
0 commit comments