unit Chilkat.EdDSA;

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

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

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TEdDSA wraps CkEdDSA via the C bridge layer. }
  TEdDSA = 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  GetAlgorithm: string;
    procedure SetAlgorithm(AValue: string);
    function  GetContext: string;
    procedure SetContext(AValue: string);
  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 Algorithm: string read GetAlgorithm write SetAlgorithm;
    property Context: string read GetContext write SetContext;

    function  GenEd25519Key(prng: TChilkatBase; privKey: TChilkatBase): Boolean;
    function  SignBdENC(bd: TChilkatBase; const encoding: string; privkey: TChilkatBase): string;
    function  VerifyBdENC(bd: TChilkatBase; const encodedSig: string; const enocding: string; pubkey: TChilkatBase): Boolean;
    function  SharedSecretENC(privkey: TChilkatBase; pubkey: TChilkatBase; const encoding: string): string;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkEdDSA_Create  = function(): Pointer; cdecl;
  TCkEdDSA_Dispose = procedure(handle: Pointer); cdecl;
  TCkEdDSA_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkEdDSA_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkEdDSA_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkEdDSA_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkEdDSA_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkEdDSA_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkEdDSA_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkEdDSA_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkEdDSA_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkEdDSA_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkEdDSA_get_Algorithm = function(handle: Pointer): PAnsiChar; cdecl;
  TCkEdDSA_put_Algorithm = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkEdDSA_get_Context = function(handle: Pointer): PAnsiChar; cdecl;
  TCkEdDSA_put_Context = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkEdDSA_GenEd25519Key = function(handle: Pointer; prng: Pointer; privKey: Pointer): LongBool; cdecl;
  TCkEdDSA_SignBdENC = function(handle: Pointer; bd: Pointer; encoding: PAnsiChar; privkey: Pointer): PAnsiChar; cdecl;
  TCkEdDSA_VerifyBdENC = function(handle: Pointer; bd: Pointer; encodedSig: PAnsiChar; enocding: PAnsiChar; pubkey: Pointer): LongBool; cdecl;
  TCkEdDSA_SharedSecretENC = function(handle: Pointer; privkey: Pointer; pubkey: Pointer; encoding: PAnsiChar): PAnsiChar; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkEdDSA_Create:  TCkEdDSA_Create  = nil;
  CkEdDSA_Dispose: TCkEdDSA_Dispose = nil;
  CkEdDSA_get_LastErrorHtml: TCkEdDSA_get_LastErrorHtml = nil;
  CkEdDSA_get_LastErrorText: TCkEdDSA_get_LastErrorText = nil;
  CkEdDSA_get_LastErrorXml: TCkEdDSA_get_LastErrorXml = nil;
  CkEdDSA_get_Version: TCkEdDSA_get_Version = nil;
  CkEdDSA_get_DebugLogFilePath: TCkEdDSA_get_DebugLogFilePath = nil;
  CkEdDSA_put_DebugLogFilePath: TCkEdDSA_put_DebugLogFilePath = nil;
  CkEdDSA_get_VerboseLogging: TCkEdDSA_get_VerboseLogging = nil;
  CkEdDSA_put_VerboseLogging: TCkEdDSA_put_VerboseLogging = nil;
  CkEdDSA_get_LastMethodSuccess: TCkEdDSA_get_LastMethodSuccess = nil;
  CkEdDSA_put_LastMethodSuccess: TCkEdDSA_put_LastMethodSuccess = nil;
  CkEdDSA_get_Algorithm: TCkEdDSA_get_Algorithm = nil;
  CkEdDSA_put_Algorithm: TCkEdDSA_put_Algorithm = nil;
  CkEdDSA_get_Context: TCkEdDSA_get_Context = nil;
  CkEdDSA_put_Context: TCkEdDSA_put_Context = nil;
  CkEdDSA_GenEd25519Key: TCkEdDSA_GenEd25519Key = nil;
  CkEdDSA_SignBdENC: TCkEdDSA_SignBdENC = nil;
  CkEdDSA_VerifyBdENC: TCkEdDSA_VerifyBdENC = nil;
  CkEdDSA_SharedSecretENC: TCkEdDSA_SharedSecretENC = nil;

constructor TEdDSA.Create;
begin
  inherited Create;
  FHandle := CkEdDSA_Create();
end;

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

function TEdDSA.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkEdDSA_get_LastErrorHtml(FHandle));
end;

function TEdDSA.GetLastErrorText: string;
begin
  Result := CkToStr(CkEdDSA_get_LastErrorText(FHandle));
end;

