Skip to content

Commit adcc95a

Browse files
committed
Cosmetic changes
Some formatting changes in DECCipherPaddings.pas unit
1 parent 9142e51 commit adcc95a

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

Source/DECCipherPaddings.pas

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ TFixedBytePadding = class abstract(TPadding)
200200
/// <returns>
201201
/// True, if block size is expected otherwise false.
202202
/// </returns>
203-
class function IsBlockSizeValid(BlockSize: integer): boolean; virtual; abstract;
203+
class function IsBlockSizeValid(BlockSize: Integer): Boolean; virtual; abstract;
204204

205205
/// <summary>
206206
/// Calculated the length of the pad.
@@ -214,7 +214,7 @@ TFixedBytePadding = class abstract(TPadding)
214214
/// <returns>
215215
/// Length of padding.
216216
/// </returns>
217-
class function GetPadLength(DataSize, BlockSize: integer): integer; virtual; abstract;
217+
class function GetPadLength(DataSize, BlockSize: Integer): Integer; virtual; abstract;
218218

219219
/// <summary>
220220
/// Retrieves the padding character used to fill up the last block(s).
@@ -228,8 +228,8 @@ TFixedBytePadding = class abstract(TPadding)
228228
/// <returns>
229229
/// The byte value used as padding
230230
/// </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;
233233
public
234234
/// <summary>
235235
/// Adds padding to the specified data, depending on the padding byte
@@ -244,7 +244,8 @@ TFixedBytePadding = class abstract(TPadding)
244244
/// <returns>
245245
/// The padded data following the algorithm implemented by the derrived class.
246246
/// </returns>
247-
class function AddPadding(const Data: TBytes; BlockSize: Integer): TBytes; override;
247+
class function AddPadding(const Data : TBytes;
248+
BlockSize : Integer): TBytes; override;
248249

249250
// <summary>
250251
/// Adds padding to the specified string, depending on the padding byte
@@ -263,7 +264,8 @@ TFixedBytePadding = class abstract(TPadding)
263264
/// <remarks>
264265
/// Call this method before starting encryption.
265266
/// </remarks>
266-
class function AddPadding(const Data: string; BlockSize: Integer): string; override;
267+
class function AddPadding(const Data : string;
268+
BlockSize : Integer): string; override;
267269

268270
// <summary>
269271
/// Adds padding to the specified raw byte string, depending on the padding
@@ -404,7 +406,7 @@ TPKCS7Padding = class(TFixedBytePadding)
404406
/// Length of padding. Can not be zero. When the DataSize is a multiply of
405407
/// the BlockSize the method returns the BlockSize.
406408
/// </returns>
407-
class function GetPadLength(DataSize, BlockSize: integer): integer; override;
409+
class function GetPadLength(DataSize, BlockSize: Integer): Integer; override;
408410

409411
/// <summary>
410412
/// Check if block size is supported by the concerete padding algorithm.
@@ -415,7 +417,7 @@ TPKCS7Padding = class(TFixedBytePadding)
415417
/// <returns>
416418
/// True, if block size is in expected range of 1..255, otherwise false.
417419
/// </returns>
418-
class function IsBlockSizeValid(BlockSize: integer): boolean; override;
420+
class function IsBlockSizeValid(BlockSize: Integer): Boolean; override;
419421

420422
/// <summary>
421423
/// Retrieves the padding character used to fill up the last block(s).
@@ -429,8 +431,8 @@ TPKCS7Padding = class(TFixedBytePadding)
429431
/// <returns>
430432
/// The byte value used as padding
431433
/// </returns>
432-
class function GetPaddingByte(PaddingLength : Integer;
433-
IsLastPaddingByte: boolean): UInt8; override;
434+
class function GetPaddingByte(PaddingLength : Integer;
435+
IsLastPaddingByte : Boolean): UInt8; override;
434436
end;
435437

