{$IFNDEF CLR}

{$I Dac.inc}

unit CRSHA1;
{$ENDIF}

interface

uses
{$IFNDEF CLR}
  CLRClasses,
{$ENDIF}
  SysUtils, CRTypes, CRHash;

type
  TSHA1CryptoServiceProvider = class(THash_SHA1)
  protected
    procedure HashCore(rgb: IntPtr; cbSize: Integer); overload; override;
    procedure HashCore(const rgb: TBytes; ibStart, cbSize: Integer); overload; override;
    function HashFinal: TBytes; override;

  public
    constructor Create; override;
    procedure Initialize; override;
  end;

implementation

constructor TSHA1CryptoServiceProvider.Create;
begin
  inherited;
  Init;
end;

procedure TSHA1CryptoServiceProvider.Initialize;
begin
  Init;
end;

procedure TSHA1CryptoServiceProvider.HashCore(rgb: IntPtr; cbSize: Integer);
begin
  if (rgb <> nil) and (cbSize > 0) then
    Calc(rgb, cbSize);
end;

procedure TSHA1CryptoServiceProvider.HashCore(const rgb: TBytes; ibStart, cbSize: Integer);
begin
  if (rgb <> nil) and (cbSize > 0) then
    Calc(rgb, ibStart, cbSize);
end;

function TSHA1CryptoServiceProvider.HashFinal: TBytes;
begin
  Done;
  SetLength(Result, DigestKeySize);
  Buffer.BlockCopy(DigestKey, 0, Result, 0, DigestKeySize);
end;

end.