function TEdDSA.GetLastErrorXml: string;
begin
  Result := CkToStr(CkEdDSA_get_LastErrorXml(FHandle));
end;

function TEdDSA.GetVersion: string;
begin
  Result := CkToStr(CkEdDSA_get_Version(FHandle));
end;

function TEdDSA.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkEdDSA_get_DebugLogFilePath(FHandle));
end;

procedure TEdDSA.SetDebugLogFilePath(AValue: string);
begin
  CkEdDSA_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TEdDSA.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkEdDSA_get_VerboseLogging(FHandle));
end;

procedure TEdDSA.SetVerboseLogging(AValue: Boolean);
begin
  CkEdDSA_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TEdDSA.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkEdDSA_get_LastMethodSuccess(FHandle));
end;

procedure TEdDSA.SetLastMethodSuccess(AValue: Boolean);
begin
  CkEdDSA_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TEdDSA.GetAlgorithm: string;
begin
  Result := CkToStr(CkEdDSA_get_Algorithm(FHandle));
end;

procedure TEdDSA.SetAlgorithm(AValue: string);
begin
  CkEdDSA_put_Algorithm(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TEdDSA.GetContext: string;
begin
  Result := CkToStr(CkEdDSA_get_Context(FHandle));
end;

procedure TEdDSA.SetContext(AValue: string);
begin
  CkEdDSA_put_Context(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TEdDSA.GenEd25519Key(prng: TChilkatBase; privKey: TChilkatBase): Boolean;
begin
  Result := Boolean(CkEdDSA_GenEd25519Key(FHandle, prng.Handle, privKey.Handle));
end;

function TEdDSA.SignBdENC(bd: TChilkatBase; const encoding: string; privkey: TChilkatBase): string;
begin
  Result := CkToStr(CkEdDSA_SignBdENC(FHandle, bd.Handle, PAnsiChar(StrToCk(encoding)), privkey.Handle));
end;

function TEdDSA.VerifyBdENC(bd: TChilkatBase; const encodedSig: string; const enocding: string; pubkey: TChilkatBase): Boolean;
begin
  Result := Boolean(CkEdDSA_VerifyBdENC(FHandle, bd.Handle, PAnsiChar(StrToCk(encodedSig)), PAnsiChar(StrToCk(enocding)), pubkey.Handle));
end;

function TEdDSA.SharedSecretENC(privkey: TChilkatBase; pubkey: TChilkatBase; const encoding: string): string;
begin
  Result := CkToStr(CkEdDSA_SharedSecretENC(FHandle, privkey.Handle, pubkey.Handle, PAnsiChar(StrToCk(encoding))));
end;

initialization
  Chilkat_GetProcedureAddress(CkEdDSA_Create,  'CkEdDSA_Create');
  Chilkat_GetProcedureAddress(CkEdDSA_Dispose, 'CkEdDSA_Dispose');
  Chilkat_GetProcedureAddress(CkEdDSA_get_LastErrorHtml, 'CkEdDSA_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkEdDSA_get_LastErrorText, 'CkEdDSA_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkEdDSA_get_LastErrorXml, 'CkEdDSA_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkEdDSA_get_Version, 'CkEdDSA_get_Version');
  Chilkat_GetProcedureAddress(CkEdDSA_get_DebugLogFilePath, 'CkEdDSA_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkEdDSA_put_DebugLogFilePath, 'CkEdDSA_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkEdDSA_get_VerboseLogging, 'CkEdDSA_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkEdDSA_put_VerboseLogging, 'CkEdDSA_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkEdDSA_get_LastMethodSuccess, 'CkEdDSA_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkEdDSA_put_LastMethodSuccess, 'CkEdDSA_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkEdDSA_get_Algorithm, 'CkEdDSA_get_Algorithm');
  Chilkat_GetProcedureAddress(CkEdDSA_put_Algorithm, 'CkEdDSA_put_Algorithm');
  Chilkat_GetProcedureAddress(CkEdDSA_get_Context, 'CkEdDSA_get_Context');
  Chilkat_GetProcedureAddress(CkEdDSA_put_Context, 'CkEdDSA_put_Context');
  Chilkat_GetProcedureAddress(CkEdDSA_GenEd25519Key, 'CkEdDSA_GenEd25519Key');
  Chilkat_GetProcedureAddress(CkEdDSA_SignBdENC, 'CkEdDSA_SignBdENC');
  Chilkat_GetProcedureAddress(CkEdDSA_VerifyBdENC, 'CkEdDSA_VerifyBdENC');
  Chilkat_GetProcedureAddress(CkEdDSA_SharedSecretENC, 'CkEdDSA_SharedSecretENC');

end.
