Skip to content

Commit 6fadfa7

Browse files
committed
Improved XMLDOC regarding exceptions and TFormat_HEX.DoDecode and TFormat_UU.Decode throw an EDECFormatException instead of an EDECException now if data is passed in a wrong format.
1 parent 681b39b commit 6fadfa7

15 files changed

+378
-38
lines changed

Source/DECBaseClass.pas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ TDECClassList = class(TDictionary<Int64, TDECClass>)
8484
/// Returns the class type if found. if it could not be found a
8585
/// EDECClassNotRegisteredException will be thrown
8686
/// </returns>
87+
/// <exception cref="EDECClassNotRegisteredException">
88+
/// Exception raised if the class specified by <c>Name</c> is not found
89+
/// </exception>
8790
function ClassByName(const Name: string): TDECClass;
8891

8992
/// <summary>
@@ -99,6 +102,9 @@ TDECClassList = class(TDictionary<Int64, TDECClass>)
99102
/// or throws an EDECClassNotRegisteredException exception if no class
100103
/// with the given identity has been found
101104
/// </returns>
105+
/// <exception cref="EDECClassNotRegisteredException">
106+
/// Exception raised if the class specified by <c>Identity</c> is not found
107+
/// </exception>
102108
function ClassByIdentity(Identity: Int64): TDECClass;
103109
/// <summary>
104110
/// Returns a list of all classes registered in this list

Source/DECCipherBase.pas

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ TDECCipher = class(TDECObject)
308308
/// <param name="States">
309309
/// List of states the state machine should be at currently
310310
/// </param>
311+
/// <exception cref="EDECCipherException">
312+
/// Exception raised if the state machine is not in one of the states
313+
/// specified by the <c>States</c> parameter.
314+
/// </exception>
311315
procedure CheckState(States: TCipherStates);
312316

313317
/// <summary>
@@ -399,6 +403,9 @@ TDECCipher = class(TDECObject)
399403
/// Returns the class type if found. if it could not be found a
400404
/// EDECClassNotRegisteredException will be thrown
401405
/// </returns>
406+
/// <exception cref="EDECClassNotRegisteredException">
407+
/// Exception raised if the class specified by <c>Name</c> is not found
408+
/// </exception>
402409
class function ClassByName(const Name: string): TDECCipherClass;
403410

404411
/// <summary>
@@ -414,6 +421,9 @@ TDECCipher = class(TDECObject)
414421
/// or throws an EDECClassNotRegisteredException exception if no class
415422
/// with the given identity has been found
416423
/// </returns>
424+
/// <exception cref="EDECClassNotRegisteredException">
425+
/// Exception raised if the class specified by <c>Identity</c> is not found
426+
/// </exception>
417427
class function ClassByIdentity(Identity: Int64): TDECCipherClass;
418428

419429
/// <summary>
@@ -600,6 +610,10 @@ TDECCipher = class(TDECObject)
600610
/// <returns>
601611
/// Encrypted data. Init must have been called previously.
602612
/// </returns>
613+
/// <exception cref="EDECCipherException">
614+
/// Exception raised if the length of the data passed as <c>Source</c>
615+
/// is not a multiple of the algorithm's block size.
616+
/// </exception>
603617
function EncodeRawByteString(const Source: RawByteString;
604618
Format: TDECFormatClass = nil): RawByteString;
605619
deprecated; // please use EncodeBytes functions now
@@ -629,6 +643,10 @@ TDECCipher = class(TDECObject)
629643
/// <returns>
630644
/// Decrypted data. Init must have been called previously.
631645
/// </returns>
646+
/// <exception cref="EDECCipherException">
647+
/// Exception raised if the length of the data passed as <c>Source</c>
648+
/// is not a multiple of the algorithm's block size.
649+
/// </exception>
632650
function DecodeRawByteString(const Source: RawByteString;
633651
Format: TDECFormatClass = nil): RawByteString; deprecated; // please use DecodeBytes functions now
634652

