unit Chilkat.CertStore;

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

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

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TCertStore wraps CkCertStore via the C bridge layer. }
  TCertStore = 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  GetAvoidWindowsPkAccess: Boolean;
    procedure SetAvoidWindowsPkAccess(AValue: Boolean);
    function  GetNumCertificates: Integer;
    function  GetSmartCardPin: string;
    procedure SetSmartCardPin(AValue: string);
    function  GetUncommonOptions: string;
    procedure SetUncommonOptions(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 AvoidWindowsPkAccess: Boolean read GetAvoidWindowsPkAccess write SetAvoidWindowsPkAccess;
    property NumCertificates: Integer read GetNumCertificates;
    property SmartCardPin: string read GetSmartCardPin write SetSmartCardPin;
    property UncommonOptions: string read GetUncommonOptions write SetUncommonOptions;

    function  AddCertificate(cert: TChilkatBase): Boolean;
    function  CreateFileStore(const filename: string): Boolean;
    function  CreateMemoryStore: Boolean;
    function  CreateRegistryStore(const regRoot: string; const regPath: string): Boolean;
    function  LoadPemFile(const pemPath: string): Boolean;
    function  LoadPemStr(const pemString: string): Boolean;
    function  LoadPfxFile(const pfxFilename: string; const password: string): Boolean;
    function  OpenCurrentUserStore(readOnly: Boolean): Boolean;
    function  OpenFileStore(const filename: string; readOnly: Boolean): Boolean;
    function  OpenLocalSystemStore(readOnly: Boolean): Boolean;
    function  OpenRegistryStore(const regRoot: string; const regPath: string; readOnly: Boolean): Boolean;
    function  OpenWindowsStore(const storeLocation: string; const storeName: string; readOnly: Boolean): Boolean;
    function  RemoveCertificate(cert: TChilkatBase): Boolean;
    function  OpenSmartcard(const csp: string): Boolean;
    function  CloseCertStore: Boolean;
    function  FindCert(json: TChilkatBase; cert: TChilkatBase): Boolean;
    function  LoadPfxBd(bd: TChilkatBase; const password: string): Boolean;
    function  GetCert(index: Integer; cert: TChilkatBase): Boolean;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkCertStore_Create  = function(): Pointer; cdecl;
  TCkCertStore_Dispose = procedure(handle: Pointer); cdecl;
  TCkCertStore_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCertStore_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCertStore_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCertStore_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCertStore_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCertStore_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCertStore_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkCertStore_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkCertStore_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkCertStore_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkCertStore_get_AvoidWindowsPkAccess = function(handle: Pointer): LongBool; cdecl;
  TCkCertStore_put_AvoidWindowsPkAccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkCertStore_get_NumCertificates = function(handle: Pointer): Integer; cdecl;
  TCkCertStore_get_SmartCardPin = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCertStore_put_SmartCardPin = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCertStore_get_UncommonOptions = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCertStore_put_UncommonOptions = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCertStore_AddCertificate = function(handle: Pointer; cert: Pointer): LongBool; cdecl;
  TCkCertStore_CreateFileStore = function(handle: Pointer; filename: PAnsiChar): LongBool; cdecl;
  TCkCertStore_CreateMemoryStore = function(handle: Pointer): LongBool; cdecl;
  TCkCertStore_CreateRegistryStore = function(handle: Pointer; regRoot: PAnsiChar; regPath: PAnsiChar): LongBool; cdecl;
  TCkCertStore_LoadPemFile = function(handle: Pointer; pemPath: PAnsiChar): LongBool; cdecl;
  TCkCertStore_LoadPemStr = function(handle: Pointer; pemString: PAnsiChar): LongBool; cdecl;
  TCkCertStore_LoadPfxFile = function(handle: Pointer; pfxFilename: PAnsiChar; password: PAnsiChar): LongBool; cdecl;
  TCkCertStore_OpenCurrentUserStore = function(handle: Pointer; readOnly: LongBool): LongBool; cdecl;
  TCkCertStore_OpenFileStore = function(handle: Pointer; filename: PAnsiChar; readOnly: LongBool): LongBool; cdecl;
  TCkCertStore_OpenLocalSystemStore = function(handle: Pointer; readOnly: LongBool): LongBool; cdecl;
  TCkCertStore_OpenRegistryStore = function(handle: Pointer; regRoot: PAnsiChar; regPath: PAnsiChar; readOnly: LongBool): LongBool; cdecl;
  TCkCertStore_OpenWindowsStore = function(handle: Pointer; storeLocation: PAnsiChar; storeName: PAnsiChar; readOnly: LongBool): LongBool; cdecl;
  TCkCertStore_RemoveCertificate = function(handle: Pointer; cert: Pointer): LongBool; cdecl;
  TCkCertStore_OpenSmartcard = function(handle: Pointer; csp: PAnsiChar): LongBool; cdecl;
  TCkCertStore_CloseCertStore = function(handle: Pointer): LongBool; cdecl;
  TCkCertStore_FindCert = function(handle: Pointer; json: Pointer; cert: Pointer): LongBool; cdecl;
  TCkCertStore_LoadPfxBd = function(handle: Pointer; bd: Pointer; password: PAnsiChar): LongBool; cdecl;
  TCkCertStore_GetCert = function(handle: Pointer; index: Integer; cert: Pointer): LongBool; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkCertStore_Create:  TCkCertStore_Create  = nil;
  CkCertStore_Dispose: TCkCertStore_Dispose = nil;
  CkCertStore_get_LastErrorHtml: TCkCertStore_get_LastErrorHtml = nil;
  CkCertStore_get_LastErrorText: TCkCertStore_get_LastErrorText = nil;
  CkCertStore_get_LastErrorXml: TCkCertStore_get_LastErrorXml = nil;
  CkCertStore_get_Version: TCkCertStore_get_Version = nil;
  CkCertStore_get_DebugLogFilePath: TCkCertStore_get_DebugLogFilePath = nil;
  CkCertStore_put_DebugLogFilePath: TCkCertStore_put_DebugLogFilePath = nil;
  CkCertStore_get_VerboseLogging: TCkCertStore_get_VerboseLogging = nil;
  CkCertStore_put_VerboseLogging: TCkCertStore_put_VerboseLogging = nil;
  CkCertStore_get_LastMethodSuccess: TCkCertStore_get_LastMethodSuccess = nil;
  CkCertStore_put_LastMethodSuccess: TCkCertStore_put_LastMethodSuccess = nil;
  CkCertStore_get_AvoidWindowsPkAccess: TCkCertStore_get_AvoidWindowsPkAccess = nil;
  CkCertStore_put_AvoidWindowsPkAccess: TCkCertStore_put_AvoidWindowsPkAccess = nil;
  CkCertStore_get_NumCertificates: TCkCertStore_get_NumCertificates = nil;
  CkCertStore_get_SmartCardPin: TCkCertStore_get_SmartCardPin = nil;
  CkCertStore_put_SmartCardPin: TCkCertStore_put_SmartCardPin = nil;
  CkCertStore_get_UncommonOptions: TCkCertStore_get_UncommonOptions = nil;
  CkCertStore_put_UncommonOptions: TCkCertStore_put_UncommonOptions = nil;
  CkCertStore_AddCertificate: TCkCertStore_AddCertificate = nil;
  CkCertStore_CreateFileStore: TCkCertStore_CreateFileStore = nil;
  CkCertStore_CreateMemoryStore: TCkCertStore_CreateMemoryStore = nil;
  CkCertStore_CreateRegistryStore: TCkCertStore_CreateRegistryStore = nil;
  CkCertStore_LoadPemFile: TCkCertStore_LoadPemFile = nil;
  CkCertStore_LoadPemStr: TCkCertStore_LoadPemStr = nil;
  CkCertStore_LoadPfxFile: TCkCertStore_LoadPfxFile = nil;
  CkCertStore_OpenCurrentUserStore: TCkCertStore_OpenCurrentUserStore = nil;
  CkCertStore_OpenFileStore: TCkCertStore_OpenFileStore = nil;
  CkCertStore_OpenLocalSystemStore: TCkCertStore_OpenLocalSystemStore = nil;
  CkCertStore_OpenRegistryStore: TCkCertStore_OpenRegistryStore = nil;
  CkCertStore_OpenWindowsStore: TCkCertStore_OpenWindowsStore = nil;
  CkCertStore_RemoveCertificate: TCkCertStore_RemoveCertificate = nil;
  CkCertStore_OpenSmartcard: TCkCertStore_OpenSmartcard = nil;
  CkCertStore_CloseCertStore: TCkCertStore_CloseCertStore = nil;
  CkCertStore_FindCert: TCkCertStore_FindCert = nil;
  CkCertStore_LoadPfxBd: TCkCertStore_LoadPfxBd = nil;
  CkCertStore_GetCert: TCkCertStore_GetCert = nil;

constructor TCertStore.Create;
begin
  inherited Create;
  FHandle := CkCertStore_Create();
end;

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

function TCertStore.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkCertStore_get_LastErrorHtml(FHandle));
end;

