unit Chilkat.PublicKey;

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

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

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TPublicKey wraps CkPublicKey via the C bridge layer. }
  TPublicKey = 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  GetKeyType: string;
    function  GetKeySize: Integer;
    function  GetEmpty: 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 KeyType: string read GetKeyType;
    property KeySize: Integer read GetKeySize;
    property Empty: Boolean read GetEmpty;

    function  GetXml: string;
    function  LoadBase64(const keyStr: string): Boolean;
    function  SaveXmlFile(const path: string): Boolean;
    function  LoadFromString(const keyString: string): Boolean;
    function  LoadFromFile(const path: string): Boolean;
    function  GetPem(preferPkcs1: Boolean): string;
    function  GetEncoded(preferPkcs1: Boolean; const encoding: string): string;
    function  SaveDerFile(preferPkcs1: Boolean; const path: string): Boolean;
    function  SavePemFile(preferPkcs1: Boolean; const path: string): Boolean;
    function  GetJwk: string;
    function  GetJwkThumbprint(const hashAlg: string): string;
    function  LoadEd25519(const pubKey: string): Boolean;
    function  LoadBd(bd: TChilkatBase): Boolean;
    function  LoadEcdsa(const curveName: string; const Qx: string; const Qy: string): Boolean;
    function  GetDerBd(preferPkcs1: Boolean; bd: TChilkatBase): Boolean;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkPublicKey_Create  = function(): Pointer; cdecl;
  TCkPublicKey_Dispose = procedure(handle: Pointer); cdecl;
  TCkPublicKey_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPublicKey_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPublicKey_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPublicKey_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPublicKey_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPublicKey_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkPublicKey_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkPublicKey_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkPublicKey_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkPublicKey_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkPublicKey_get_KeyType = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPublicKey_get_KeySize = function(handle: Pointer): Integer; cdecl;
  TCkPublicKey_get_Empty = function(handle: Pointer): LongBool; cdecl;
  TCkPublicKey_GetXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPublicKey_LoadBase64 = function(handle: Pointer; keyStr: PAnsiChar): LongBool; cdecl;
  TCkPublicKey_SaveXmlFile = function(handle: Pointer; path: PAnsiChar): LongBool; cdecl;
  TCkPublicKey_LoadFromString = function(handle: Pointer; keyString: PAnsiChar): LongBool; cdecl;
  TCkPublicKey_LoadFromFile = function(handle: Pointer; path: PAnsiChar): LongBool; cdecl;
  TCkPublicKey_GetPem = function(handle: Pointer; preferPkcs1: LongBool): PAnsiChar; cdecl;
  TCkPublicKey_GetEncoded = function(handle: Pointer; preferPkcs1: LongBool; encoding: PAnsiChar): PAnsiChar; cdecl;
  TCkPublicKey_SaveDerFile = function(handle: Pointer; preferPkcs1: LongBool; path: PAnsiChar): LongBool; cdecl;
  TCkPublicKey_SavePemFile = function(handle: Pointer; preferPkcs1: LongBool; path: PAnsiChar): LongBool; cdecl;
  TCkPublicKey_GetJwk = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPublicKey_GetJwkThumbprint = function(handle: Pointer; hashAlg: PAnsiChar): PAnsiChar; cdecl;
  TCkPublicKey_LoadEd25519 = function(handle: Pointer; pubKey: PAnsiChar): LongBool; cdecl;
  TCkPublicKey_LoadBd = function(handle: Pointer; bd: Pointer): LongBool; cdecl;
  TCkPublicKey_LoadEcdsa = function(handle: Pointer; curveName: PAnsiChar; Qx: PAnsiChar; Qy: PAnsiChar): LongBool; cdecl;
  TCkPublicKey_GetDerBd = function(handle: Pointer; preferPkcs1: LongBool; bd: Pointer): LongBool; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkPublicKey_Create:  TCkPublicKey_Create  = nil;
  CkPublicKey_Dispose: TCkPublicKey_Dispose = nil;
  CkPublicKey_get_LastErrorHtml: TCkPublicKey_get_LastErrorHtml = nil;
  CkPublicKey_get_LastErrorText: TCkPublicKey_get_LastErrorText = nil;
  CkPublicKey_get_LastErrorXml: TCkPublicKey_get_LastErrorXml = nil;
  CkPublicKey_get_Version: TCkPublicKey_get_Version = nil;
  CkPublicKey_get_DebugLogFilePath: TCkPublicKey_get_DebugLogFilePath = nil;
  CkPublicKey_put_DebugLogFilePath: TCkPublicKey_put_DebugLogFilePath = nil;
  CkPublicKey_get_VerboseLogging: TCkPublicKey_get_VerboseLogging = nil;
  CkPublicKey_put_VerboseLogging: TCkPublicKey_put_VerboseLogging = nil;
  CkPublicKey_get_LastMethodSuccess: TCkPublicKey_get_LastMethodSuccess = nil;
  CkPublicKey_put_LastMethodSuccess: TCkPublicKey_put_LastMethodSuccess = nil;
  CkPublicKey_get_KeyType: TCkPublicKey_get_KeyType = nil;
  CkPublicKey_get_KeySize: TCkPublicKey_get_KeySize = nil;
  CkPublicKey_get_Empty: TCkPublicKey_get_Empty = nil;
  CkPublicKey_GetXml: TCkPublicKey_GetXml = nil;
  CkPublicKey_LoadBase64: TCkPublicKey_LoadBase64 = nil;
  CkPublicKey_SaveXmlFile: TCkPublicKey_SaveXmlFile = nil;
  CkPublicKey_LoadFromString: TCkPublicKey_LoadFromString = nil;
  CkPublicKey_LoadFromFile: TCkPublicKey_LoadFromFile = nil;
  CkPublicKey_GetPem: TCkPublicKey_GetPem = nil;
  CkPublicKey_GetEncoded: TCkPublicKey_GetEncoded = nil;
  CkPublicKey_SaveDerFile: TCkPublicKey_SaveDerFile = nil;
  CkPublicKey_SavePemFile: TCkPublicKey_SavePemFile = nil;
  CkPublicKey_GetJwk: TCkPublicKey_GetJwk = nil;
  CkPublicKey_GetJwkThumbprint: TCkPublicKey_GetJwkThumbprint = nil;
  CkPublicKey_LoadEd25519: TCkPublicKey_LoadEd25519 = nil;
  CkPublicKey_LoadBd: TCkPublicKey_LoadBd = nil;
  CkPublicKey_LoadEcdsa: TCkPublicKey_LoadEcdsa = nil;
  CkPublicKey_GetDerBd: TCkPublicKey_GetDerBd = nil;

