unit Chilkat.Ecc;

{
  Pascal wrapper for Chilkat Ecc.
  Auto-generated by PascalWrapperGenerator -- do not edit manually.
}

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TEcc wraps CkEcc via the C bridge layer. }
  TEcc = class(TChilkatBase)
  private
    function  GetLastErrorHtml: string;
    function  GetLastErrorText: string;
    function  GetLastErrorXml: string;
    function  GetVersion: string;
    function  GetDebugLogFilePath: string;
    procedure SetDebugLogFilePath(AValue: string);
    function  GetVerboseLogging: Boolean;
    procedure SetVerboseLogging(AValue: Boolean);
    function  GetLastMethodSuccess: Boolean;
    procedure SetLastMethodSuccess(AValue: Boolean);
    function  GetAsnFormat: Boolean;
    procedure SetAsnFormat(AValue: Boolean);
  public
    constructor Create;
    destructor  Destroy; override;

    property LastErrorHtml: string read GetLastErrorHtml;
    property LastErrorText: string read GetLastErrorText;
    property LastErrorXml: string read GetLastErrorXml;
    property Version: string read GetVersion;
    property DebugLogFilePath: string read GetDebugLogFilePath write SetDebugLogFilePath;
    property VerboseLogging: Boolean read GetVerboseLogging write SetVerboseLogging;
    property LastMethodSuccess: Boolean read GetLastMethodSuccess write SetLastMethodSuccess;
    property AsnFormat: Boolean read GetAsnFormat write SetAsnFormat;

    function  SharedSecretENC(privKey: TChilkatBase; pubKey: TChilkatBase; const encoding: string): string;
    function  SignHashENC(const encodedHash: string; const encoding: string; privkey: TChilkatBase; prng: TChilkatBase): string;
    function  VerifyHashENC(const encodedHash: string; const encodedSig: string; const encoding: string; pubkey: TChilkatBase): Integer;
    function  SignBd(bdData: TChilkatBase; const hashAlg: string; const encoding: string; privKey: TChilkatBase; prng: TChilkatBase): string;
    function  VerifyBd(bdData: TChilkatBase; const hashAlg: string; const encodedSig: string; const encoding: string; pubkey: TChilkatBase): Integer;
    function  SignBdUsingCert(bdData: TChilkatBase; const hashAlg: string; const encoding: string; cert: TChilkatBase): string;
    function  SignHashUsingCert(const encodedHash: string; const encoding: string; cert: TChilkatBase): string;
    function  GenKey(const curveName: string; prng: TChilkatBase; privKey: TChilkatBase): Boolean;
    function  GenKey2(const curveName: string; const encodedK: string; const encoding: string; privKey: TChilkatBase): Boolean;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkEcc_Create  = function(): Pointer; cdecl;
  TCkEcc_Dispose = procedure(handle: Pointer); cdecl;
  TCkEcc_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkEcc_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkEcc_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkEcc_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkEcc_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkEcc_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkEcc_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkEcc_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkEcc_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkEcc_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkEcc_get_AsnFormat = function(handle: Pointer): LongBool; cdecl;
  TCkEcc_put_AsnFormat = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkEcc_SharedSecretENC = function(handle: Pointer; privKey: Pointer; pubKey: Pointer; encoding: PAnsiChar): PAnsiChar; cdecl;
  TCkEcc_SignHashENC = function(handle: Pointer; encodedHash: PAnsiChar; encoding: PAnsiChar; privkey: Pointer; prng: Pointer): PAnsiChar; cdecl;
  TCkEcc_VerifyHashENC = function(handle: Pointer; encodedHash: PAnsiChar; encodedSig: PAnsiChar; encoding: PAnsiChar; pubkey: Pointer): Integer; cdecl;
  TCkEcc_SignBd = function(handle: Pointer; bdData: Pointer; hashAlg: PAnsiChar; encoding: PAnsiChar; privKey: Pointer; prng: Pointer): PAnsiChar; cdecl;
  TCkEcc_VerifyBd = function(handle: Pointer; bdData: Pointer; hashAlg: PAnsiChar; encodedSig: PAnsiChar; encoding: PAnsiChar; pubkey: Pointer): Integer; cdecl;
  TCkEcc_SignBdUsingCert = function(handle: Pointer; bdData: Pointer; hashAlg: PAnsiChar; encoding: PAnsiChar; cert: Pointer): PAnsiChar; cdecl;
  TCkEcc_SignHashUsingCert = function(handle: Pointer; encodedHash: PAnsiChar; encoding: PAnsiChar; cert: Pointer): PAnsiChar; cdecl;
  TCkEcc_GenKey = function(handle: Pointer; curveName: PAnsiChar; prng: Pointer; privKey: Pointer): LongBool; cdecl;
  TCkEcc_GenKey2 = function(handle: Pointer; curveName: PAnsiChar; encodedK: PAnsiChar; encoding: PAnsiChar; privKey: Pointer): LongBool; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkEcc_Create:  TCkEcc_Create  = nil;
  CkEcc_Dispose: TCkEcc_Dispose = nil;
  CkEcc_get_LastErrorHtml: TCkEcc_get_LastErrorHtml = nil;
  CkEcc_get_LastErrorText: TCkEcc_get_LastErrorText = nil;
  CkEcc_get_LastErrorXml: TCkEcc_get_LastErrorXml = nil;
  CkEcc_get_Version: TCkEcc_get_Version = nil;
  CkEcc_get_DebugLogFilePath: TCkEcc_get_DebugLogFilePath = nil;
  CkEcc_put_DebugLogFilePath: TCkEcc_put_DebugLogFilePath = nil;
  CkEcc_get_VerboseLogging: TCkEcc_get_VerboseLogging = nil;
  CkEcc_put_VerboseLogging: TCkEcc_put_VerboseLogging = nil;
  CkEcc_get_LastMethodSuccess: TCkEcc_get_LastMethodSuccess = nil;
  CkEcc_put_LastMethodSuccess: TCkEcc_put_LastMethodSuccess = nil;
  CkEcc_get_AsnFormat: TCkEcc_get_AsnFormat = nil;
  CkEcc_put_AsnFormat: TCkEcc_put_AsnFormat = nil;
  CkEcc_SharedSecretENC: TCkEcc_SharedSecretENC = nil;
  CkEcc_SignHashENC: TCkEcc_SignHashENC = nil;
  CkEcc_VerifyHashENC: TCkEcc_VerifyHashENC = nil;
  CkEcc_SignBd: TCkEcc_SignBd = nil;
  CkEcc_VerifyBd: TCkEcc_VerifyBd = nil;
  CkEcc_SignBdUsingCert: TCkEcc_SignBdUsingCert = nil;
  CkEcc_SignHashUsingCert: TCkEcc_SignHashUsingCert = nil;
  CkEcc_GenKey: TCkEcc_GenKey = nil;
  CkEcc_GenKey2: TCkEcc_GenKey2 = nil;