function TCertStore.GetLastErrorText: string;
begin
  Result := CkToStr(CkCertStore_get_LastErrorText(FHandle));
end;

function TCertStore.GetLastErrorXml: string;
begin
  Result := CkToStr(CkCertStore_get_LastErrorXml(FHandle));
end;

function TCertStore.GetVersion: string;
begin
  Result := CkToStr(CkCertStore_get_Version(FHandle));
end;

function TCertStore.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkCertStore_get_DebugLogFilePath(FHandle));
end;

procedure TCertStore.SetDebugLogFilePath(AValue: string);
begin
  CkCertStore_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCertStore.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkCertStore_get_VerboseLogging(FHandle));
end;

procedure TCertStore.SetVerboseLogging(AValue: Boolean);
begin
  CkCertStore_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TCertStore.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkCertStore_get_LastMethodSuccess(FHandle));
end;

procedure TCertStore.SetLastMethodSuccess(AValue: Boolean);
begin
  CkCertStore_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TCertStore.GetAvoidWindowsPkAccess: Boolean;
begin
  Result := Boolean(CkCertStore_get_AvoidWindowsPkAccess(FHandle));
end;

procedure TCertStore.SetAvoidWindowsPkAccess(AValue: Boolean);
begin
  CkCertStore_put_AvoidWindowsPkAccess(FHandle, LongBool(AValue));