constructor TPublicKey.Create;
begin
  inherited Create;
  FHandle := CkPublicKey_Create();
end;

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

function TPublicKey.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkPublicKey_get_LastErrorHtml(FHandle));
end;

function TPublicKey.GetLastErrorText: string;
begin
  Result := CkToStr(CkPublicKey_get_LastErrorText(FHandle));
end;

function TPublicKey.GetLastErrorXml: string;
begin
  Result := CkToStr(CkPublicKey_get_LastErrorXml(FHandle));
end;

function TPublicKey.GetVersion: string;
begin
  Result := CkToStr(CkPublicKey_get_Version(FHandle));
end;

function TPublicKey.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkPublicKey_get_DebugLogFilePath(FHandle));
end;

procedure TPublicKey.SetDebugLogFilePath(AValue: string);
begin
  CkPublicKey_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TPublicKey.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkPublicKey_get_VerboseLogging(FHandle));
end;

procedure TPublicKey.SetVerboseLogging(AValue: Boolean);
begin
  CkPublicKey_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TPublicKey.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkPublicKey_get_LastMethodSuccess(FHandle));
end;

procedure TPublicKey.SetLastMethodSuccess(AValue: Boolean);
begin
  CkPublicKey_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TPublicKey.GetKeyType: string;
begin
  Result := CkToStr(CkPublicKey_get_KeyType(FHandle));
end;

function TPublicKey.GetKeySize: Integer;
begin
  Result := CkPublicKey_get_KeySize(FHandle);
end;

function TPublicKey.GetEmpty: Boolean;
begin
  Result := Boolean(CkPublicKey_get_Empty(FHandle));
end;

function TPublicKey.GetXml: string;
begin
  Result := CkToStr(CkPublicKey_GetXml(FHandle));
end;

function TPublicKey.LoadBase64(const keyStr: string): Boolean;
begin
  Result := Boolean(CkPublicKey_LoadBase64(FHandle, PAnsiChar(StrToCk(keyStr))));
end;

function TPublicKey.SaveXmlFile(const path: string): Boolean;
begin
  Result := Boolean(CkPublicKey_SaveXmlFile(FHandle, PAnsiChar(StrToCk(path))));
end;

function TPublicKey.LoadFromString(const keyString: string): Boolean;
begin
  Result := Boolean(CkPublicKey_LoadFromString(FHandle, PAnsiChar(StrToCk(keyString))));
end;

function TPublicKey.LoadFromFile(const path: string): Boolean;
begin
  Result := Boolean(CkPublicKey_LoadFromFile(FHandle, PAnsiChar(StrToCk(path))));
end;

function TPublicKey.GetPem(preferPkcs1: Boolean): string;
begin
  Result := CkToStr(CkPublicKey_GetPem(FHandle, LongBool(preferPkcs1)));
end;

function TPublicKey.GetEncoded(preferPkcs1: Boolean; const encoding: string): string;
begin
  Result := CkToStr(CkPublicKey_GetEncoded(FHandle, LongBool(preferPkcs1), PAnsiChar(StrToCk(encoding))));
end;

function TPublicKey.SaveDerFile(preferPkcs1: Boolean; const path: string): Boolean;
begin
  Result := Boolean(CkPublicKey_SaveDerFile(FHandle, LongBool(preferPkcs1), PAnsiChar(StrToCk(path))));
