@@ -349,125 +349,6 @@ TDECHash = class(TDECObject, IDECHash)
349349 // / </returns>
350350 function CalcString (const Value : RawByteString; Format: TDECFormatClass): RawByteString; overload;
351351
352- // / <summary>
353- <<<<<<< HEAD
354- // / Calculates the hash value over a given stream of bytes
355- // / </summary>
356- // / <param name="Stream">
357- // / Memory or file stream over which the hash value shall be calculated.
358- // / The stream must be assigned. The hash value will always be calculated
359- // / from the current position of the stream.
360- // / </param>
361- // / <param name="Size">
362- // / Number of bytes within the stream over which to calculate the hash value
363- // / </param>
364- // / <param name="HashResult">
365- // / In this byte array the calculated hash value will be returned
366- // / </param>
367- // / <param name="OnProgress">
368- // / Optional callback routine. It can be used to display the progress of
369- // / the operation.
370- // / </param>
371- procedure CalcStream (const Stream: TStream; Size: Int64; var HashResult: TBytes;
372- const OnProgress:TDECProgressEvent = nil ); overload;
373- // / <summary>
374- // / Calculates the hash value over a givens stream of bytes
375- // / </summary>
376- // / <param name="Stream">
377- // / Memory or file stream over which the hash value shall be calculated.
378- // / The stream must be assigned. The hash value will always be calculated
379- // / from the current position of the stream.
380- // / </param>
381- // / <param name="Size">
382- // / Number of bytes within the stream over which to calculate the hash value
383- // / </param>
384- // / <param name="Format">
385- // / Optional formatting class. The formatting of that will be applied to
386- // / the returned hash value.
387- // / </param>
388- // / <param name="OnProgress">
389- // / Optional callback routine. It can be used to display the progress of
390- // / the operation.
391- // / </param>
392- // / <returns>
393- // / Hash value over the bytes in the stream, formatted with the formatting
394- // / passed as format parameter, if used.
395- // / </returns>
396- function CalcStream (const Stream: TStream; Size: Int64; Format: TDECFormatClass = nil ;
397- const OnProgress:TDECProgressEvent = nil ): RawByteString; overload;
398-
399- // / <summary>
400- // / Calculates the hash value over a given stream of bytes. The calculated
401- // / hash value can be retrieved with one of the DigestAsXXX methods.
402- // / </summary>
403- // / <param name="Stream">
404- // / Memory or file stream over which the hash value shall be calculated.
405- // / The stream must be assigned. The hash value will always be calculated
406- // / from the current position of the stream.
407- // / </param>
408- // / <param name="Size">
409- // / Number of bytes within the stream over which to calculate the hash value
410- // / </param>
411- // / <param name="OnProgress">
412- // / Optional callback routine. It can be used to display the progress of
413- // / the operation.
414- // / </param>
415- // / <param name="DoFinalize">
416- // / Optinal parameter: if true this call is the last one and the
417- // / finalization of the hash calculation, including calling done, will be
418- // / carried out in this method call as well.
419- // / </param>
420- // / <remarks>
421- // / Before calling this method for the first time after creation of the
422- // / hash instance or after calling Done Init needs to be called.
423- // / After calling this method Done needs to be called and in case of
424- // / algorithms (like SHA3) with a message size in bits and not whole bytes
425- // / the contents of the last byte needs to be assigned to PaddingByte before
426- // / calling Done!
427- // / </remarks>
428- procedure CalcStream (const Stream: TStream; Size: Int64;
429- const OnProgress:TDECProgressEvent = nil ;
430- DoFinalize: Boolean = false); overload;
431-
432- // / <summary>
433- // / Calculates the hash value over the contents of a given file
434- // / </summary>
435- // / <param name="FileName">
436- // / Path and name of the file to be processed
437- // / </param>
438- // / <param name="HashResult">
439- // / Here the resulting hash value is being returned as byte array
440- // / </param>
441- // / <param name="OnProgress">
442- // / Optional callback. If being used the hash calculation will call it from
443- // / time to time to return the current progress of the operation
444- // / </param>
445- procedure CalcFile (const FileName: string; var HashResult: TBytes;
446- const OnProgress:TDECProgressEvent = nil ); overload;
447- // / <summary>
448- // / Calculates the hash value over the contents of a given file
449- =======
450- // / Defines the byte used in some algorithms to padd the end of the data
451- // / if the length of the data cannot be divided by required size for the
452- // / hash algorithm without reminder. For algorithms which can handle message
453- // / lengths which are not whole bytes (e.g. SHA3), it can be used to define
454- // / the last bits. This should be done only for those methods not already
455- // / returning the calculated hash value, as those manage handling of the
456- // / last byte themselves.
457- >>>>>>> origin/development
458- // / </summary>
459- // / <remarks>
460- // / If an algorithm is used which can operate on bit sized message lengths
461- // / and a method for feeding the data is used which does not already return
462- // / the calculated hash value one needs to set the contents of the last
463- // / byte with this property! For a stream for instance the length specified
464- // / when calling CalcStream needs to be 1 byte less and that last byte
465- // / needs to be assigned to this property just before calling Done.
466- // / </remarks>
467- <<<<<<< HEAD
468- function CalcFile (const FileName: string; Format: TDECFormatClass = nil ;
469- const OnProgress:TDECProgressEvent = nil ): RawByteString; overload;
470-
471352 // / <summary>
472353 // / Defines the byte used in some algorithms to padd the end of the data
473354 // / if the length of the data cannot be divided by required size for the
@@ -485,8 +366,6 @@ TDECHash = class(TDECObject, IDECHash)
485366 // / when calling CalcStream needs to be 1 byte less and that last byte
486367 // / needs to be assigned to this property just before calling Done.
487368 // / </remarks>
488- =======
489- >>>>>>> origin/development
490369 property PaddingByte: Byte read GetPaddingByte write SetPaddingByte;
491370 end ;
492371
@@ -875,180 +754,6 @@ class function TDECHash.ClassByName(const Name: string): TDECHashClass;
875754 Result := TDECHashClass(ClassList.ClassByName(Name ));
876755end ;
877756
878- <<<<<<< HEAD
879- procedure TDECHash.CalcStream (const Stream: TStream; Size: Int64;
880- var HashResult: TBytes; const OnProgress:TDECProgressEvent);
881- var
882- Buffer: TBytes;
883- Bytes: Integer;
884- Max, Pos: Int64;
885- begin
886- Assert(Assigned(Stream), ' Stream to calculate hash on is not assigned' );
887-
888- Max := 0 ;
889- SetLength(HashResult, 0 );
890- try
891- Init;
892-
893- if StreamBufferSize <= 0 then
894- StreamBufferSize := 8192 ;
895-
896- Pos := Stream.Position;
897-
898- if Size < 0 then
899- Size := Stream.Size - Pos;
900-
901- // Last byte is incomplete so it mustn't be processed
902- if (FFinalByteLength > 0 ) then
903- Dec(Size);
904-
905- Max := Pos + Size;
906-
907- if Assigned(OnProgress) then
908- OnProgress(Max, 0 , Started);
909-
910- Bytes := StreamBufferSize mod FBufferSize;
911-
912- if Bytes = 0 then
913- Bytes := StreamBufferSize
914- else
915- Bytes := StreamBufferSize + FBufferSize - Bytes;
916-
917- if Bytes > Size then
918- SetLength(Buffer, Size)
919- else
920- SetLength(Buffer, Bytes);
921-
922- while Size > 0 do
923- begin
924- Bytes := Length(Buffer);
925- if Bytes > Size then
926- Bytes := Size;
927- Stream.ReadBuffer(Buffer[0 ], Bytes);
928- Calc(Buffer[0 ], Bytes);
929- Dec(Size, Bytes);
930- Inc(Pos, Bytes);
931-
932- if Assigned(OnProgress) then
933- OnProgress(Max, Pos, Processing);
934- end ;
935-
936- // Last byte is incomplete but algorithm may need its value for padding
937- if (FFinalByteLength > 0 ) then
938- Stream.ReadBuffer(FPaddingByte, 1 );
939-
940- Done;
941- HashResult := DigestAsBytes;
942- finally
943- ProtectBytes(Buffer);
944- if Assigned(OnProgress) then
945- OnProgress(Max, Max, Finished);
946- end ;
947- end ;
948-
949- function TDECHash.CalcStream (const Stream: TStream; Size: Int64;
950- Format: TDECFormatClass; const OnProgress:TDECProgressEvent): RawByteString;
951- var
952- Hash: TBytes;
953- begin
954- CalcStream(Stream, Size, Hash, OnProgress);
955- Result := BytesToRawString(ValidFormat(Format).Encode(Hash));
956- end ;
957-
958- procedure TDECHash.CalcStream (const Stream: TStream; Size: Int64;
959- const OnProgress:TDECProgressEvent;
960- DoFinalize: Boolean);
961- var
962- Buffer: TBytes;
963- Bytes: Integer;
964- Max, Pos: Int64;
965- begin
966- Assert(Assigned(Stream), ' Stream to calculate hash on is not assigned' );
967-
968- Max := 0 ;
969- try
970- if StreamBufferSize <= 0 then
971- StreamBufferSize := 8192 ;
972-
973- Pos := Stream.Position;
974-
975- if Size < 0 then
976- Size := Stream.Size - Pos;
977-
978- // Last byte is incomplete so it mustn't be processed
979- if DoFinalize and (FFinalByteLength > 0 ) then
980- Dec(Size);
981-
982- Max := Pos + Size;
983-
984- if Assigned(OnProgress) then
985- OnProgress(Max, 0 , Started);
986-
987- Bytes := StreamBufferSize mod FBufferSize;
988-
989- if Bytes = 0 then
990- Bytes := StreamBufferSize
991- else
992- Bytes := StreamBufferSize + FBufferSize - Bytes;
993-
994- if Bytes > Size then
995- SetLength(Buffer, Size)
996- else
997- SetLength(Buffer, Bytes);
998-
999- while Size > 0 do
1000- begin
1001- Bytes := Length(Buffer);
1002- if Bytes > Size then
1003- Bytes := Size;
1004- Stream.ReadBuffer(Buffer[0 ], Bytes);
1005- Calc(Buffer[0 ], Bytes);
1006- Dec(Size, Bytes);
1007- Inc(Pos, Bytes);
1008-
1009- if Assigned(OnProgress) then
1010- OnProgress(Max, Pos, Processing);
1011- end ;
1012-
1013- // Last byte is incomplete but algorithm may need its value for padding
1014- if DoFinalize then
1015- begin
1016- if (FFinalByteLength > 0 ) then
1017- Stream.ReadBuffer(FPaddingByte, 1 );
1018- Done;
1019- end ;
1020- finally
1021- ProtectBytes(Buffer);
1022- if Assigned(OnProgress) then
1023- OnProgress(Max, Max, Finished);
1024- end ;
1025- end ;
1026-
1027- procedure TDECHash.CalcFile (const FileName: string; var HashResult: TBytes;
1028- const OnProgress:TDECProgressEvent);
1029- var
1030- S: TFileStream;
1031- begin
1032- SetLength(HashResult, 0 );
1033- S := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
1034- try
1035- CalcStream(S, S.Size, HashResult, OnProgress);
1036- finally
1037- S.Free;
1038- end ;
1039- end ;
1040-
1041- function TDECHash.CalcFile (const FileName: string; Format: TDECFormatClass;
1042- const OnProgress:TDECProgressEvent): RawByteString;
1043- var
1044- Hash: TBytes;
1045- begin
1046- CalcFile(FileName, Hash, OnProgress);
1047- Result := BytesToRawString(ValidFormat(Format).Encode(Hash));
1048- end ;
1049-
1050- =======
1051- >>>>>>> origin/development
1052757{ $IFDEF DELPHIORBCB}
1053758procedure ModuleUnload (Instance: NativeUInt);
1054759var // automaticaly deregistration/releasing
0 commit comments