constructor TEcc.Create;
begin
  inherited Create;
  FHandle := CkEcc_Create();
end;

destructor TEcc.Destroy;
begin
  if FHandle <> nil then
    CkEcc_Dispose(FHandle);
  FHandle := nil;
  inherited;
end;

function TEcc.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkEcc_get_LastErrorHtml(FHandle));
end;

function TEcc.GetLastErrorText: string;
begin
  Result := CkToStr(CkEcc_get_LastErrorText(FHandle));
end;

function TEcc.GetLastErrorXml: string;
begin
  Result := CkToStr(CkEcc_get_LastErrorXml(FHandle));
end;

function TEcc.GetVersion: string;
begin
  Result := CkToStr(CkEcc_get_Version(FHandle));
end;

function TEcc.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkEcc_get_DebugLogFilePath(FHandle));
end;

procedure TEcc.SetDebugLogFilePath(AValue: string);
begin
  CkEcc_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TEcc.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkEcc_get_VerboseLogging(FHandle));
end;

procedure TEcc.SetVerboseLogging(AValue: Boolean);
begin
  CkEcc_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TEcc.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkEcc_get_LastMethodSuccess(FHandle));
end;

procedure TEcc.SetLastMethodSuccess(AValue: Boolean);
begin
  CkEcc_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TEcc.GetAsnFormat: Boolean;
begin
  Result := Boolean(CkEcc_get_AsnFormat(FHandle));
end;

procedure TEcc.SetAsnFormat(AValue: Boolean);
begin
  CkEcc_put_AsnFormat(FHandle, LongBool(AValue));
end;

function TEcc.SharedSecretENC(privKey: TChilkatBase; pubKey: TChilkatBase; const encoding: string): string;
begin
  Result := CkToStr(CkEcc_SharedSecretENC(FHandle, privKey.Handle, pubKey.Handle, PAnsiChar(StrToCk(encoding))));
end;

function TEcc.SignHashENC(const encodedHash: string; const encoding: string; privkey: TChilkatBase; prng: TChilkatBase): string;
begin
  Result := CkToStr(CkEcc_SignHashENC(FHandle, PAnsiChar(StrToCk(encodedHash)), PAnsiChar(StrToCk(encoding)), privkey.Handle, prng.Handle));
end;