end;

function TPublicKey.SavePemFile(preferPkcs1: Boolean; const path: string): Boolean;
begin
  Result := Boolean(CkPublicKey_SavePemFile(FHandle, LongBool(preferPkcs1), PAnsiChar(StrToCk(path))));
end;

function TPublicKey.GetJwk: string;
begin
  Result := CkToStr(CkPublicKey_GetJwk(FHandle));
end;

function TPublicKey.GetJwkThumbprint(const hashAlg: string): string;
begin
  Result := CkToStr(CkPublicKey_GetJwkThumbprint(FHandle, PAnsiChar(StrToCk(hashAlg))));
end;

function TPublicKey.LoadEd25519(const pubKey: string): Boolean;
begin
  Result := Boolean(CkPublicKey_LoadEd25519(FHandle, PAnsiChar(StrToCk(pubKey))));
end;

function TPublicKey.LoadBd(bd: TChilkatBase): Boolean;
begin
  Result := Boolean(CkPublicKey_LoadBd(FHandle, bd.Handle));
end;

function TPublicKey.LoadEcdsa(const curveName: string; const Qx: string; const Qy: string): Boolean;
begin
  Result := Boolean(CkPublicKey_LoadEcdsa(FHandle, PAnsiChar(StrToCk(curveName)), PAnsiChar(StrToCk(Qx)), PAnsiChar(StrToCk(Qy))));
end;

function TPublicKey.GetDerBd(preferPkcs1: Boolean; bd: TChilkatBase): Boolean;
begin
  Result := Boolean(CkPublicKey_GetDerBd(FHandle, LongBool(preferPkcs1), bd.Handle));
end;

initialization
  Chilkat_GetProcedureAddress(CkPublicKey_Create,  'CkPublicKey_Create');
  Chilkat_GetProcedureAddress(CkPublicKey_Dispose, 'CkPublicKey_Dispose');
  Chilkat_GetProcedureAddress(CkPublicKey_get_LastErrorHtml, 'CkPublicKey_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkPublicKey_get_LastErrorText, 'CkPublicKey_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkPublicKey_get_LastErrorXml, 'CkPublicKey_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkPublicKey_get_Version, 'CkPublicKey_get_Version');
  Chilkat_GetProcedureAddress(CkPublicKey_get_DebugLogFilePath, 'CkPublicKey_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkPublicKey_put_DebugLogFilePath, 'CkPublicKey_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkPublicKey_get_VerboseLogging, 'CkPublicKey_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkPublicKey_put_VerboseLogging, 'CkPublicKey_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkPublicKey_get_LastMethodSuccess, 'CkPublicKey_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkPublicKey_put_LastMethodSuccess, 'CkPublicKey_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkPublicKey_get_KeyType, 'CkPublicKey_get_KeyType');
  Chilkat_GetProcedureAddress(CkPublicKey_get_KeySize, 'CkPublicKey_get_KeySize');
  Chilkat_GetProcedureAddress(CkPublicKey_get_Empty, 'CkPublicKey_get_Empty');
  Chilkat_GetProcedureAddress(CkPublicKey_GetXml, 'CkPublicKey_GetXml');
  Chilkat_GetProcedureAddress(CkPublicKey_LoadBase64, 'CkPublicKey_LoadBase64');
  Chilkat_GetProcedureAddress(CkPublicKey_SaveXmlFile, 'CkPublicKey_SaveXmlFile');
  Chilkat_GetProcedureAddress(CkPublicKey_LoadFromString, 'CkPublicKey_LoadFromString');
  Chilkat_GetProcedureAddress(CkPublicKey_LoadFromFile, 'CkPublicKey_LoadFromFile');
  Chilkat_GetProcedureAddress(CkPublicKey_GetPem, 'CkPublicKey_GetPem');
  Chilkat_GetProcedureAddress(CkPublicKey_GetEncoded, 'CkPublicKey_GetEncoded');
  Chilkat_GetProcedureAddress(CkPublicKey_SaveDerFile, 'CkPublicKey_SaveDerFile');
  Chilkat_GetProcedureAddress(CkPublicKey_SavePemFile, 'CkPublicKey_SavePemFile');
  Chilkat_GetProcedureAddress(CkPublicKey_GetJwk, 'CkPublicKey_GetJwk');
  Chilkat_GetProcedureAddress(CkPublicKey_GetJwkThumbprint, 'CkPublicKey_GetJwkThumbprint');
  Chilkat_GetProcedureAddress(CkPublicKey_LoadEd25519, 'CkPublicKey_LoadEd25519');
  Chilkat_GetProcedureAddress(CkPublicKey_LoadBd, 'CkPublicKey_LoadBd');
  Chilkat_GetProcedureAddress(CkPublicKey_LoadEcdsa, 'CkPublicKey_LoadEcdsa');
  Chilkat_GetProcedureAddress(CkPublicKey_GetDerBd, 'CkPublicKey_GetDerBd');

end.