436438
/// <summary>
@@ -447,7 +449,7 @@ TPKCS5Padding = class(TPKCS7Padding)
447449
/// <returns>
448450
/// True, if block size is in expected range of 1..255, otherwise false.
449451
/// </returns>
450-
class function IsBlockSizeValid(BlockSize: integer): boolean; override;
452+
class function IsBlockSizeValid(BlockSize: Integer): Boolean; override;
451453
end;
452454

453455
/// <summary>
@@ -478,7 +480,7 @@ TANSI_X9_23_Padding = class(TFixedBytePadding)
478480
/// Length of padding. Can be zero when the DataSize is a multiply of
479481
/// the BlockSize.
480482
/// </returns>
481-
class function GetPadLength(DataSize, BlockSize: integer): integer; override;
483+
class function GetPadLength(DataSize, BlockSize: Integer): Integer; override;
482484

483485
/// <summary>
484486
/// Check if block size is supported by the concerete padding algorithm.
@@ -489,7 +491,7 @@ TANSI_X9_23_Padding = class(TFixedBytePadding)
489491
/// <returns>
490492
/// True, if block size is > 0, otherwise false.
491493
/// </returns>
492-
class function IsBlockSizeValid(BlockSize: integer): boolean; override;
494+
class function IsBlockSizeValid(BlockSize: Integer): Boolean; override;
493495
/// <summary>
494496
/// Retrieves the padding character used to fill up the last block(s).
495497
/// </summary>
@@ -502,8 +504,8 @@ TANSI_X9_23_Padding = class(TFixedBytePadding)
502504
/// <returns>
503505
/// The byte value used as padding
504506
/// </returns>
505-
class function GetPaddingByte(PaddingLength : Integer;
506-
IsLastPaddingByte: boolean): UInt8; override;
507+
class function GetPaddingByte(PaddingLength : Integer;
508+
IsLastPaddingByte : Boolean): UInt8; override;
507509
public
508510
/// <summary>
509511
/// Validates if the specified data contains valid padding as defined by
@@ -524,7 +526,7 @@ TANSI_X9_23_Padding = class(TFixedBytePadding)
524526
/// here.
525527
/// </returns>
526528
class function HasValidPadding(const Data : TBytes;
527-
BlockSize : Integer): Boolean; override;
529+
BlockSize : Integer): Boolean; override;
528530
end;
529531

530532
// 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)
542544
/// </param> /// <returns>
543545
/// The byte value used as padding
544546
/// </returns>
545-
class function GetPaddingByte(PaddingLength : Integer;
546-
IsLastPaddingByte: boolean): UInt8; override;
547+
class function GetPaddingByte(PaddingLength : Integer;
548+
IsLastPaddingByte : Boolean): UInt8; override;
547549
end;
548550

549551
TISO7816Padding = class(TFixedBytePadding)
@@ -561,7 +563,7 @@ TISO7816Padding = class(TFixedBytePadding)
561563
/// Length of padding. Can not zero when the DataSize is a multiply of
562564
/// the BlockSize.
563565
/// </returns>
564-
class function GetPadLength(DataSize, BlockSize: integer): integer; override;
566+
class function GetPadLength(DataSize, BlockSize: Integer): Integer; override;
565567
public
566568
/// <summary>
567569
/// Adds padding to the specified data, depending on the padding byte
@@ -576,7 +578,8 @@ TISO7816Padding = class(TFixedBytePadding)
576578
/// <returns>
577579
/// The padded data following the algorithm implemented by the derrived class.
578580
/// </returns>
579-
class function AddPadding(const Data: TBytes; BlockSize: Integer): TBytes; override;
581+
class function AddPadding(const Data : TBytes;
582+
BlockSize : Integer): TBytes; override;
580583

581584
/// <summary>
582585
/// Validates if the specified data contains valid padding as defined by
@@ -618,7 +621,7 @@ implementation
618621
DECUtil, DECRandom;
619622