@@ -649,6 +667,10 @@ TDECCipher = class(TDECObject)
649667
/// <returns>
650668
/// Encrypted data. Init must have been called previously.
651669
/// </returns>
670+
/// <exception cref="EDECCipherException">
671+
/// Exception raised if the length of the data passed as <c>Source</c>
672+
/// is not a multiple of the algorithm's block size.
673+
/// </exception>
652674
function EncodeBytes(const Source: TBytes; Format: TDECFormatClass = nil): TBytes;
653675
/// <summary>
654676
/// Decrypts the contents of a ByteArray.
@@ -669,6 +691,10 @@ TDECCipher = class(TDECObject)
669691
/// <returns>
670692
/// Decrypted data. Init must have been called previously.
671693
/// </returns>
694+
/// <exception cref="EDECCipherException">
695+
/// Exception raised if the length of the data passed as <c>Source</c>
696+
/// is not a multiple of the algorithm's block size.
697+
/// </exception>
672698
function DecodeBytes(const Source: TBytes; Format: TDECFormatClass): TBytes;
673699

674700
// CalcMACBytes deferred since the current implementation would neither be

Source/DECCipherFormats.pas

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
100100
/// <returns>
101101
/// Byte array with encrypted data
102102
/// </returns>
103+
/// <exception cref="EDECCipherException">
104+
/// Exception raised if the length of the data passed as <c>Source</c>
105+
/// is not a multiple of the algorithm's block size.
106+
/// </exception>
103107
function EncodeBytes(const Source: TBytes): TBytes;
104108

105109
/// <summary>
@@ -114,6 +118,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
114118
/// <returns>
115119
/// Byte array with decrypted data
116120
/// </returns>
121+
/// <exception cref="EDECCipherException">
122+
/// Exception raised if the length of the data passed as <c>Source</c>
123+
/// is not a multiple of the algorithm's block size.
124+
/// </exception>
117125
function DecodeBytes(const Source: TBytes): TBytes;
118126

119127
/// <summary>
@@ -134,6 +142,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
134142
/// <param name="OnProgress">
135143
/// optional callback for reporting progress of the operation
136144
/// </param>
145+
/// <exception cref="EDECCipherException">
146+
/// Exception raised if the length of the data passed as <c>Source</c>
147+
/// is not a multiple of the algorithm's block size.
148+
/// </exception>
137149
procedure EncodeStream(const Source, Dest: TStream; DataSize: Int64;
138150
const OnProgress: TDECProgressEvent = nil);
139151

@@ -155,6 +167,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
155167
/// <param name="OnProgress">
156168
/// optional callback for reporting progress of the operation
157169
/// </param>
170+
/// <exception cref="EDECCipherException">
171+
/// Exception raised if the length of the data passed as <c>Source</c>
172+
/// is not a multiple of the algorithm's block size.
173+
/// </exception>
158174
procedure DecodeStream(const Source, Dest: TStream; DataSize: Int64;
159175
const OnProgress: TDECProgressEvent = nil);
160176

@@ -174,6 +190,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
174190
/// Optional event which can be passed to get information about the
175191
/// progress of the encryption operation
176192
/// </param>
193+
/// <exception cref="EDECCipherException">
194+
/// Exception raised if the length of the data passed as <c>Source</c>
195+
/// is not a multiple of the algorithm's block size.
196+
/// </exception>
177197
procedure EncodeFile(const SourceFileName, DestFileName: string;
178198
const OnProgress: TDECProgressEvent = nil);
179199

@@ -193,6 +213,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
193213
/// Optional event which can be passed to get information about the
194214
/// progress of the decryption operation
195215
/// </param>
216+
/// <exception cref="EDECCipherException">
217+
/// Exception raised if the length of the data passed as <c>Source</c>
218+
/// is not a multiple of the algorithm's block size.
219+
/// </exception>
196220
procedure DecodeFile(const SourceFileName, DestFileName: string;
197221
const OnProgress: TDECProgressEvent = nil);
198222