end;

function TCertStore.GetNumCertificates: Integer;
begin
  Result := CkCertStore_get_NumCertificates(FHandle);
end;

function TCertStore.GetSmartCardPin: string;
begin
  Result := CkToStr(CkCertStore_get_SmartCardPin(FHandle));
end;

procedure TCertStore.SetSmartCardPin(AValue: string);
begin
  CkCertStore_put_SmartCardPin(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCertStore.GetUncommonOptions: string;
begin
  Result := CkToStr(CkCertStore_get_UncommonOptions(FHandle));
end;

procedure TCertStore.SetUncommonOptions(AValue: string);
begin
  CkCertStore_put_UncommonOptions(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCertStore.AddCertificate(cert: TChilkatBase): Boolean;
begin
  Result := Boolean(CkCertStore_AddCertificate(FHandle, cert.Handle));
end;

function TCertStore.CreateFileStore(const filename: string): Boolean;
begin
  Result := Boolean(CkCertStore_CreateFileStore(FHandle, PAnsiChar(StrToCk(filename))));
end;

function TCertStore.CreateMemoryStore: Boolean;
begin
  Result := Boolean(CkCertStore_CreateMemoryStore(FHandle));
end;

function TCertStore.CreateRegistryStore(const regRoot: string; const regPath: string): Boolean;
begin
  Result := Boolean(CkCertStore_CreateRegistryStore(FHandle, PAnsiChar(StrToCk(regRoot)), PAnsiChar(StrToCk(regPath))));
end;

function TCertStore.LoadPemFile(const pemPath: string): Boolean;
begin
  Result := Boolean(CkCertStore_LoadPemFile(FHandle, PAnsiChar(StrToCk(pemPath))));
end;

function TCertStore.LoadPemStr(const pemString: string): Boolean;
begin
  Result := Boolean(CkCertStore_LoadPemStr(FHandle, PAnsiChar(StrToCk(pemString))));
end;

function TCertStore.LoadPfxFile(const pfxFilename: string; const password: string): Boolean;
begin
  Result := Boolean(CkCertStore_LoadPfxFile(FHandle, PAnsiChar(StrToCk(pfxFilename)), PAnsiChar(StrToCk(password))));
end;

function TCertStore.OpenCurrentUserStore(readOnly: Boolean): Boolean;
begin
  Result := Boolean(CkCertStore_OpenCurrentUserStore(FHandle, LongBool(readOnly)));
end;

function TCertStore.OpenFileStore(const filename: string; readOnly: Boolean): Boolean;
begin
  Result := Boolean(CkCertStore_OpenFileStore(FHandle, PAnsiChar(StrToCk(filename)), LongBool(readOnly)));
end;

function TCertStore.OpenLocalSystemStore(readOnly: Boolean): Boolean;
begin
  Result := Boolean(CkCertStore_OpenLocalSystemStore(FHandle, LongBool(readOnly)));
end;

function TCertStore.OpenRegistryStore(const regRoot: string; const regPath: string; readOnly: Boolean): Boolean;
begin
  Result := Boolean(CkCertStore_OpenRegistryStore(FHandle, PAnsiChar(StrToCk(regRoot)), PAnsiChar(StrToCk(regPath)), LongBool(readOnly)));
end;

function TCertStore.OpenWindowsStore(const storeLocation: string; const storeName: string; readOnly: Boolean): Boolean;
begin
  Result := Boolean(CkCertStore_OpenWindowsStore(FHandle, PAnsiChar(StrToCk(storeLocation)), PAnsiChar(StrToCk(storeName)), LongBool(readOnly)));
end;

function TCertStore.RemoveCertificate(cert: TChilkatBase): Boolean;
begin
  Result := Boolean(CkCertStore_RemoveCertificate(FHandle, cert.Handle));
end;

function TCertStore.OpenSmartcard(const csp: string): Boolean;
begin
  Result := Boolean(CkCertStore_OpenSmartcard(FHandle, PAnsiChar(StrToCk(csp))));
end;

function TCertStore.CloseCertStore: Boolean;
begin
  Result := Boolean(CkCertStore_CloseCertStore(FHandle));
end;

function TCertStore.FindCert(json: TChilkatBase; cert: TChilkatBase): Boolean;
begin
  Result := Boolean(CkCertStore_FindCert(FHandle, json.Handle, cert.Handle));
end;

function TCertStore.LoadPfxBd(bd: TChilkatBase; const password: string): Boolean;
begin
  Result := Boolean(CkCertStore_LoadPfxBd(FHandle, bd.Handle, PAnsiChar(StrToCk(password))));
end;

function TCertStore.GetCert(index: Integer; cert: TChilkatBase): Boolean;
begin
  Result := Boolean(CkCertStore_GetCert(FHandle, index, cert.Handle));
end;

initialization
  Chilkat_GetProcedureAddress(CkCertStore_Create,  'CkCertStore_Create');
  Chilkat_GetProcedureAddress(CkCertStore_Dispose, 'CkCertStore_Dispose');
  Chilkat_GetProcedureAddress(CkCertStore_get_LastErrorHtml, 'CkCertStore_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkCertStore_get_LastErrorText, 'CkCertStore_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkCertStore_get_LastErrorXml, 'CkCertStore_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkCertStore_get_Version, 'CkCertStore_get_Version');
  Chilkat_GetProcedureAddress(CkCertStore_get_DebugLogFilePath, 'CkCertStore_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkCertStore_put_DebugLogFilePath, 'CkCertStore_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkCertStore_get_VerboseLogging, 'CkCertStore_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkCertStore_put_VerboseLogging, 'CkCertStore_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkCertStore_get_LastMethodSuccess, 'CkCertStore_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkCertStore_put_LastMethodSuccess, 'CkCertStore_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkCertStore_get_AvoidWindowsPkAccess, 'CkCertStore_get_AvoidWindowsPkAccess');
  Chilkat_GetProcedureAddress(CkCertStore_put_AvoidWindowsPkAccess, 'CkCertStore_put_AvoidWindowsPkAccess');
  Chilkat_GetProcedureAddress(CkCertStore_get_NumCertificates, 'CkCertStore_get_NumCertificates');
  Chilkat_GetProcedureAddress(CkCertStore_get_SmartCardPin, 'CkCertStore_get_SmartCardPin');
  Chilkat_GetProcedureAddress(CkCertStore_put_SmartCardPin, 'CkCertStore_put_SmartCardPin');
  Chilkat_GetProcedureAddress(CkCertStore_get_UncommonOptions, 'CkCertStore_get_UncommonOptions');
  Chilkat_GetProcedureAddress(CkCertStore_put_UncommonOptions, 'CkCertStore_put_UncommonOptions');
  Chilkat_GetProcedureAddress(CkCertStore_AddCertificate, 'CkCertStore_AddCertificate');
  Chilkat_GetProcedureAddress(CkCertStore_CreateFileStore, 'CkCertStore_CreateFileStore');
  Chilkat_GetProcedureAddress(CkCertStore_CreateMemoryStore, 'CkCertStore_CreateMemoryStore');
  Chilkat_GetProcedureAddress(CkCertStore_CreateRegistryStore, 'CkCertStore_CreateRegistryStore');
  Chilkat_GetProcedureAddress(CkCertStore_LoadPemFile, 'CkCertStore_LoadPemFile');
  Chilkat_GetProcedureAddress(CkCertStore_LoadPemStr, 'CkCertStore_LoadPemStr');
  Chilkat_GetProcedureAddress(CkCertStore_LoadPfxFile, 'CkCertStore_LoadPfxFile');
  Chilkat_GetProcedureAddress(CkCertStore_OpenCurrentUserStore, 'CkCertStore_OpenCurrentUserStore');
  Chilkat_GetProcedureAddress(CkCertStore_OpenFileStore, 'CkCertStore_OpenFileStore');
  Chilkat_GetProcedureAddress(CkCertStore_OpenLocalSystemStore, 'CkCertStore_OpenLocalSystemStore');
  Chilkat_GetProcedureAddress(CkCertStore_OpenRegistryStore, 'CkCertStore_OpenRegistryStore');
  Chilkat_GetProcedureAddress(CkCertStore_OpenWindowsStore, 'CkCertStore_OpenWindowsStore');
  Chilkat_GetProcedureAddress(CkCertStore_RemoveCertificate, 'CkCertStore_RemoveCertificate');
  Chilkat_GetProcedureAddress(CkCertStore_OpenSmartcard, 'CkCertStore_OpenSmartcard');
  Chilkat_GetProcedureAddress(CkCertStore_CloseCertStore, 'CkCertStore_CloseCertStore');
  Chilkat_GetProcedureAddress(CkCertStore_FindCert, 'CkCertStore_FindCert');
  Chilkat_GetProcedureAddress(CkCertStore_LoadPfxBd, 'CkCertStore_LoadPfxBd');
  Chilkat_GetProcedureAddress(CkCertStore_GetCert, 'CkCertStore_GetCert');

end.