620623
resourcestring
621-
sInvalidPadding = 'Invalid %0:s padding';
624+
sInvalidPadding = 'Invalid %0:s padding';
622625
sUnsupportedBlockSizeForPadding = 'Unsupported block size of %1:d for %0:s padding';
623626

624627
{ TFixedBytePadding }
@@ -632,7 +635,9 @@ class function TFixedBytePadding.AddPadding(const Data : TBytes;
632635
if not IsBlockSizeValid(BlockSize) then
633636
raise EDECCipherException.CreateResFmt(@sUnsupportedBlockSizeForPadding,
634637
[ClassName, BlockSize]);
638+
635639
PadLength := GetPadLength(Length(Data), BlockSize);
640+
636641
SetLength(Result, Length(Data) + PadLength);
637642
if Length(Data) > 0 then
638643
Move(Data[0], Result[0], Length(Data));
@@ -723,12 +728,12 @@ class function TFixedBytePadding.RemovePadding(const Data : string;
723728
class function TPKCS7Padding.GetPadLength(DataSize,
724729
BlockSize: integer): integer;
725730
begin
726-
result := BlockSize - (DataSize mod BlockSize);
731+
Result := BlockSize - (DataSize mod BlockSize);
727732
end;
728733

729734
class function TPKCS7Padding.IsBlockSizeValid(BlockSize: integer): boolean;
730735
begin
731-
result := (BlockSize > 0) and (BlockSize < 256);
736+
Result := (BlockSize > 0) and (BlockSize < 256);
732737
end;
733738

734739
class function TPKCS7Padding.GetPaddingByte(PaddingLength: Integer;
@@ -741,14 +746,14 @@ class function TPKCS7Padding.GetPaddingByte(PaddingLength: Integer;
741746

742747
class function TPKCS5Padding.IsBlockSizeValid(BlockSize: integer): boolean;
743748
begin
744-
result := BlockSize = 8;
749+
Result := BlockSize = 8;
745750
end;
746751

747752
{ TANSI_X9_23_Padding }
748753

749754
class function TANSI_X9_23_Padding.IsBlockSizeValid(BlockSize: integer): boolean;
750755
begin
751-
result := BlockSize > 0;
756+
Result := BlockSize > 0;
752757
end;
753758

754759
class function TANSI_X9_23_Padding.GetPaddingByte(PaddingLength: Integer;
@@ -763,7 +768,7 @@ class function TANSI_X9_23_Padding.GetPaddingByte(PaddingLength: Integer;
763768
class function TANSI_X9_23_Padding.GetPadLength(DataSize,
764769
BlockSize: integer): integer;
765770
begin
766-
result := DataSize mod BlockSize;
771+
Result := DataSize mod BlockSize;
767772
end;
768773

769774
class function TANSI_X9_23_Padding.HasValidPadding(const Data: TBytes;
@@ -801,7 +806,7 @@ class function TISO10126Padding.GetPaddingByte(PaddingLength: Integer;
801806
class function TISO7816Padding.GetPadLength(DataSize,
802807
BlockSize: integer): integer;
803808
begin
804-
result := DataSize mod BlockSize;
809+
Result := DataSize mod BlockSize;
805810
end;
806811

807812
class function TISO7816Padding.AddPadding(const Data: TBytes;
@@ -813,10 +818,13 @@ class function TISO7816Padding.AddPadding(const Data: TBytes;
813818
if not IsBlockSizeValid(BlockSize) then
814819
raise EDECCipherException.CreateResFmt(@sUnsupportedBlockSizeForPadding,
815820
[ClassName, BlockSize]);
821+
816822
PadLength := GetPadLength(Length(Data), BlockSize);
823+
817824
SetLength(Result, Length(Data) + PadLength);
818825
if Length(Data) > 0 then
819826
Move(Data[0], Result[0], Length(Data));
827+
820828
I := Length(Data);
821829
Result[I] := $80;
822830
for I := succ(Length(Data)) to High(Result) do

0 commit comments

Comments
 (0)