@@ -215,6 +239,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
215239
/// <returns>
216240
/// Encrypted string as a byte array
217241
/// </returns>
242+
/// <exception cref="EDECCipherException">
243+
/// Exception raised if the length of the data passed as <c>Source</c>
244+
/// is not a multiple of the algorithm's block size.
245+
/// </exception>
218246
function EncodeStringToBytes(const Source: string;
219247
Format: TDECFormatClass = nil): TBytes; overload;
220248

@@ -237,6 +265,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
237265
/// <returns>
238266
/// Encrypted string as a byte array
239267
/// </returns>
268+
/// <exception cref="EDECCipherException">
269+
/// Exception raised if the length of the data passed as <c>Source</c>
270+
/// is not a multiple of the algorithm's block size.
271+
/// </exception>
240272
function EncodeStringToBytes(const Source: RawByteString;
241273
Format: TDECFormatClass = nil): TBytes; overload;
242274

@@ -266,6 +298,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
266298
/// byte combinations in a destructive way, making the encrypted string
267299
/// un-decryptable.
268300
/// </remarks>
301+
/// <exception cref="EDECCipherException">
302+
/// Exception raised if the length of the data passed as <c>Source</c>
303+
/// is not a multiple of the algorithm's block size.
304+
/// </exception>
269305
function EncodeStringToString(const Source: string;
270306
Format: TDECFormatClass = nil): string; overload;
271307

@@ -295,6 +331,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
295331
/// byte combinations in a destructive way, making the encrypted string
296332
/// un-decryptable.
297333
/// </remarks>
334+
/// <exception cref="EDECCipherException">
335+
/// Exception raised if the length of the data passed as <c>Source</c>
336+
/// is not a multiple of the algorithm's block size.
337+
/// </exception>
298338
function EncodeStringToString(const Source: RawByteString;
299339
Format: TDECFormatClass = nil): RawByteString; overload;
300340

@@ -317,6 +357,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
317357
/// <returns>
318358
/// Decrypted string as a byte array
319359
/// </returns>
360+
/// <exception cref="EDECCipherException">
361+
/// Exception raised if the length of the data passed as <c>Source</c>
362+
/// is not a multiple of the algorithm's block size.
363+
/// </exception>
320364
function DecodeStringToBytes(const Source: string;
321365
Format: TDECFormatClass = nil): TBytes; overload;
322366

@@ -339,6 +383,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
339383
/// <returns>
340384
/// Decrypted string as a byte array
341385
/// </returns>
386+
/// <exception cref="EDECCipherException">
387+
/// Exception raised if the length of the data passed as <c>Source</c>
388+
/// is not a multiple of the algorithm's block size.
389+
/// </exception>
342390
function DecodeStringToBytes(const Source: RawByteString;
343391
Format: TDECFormatClass = nil): TBytes; overload;
344392

@@ -366,6 +414,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
366414
/// which uses an 7-bit ASCII compatible string as input so that it
367415
/// didn't get altered by Unicode string processing in some hafrmful way
368416
/// </remarks>
417+
/// <exception cref="EDECCipherException">
418+
/// Exception raised if the length of the data passed as <c>Source</c>
419+
/// is not a multiple of the algorithm's block size.
420+
/// </exception>
369421
function DecodeStringToString(const Source: string;
370422
Format: TDECFormatClass = nil): string; overload;
371423

@@ -393,6 +445,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
393445
/// which uses an 7-bit ASCII compatible string as input so that it
394446
/// didn't get altered by string processing in some hafrmful way
395447
/// </remarks>
448+
/// <exception cref="EDECCipherException">
449+
/// Exception raised if the length of the data passed as <c>Source</c>
450+
/// is not a multiple of the algorithm's block size.
451+
/// </exception>
396452
function DecodeStringToString(const Source: RawByteString;
397453
Format: TDECFormatClass = nil): RawByteString; overload;
398454