function TEcc.VerifyHashENC(const encodedHash: string; const encodedSig: string; const encoding: string; pubkey: TChilkatBase): Integer;
begin
  Result := CkEcc_VerifyHashENC(FHandle, PAnsiChar(StrToCk(encodedHash)), PAnsiChar(StrToCk(encodedSig)), PAnsiChar(StrToCk(encoding)), pubkey.Handle);
end;

function TEcc.SignBd(bdData: TChilkatBase; const hashAlg: string; const encoding: string; privKey: TChilkatBase; prng: TChilkatBase): string;
begin
  Result := CkToStr(CkEcc_SignBd(FHandle, bdData.Handle, PAnsiChar(StrToCk(hashAlg)), PAnsiChar(StrToCk(encoding)), privKey.Handle, prng.Handle));
end;

function TEcc.VerifyBd(bdData: TChilkatBase; const hashAlg: string; const encodedSig: string; const encoding: string; pubkey: TChilkatBase): Integer;
begin
  Result := CkEcc_VerifyBd(FHandle, bdData.Handle, PAnsiChar(StrToCk(hashAlg)), PAnsiChar(StrToCk(encodedSig)), PAnsiChar(StrToCk(encoding)), pubkey.Handle);
end;

function TEcc.SignBdUsingCert(bdData: TChilkatBase; const hashAlg: string; const encoding: string; cert: TChilkatBase): string;
begin
  Result := CkToStr(CkEcc_SignBdUsingCert(FHandle, bdData.Handle, PAnsiChar(StrToCk(hashAlg)), PAnsiChar(StrToCk(encoding)), cert.Handle));
end;

function TEcc.SignHashUsingCert(const encodedHash: string; const encoding: string; cert: TChilkatBase): string;
begin
  Result := CkToStr(CkEcc_SignHashUsingCert(FHandle, PAnsiChar(StrToCk(encodedHash)), PAnsiChar(StrToCk(encoding)), cert.Handle));
end;

function TEcc.GenKey(const curveName: string; prng: TChilkatBase; privKey: TChilkatBase): Boolean;
begin
  Result := Boolean(CkEcc_GenKey(FHandle, PAnsiChar(StrToCk(curveName)), prng.Handle, privKey.Handle));
end;

function TEcc.GenKey2(const curveName: string; const encodedK: string; const encoding: string; privKey: TChilkatBase): Boolean;
begin
  Result := Boolean(CkEcc_GenKey2(FHandle, PAnsiChar(StrToCk(curveName)), PAnsiChar(StrToCk(encodedK)), PAnsiChar(StrToCk(encoding)), privKey.Handle));
end;

initialization
  Chilkat_GetProcedureAddress(CkEcc_Create,  'CkEcc_Create');
  Chilkat_GetProcedureAddress(CkEcc_Dispose, 'CkEcc_Dispose');
  Chilkat_GetProcedureAddress(CkEcc_get_LastErrorHtml, 'CkEcc_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkEcc_get_LastErrorText, 'CkEcc_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkEcc_get_LastErrorXml, 'CkEcc_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkEcc_get_Version, 'CkEcc_get_Version');
  Chilkat_GetProcedureAddress(CkEcc_get_DebugLogFilePath, 'CkEcc_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkEcc_put_DebugLogFilePath, 'CkEcc_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkEcc_get_VerboseLogging, 'CkEcc_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkEcc_put_VerboseLogging, 'CkEcc_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkEcc_get_LastMethodSuccess, 'CkEcc_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkEcc_put_LastMethodSuccess, 'CkEcc_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkEcc_get_AsnFormat, 'CkEcc_get_AsnFormat');
  Chilkat_GetProcedureAddress(CkEcc_put_AsnFormat, 'CkEcc_put_AsnFormat');
  Chilkat_GetProcedureAddress(CkEcc_SharedSecretENC, 'CkEcc_SharedSecretENC');
  Chilkat_GetProcedureAddress(CkEcc_SignHashENC, 'CkEcc_SignHashENC');
  Chilkat_GetProcedureAddress(CkEcc_VerifyHashENC, 'CkEcc_VerifyHashENC');
  Chilkat_GetProcedureAddress(CkEcc_SignBd, 'CkEcc_SignBd');
  Chilkat_GetProcedureAddress(CkEcc_VerifyBd, 'CkEcc_VerifyBd');
  Chilkat_GetProcedureAddress(CkEcc_SignBdUsingCert, 'CkEcc_SignBdUsingCert');
  Chilkat_GetProcedureAddress(CkEcc_SignHashUsingCert, 'CkEcc_SignHashUsingCert');
  Chilkat_GetProcedureAddress(CkEcc_GenKey, 'CkEcc_GenKey');
  Chilkat_GetProcedureAddress(CkEcc_GenKey2, 'CkEcc_GenKey2');

end.