@@ -416,6 +472,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
416472
/// <returns>
417473
/// Encrypted string as a byte array
418474
/// </returns>
475+
/// <exception cref="EDECCipherException">
476+
/// Exception raised if the length of the data passed as <c>Source</c>
477+
/// is not a multiple of the algorithm's block size.
478+
/// </exception>
419479
function EncodeStringToBytes(const Source: AnsiString;
420480
Format: TDECFormatClass = nil): TBytes; overload;
421481

@@ -445,6 +505,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
445505
/// byte combinations in a destructive way, making the encrypted string
446506
/// un-decryptable.
447507
/// </remarks>
508+
/// <exception cref="EDECCipherException">
509+
/// Exception raised if the length of the data passed as <c>Source</c>
510+
/// is not a multiple of the algorithm's block size.
511+
/// </exception>
448512
function EncodeStringToString(const Source: AnsiString;
449513
Format: TDECFormatClass = nil): AnsiString; overload;
450514

@@ -467,6 +531,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
467531
/// <returns>
468532
/// Decrypted string as a byte array
469533
/// </returns>
534+
/// <exception cref="EDECCipherException">
535+
/// Exception raised if the length of the data passed as <c>Source</c>
536+
/// is not a multiple of the algorithm's block size.
537+
/// </exception>
470538
function DecodeStringToBytes(const Source: AnsiString;
471539
Format: TDECFormatClass = nil): TBytes; overload;
472540

@@ -494,6 +562,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
494562
/// which uses an 7-bit ASCII compatible string as input so that it
495563
/// didn't get altered by string processing in some hafrmful way
496564
/// </remarks>
565+
/// <exception cref="EDECCipherException">
566+
/// Exception raised if the length of the data passed as <c>Source</c>
567+
/// is not a multiple of the algorithm's block size.
568+
/// </exception>
497569
function DecodeStringToString(const Source: AnsiString;
498570
Format: TDECFormatClass = nil): AnsiString; overload;
499571
{$ENDIF}
@@ -518,6 +590,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
518590
/// <returns>
519591
/// Encrypted string as a byte array
520592
/// </returns>
593+
/// <exception cref="EDECCipherException">
594+
/// Exception raised if the length of the data passed as <c>Source</c>
595+
/// is not a multiple of the algorithm's block size.
596+
/// </exception>
521597
function EncodeStringToBytes(const Source: WideString;
522598
Format: TDECFormatClass = nil): TBytes; overload;
523599

@@ -547,6 +623,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
547623
/// byte combinations in a destructive way, making the encrypted string
548624
/// un-decryptable.
549625
/// </remarks>
626+
/// <exception cref="EDECCipherException">
627+
/// Exception raised if the length of the data passed as <c>Source</c>
628+
/// is not a multiple of the algorithm's block size.
629+
/// </exception>
550630
function EncodeStringToString(const Source: WideString;
551631
Format: TDECFormatClass = nil): WideString; overload;
552632

@@ -569,6 +649,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
569649
/// <returns>
570650
/// Decrypted string as a byte array
571651
/// </returns>
652+
/// <exception cref="EDECCipherException">
653+
/// Exception raised if the length of the data passed as <c>Source</c>
654+
/// is not a multiple of the algorithm's block size.
655+
/// </exception>
572656
function DecodeStringToBytes(const Source: WideString;
573657
Format: TDECFormatClass = nil): TBytes; overload;
574658

@@ -596,6 +680,10 @@ TDECFormattedCipher = class(TDECCipherModes, IDECCipher)
596680
/// which uses an 7-bit ASCII compatible string as input so that it
597681
/// didn't get altered by string processing in some hafrmful way
598682
/// </remarks>
683+
/// <exception cref="EDECCipherException">
684+
/// Exception raised if the length of the data passed as <c>Source</c>
685+
/// is not a multiple of the algorithm's block size.
686+
/// </exception>
599687
function DecodeStringToString(const Source: WideString;
600688
Format: TDECFormatClass = nil): WideString; overload;
601689
{$ENDIF}

0 commit comments

Comments
 (0)