unit Chilkat.Csr;

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

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

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TCsr wraps CkCsr via the C bridge layer. }
  TCsr = 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  GetCommonName: string;
    procedure SetCommonName(AValue: string);
    function  GetCountry: string;
    procedure SetCountry(AValue: string);
    function  GetState: string;
    procedure SetState(AValue: string);
    function  GetLocality: string;
    procedure SetLocality(AValue: string);
    function  GetCompany: string;
    procedure SetCompany(AValue: string);
    function  GetCompanyDivision: string;
    procedure SetCompanyDivision(AValue: string);
    function  GetEmailAddress: string;
    procedure SetEmailAddress(AValue: string);
    function  GetHashAlgorithm: string;
    procedure SetHashAlgorithm(AValue: string);
    function  GetPssPadding: Boolean;
    procedure SetPssPadding(AValue: Boolean);
    function  GetMgfHashAlg: string;
    procedure SetMgfHashAlg(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 CommonName: string read GetCommonName write SetCommonName;
    property Country: string read GetCountry write SetCountry;
    property State: string read GetState write SetState;
    property Locality: string read GetLocality write SetLocality;
    property Company: string read GetCompany write SetCompany;
    property CompanyDivision: string read GetCompanyDivision write SetCompanyDivision;
    property EmailAddress: string read GetEmailAddress write SetEmailAddress;
    property HashAlgorithm: string read GetHashAlgorithm write SetHashAlgorithm;
    property PssPadding: Boolean read GetPssPadding write SetPssPadding;
    property MgfHashAlg: string read GetMgfHashAlg write SetMgfHashAlg;

    function  GenCsrPem(privKey: TChilkatBase): string;
    function  GenCsrBd(privKey: TChilkatBase; csrData: TChilkatBase): Boolean;
    function  SetSubjectField(const oid: string; const value: string; const asnType: string): Boolean;
    function  LoadCsrPem(const csrPemStr: string): Boolean;
    function  GetSubjectField(const oid: string): string;
    function  GetPublicKey(pubkey: TChilkatBase): Boolean;
    function  VerifyCsr: Boolean;
    function  AddSan(const sanType: string; const sanValue: string): Boolean;
    function  GetSans(sans: TChilkatBase): Boolean;
    function  SetExtensionRequest(extensionReqXml: TChilkatBase): Boolean;
    function  GetExtensionRequest(extensionReqXml: TChilkatBase): Boolean;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkCsr_Create  = function(): Pointer; cdecl;
  TCkCsr_Dispose = procedure(handle: Pointer); cdecl;
  TCkCsr_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCsr_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkCsr_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkCsr_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkCsr_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkCsr_get_CommonName = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_put_CommonName = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCsr_get_Country = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_put_Country = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCsr_get_State = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_put_State = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCsr_get_Locality = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_put_Locality = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCsr_get_Company = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_put_Company = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCsr_get_CompanyDivision = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_put_CompanyDivision = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCsr_get_EmailAddress = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_put_EmailAddress = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCsr_get_HashAlgorithm = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_put_HashAlgorithm = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCsr_get_PssPadding = function(handle: Pointer): LongBool; cdecl;
  TCkCsr_put_PssPadding = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkCsr_get_MgfHashAlg = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCsr_put_MgfHashAlg = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCsr_GenCsrPem = function(handle: Pointer; privKey: Pointer): PAnsiChar; cdecl;
  TCkCsr_GenCsrBd = function(handle: Pointer; privKey: Pointer; csrData: Pointer): LongBool; cdecl;
  TCkCsr_SetSubjectField = function(handle: Pointer; oid: PAnsiChar; value: PAnsiChar; asnType: PAnsiChar): LongBool; cdecl;
  TCkCsr_LoadCsrPem = function(handle: Pointer; csrPemStr: PAnsiChar): LongBool; cdecl;
  TCkCsr_GetSubjectField = function(handle: Pointer; oid: PAnsiChar): PAnsiChar; cdecl;
  TCkCsr_GetPublicKey = function(handle: Pointer; pubkey: Pointer): LongBool; cdecl;
  TCkCsr_VerifyCsr = function(handle: Pointer): LongBool; cdecl;
  TCkCsr_AddSan = function(handle: Pointer; sanType: PAnsiChar; sanValue: PAnsiChar): LongBool; cdecl;
  TCkCsr_GetSans = function(handle: Pointer; sans: Pointer): LongBool; cdecl;
  TCkCsr_SetExtensionRequest = function(handle: Pointer; extensionReqXml: Pointer): LongBool; cdecl;
  TCkCsr_GetExtensionRequest = function(handle: Pointer; extensionReqXml: Pointer): LongBool; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkCsr_Create:  TCkCsr_Create  = nil;
  CkCsr_Dispose: TCkCsr_Dispose = nil;
  CkCsr_get_LastErrorHtml: TCkCsr_get_LastErrorHtml = nil;
  CkCsr_get_LastErrorText: TCkCsr_get_LastErrorText = nil;
  CkCsr_get_LastErrorXml: TCkCsr_get_LastErrorXml = nil;
  CkCsr_get_Version: TCkCsr_get_Version = nil;
  CkCsr_get_DebugLogFilePath: TCkCsr_get_DebugLogFilePath = nil;
  CkCsr_put_DebugLogFilePath: TCkCsr_put_DebugLogFilePath = nil;
  CkCsr_get_VerboseLogging: TCkCsr_get_VerboseLogging = nil;
  CkCsr_put_VerboseLogging: TCkCsr_put_VerboseLogging = nil;
  CkCsr_get_LastMethodSuccess: TCkCsr_get_LastMethodSuccess = nil;
  CkCsr_put_LastMethodSuccess: TCkCsr_put_LastMethodSuccess = nil;
  CkCsr_get_CommonName: TCkCsr_get_CommonName = nil;
  CkCsr_put_CommonName: TCkCsr_put_CommonName = nil;
  CkCsr_get_Country: TCkCsr_get_Country = nil;
  CkCsr_put_Country: TCkCsr_put_Country = nil;
  CkCsr_get_State: TCkCsr_get_State = nil;
  CkCsr_put_State: TCkCsr_put_State = nil;
  CkCsr_get_Locality: TCkCsr_get_Locality = nil;
  CkCsr_put_Locality: TCkCsr_put_Locality = nil;
  CkCsr_get_Company: TCkCsr_get_Company = nil;
  CkCsr_put_Company: TCkCsr_put_Company = nil;
  CkCsr_get_CompanyDivision: TCkCsr_get_CompanyDivision = nil;
  CkCsr_put_CompanyDivision: TCkCsr_put_CompanyDivision = nil;
  CkCsr_get_EmailAddress: TCkCsr_get_EmailAddress = nil;
  CkCsr_put_EmailAddress: TCkCsr_put_EmailAddress = nil;
  CkCsr_get_HashAlgorithm: TCkCsr_get_HashAlgorithm = nil;
  CkCsr_put_HashAlgorithm: TCkCsr_put_HashAlgorithm = nil;
  CkCsr_get_PssPadding: TCkCsr_get_PssPadding = nil;
  CkCsr_put_PssPadding: TCkCsr_put_PssPadding = nil;
  CkCsr_get_MgfHashAlg: TCkCsr_get_MgfHashAlg = nil;
  CkCsr_put_MgfHashAlg: TCkCsr_put_MgfHashAlg = nil;
  CkCsr_GenCsrPem: TCkCsr_GenCsrPem = nil;
  CkCsr_GenCsrBd: TCkCsr_GenCsrBd = nil;
  CkCsr_SetSubjectField: TCkCsr_SetSubjectField = nil;
  CkCsr_LoadCsrPem: TCkCsr_LoadCsrPem = nil;
  CkCsr_GetSubjectField: TCkCsr_GetSubjectField = nil;
  CkCsr_GetPublicKey: TCkCsr_GetPublicKey = nil;
  CkCsr_VerifyCsr: TCkCsr_VerifyCsr = nil;
  CkCsr_AddSan: TCkCsr_AddSan = nil;
  CkCsr_GetSans: TCkCsr_GetSans = nil;
  CkCsr_SetExtensionRequest: TCkCsr_SetExtensionRequest = nil;
  CkCsr_GetExtensionRequest: TCkCsr_GetExtensionRequest = nil;

constructor TCsr.Create;
begin
  inherited Create;
  FHandle := CkCsr_Create();
end;

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

function TCsr.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkCsr_get_LastErrorHtml(FHandle));
end;

function TCsr.GetLastErrorText: string;
begin
  Result := CkToStr(CkCsr_get_LastErrorText(FHandle));
end;

function TCsr.GetLastErrorXml: string;
begin
  Result := CkToStr(CkCsr_get_LastErrorXml(FHandle));
end;

function TCsr.GetVersion: string;
begin
  Result := CkToStr(CkCsr_get_Version(FHandle));
end;

function TCsr.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkCsr_get_DebugLogFilePath(FHandle));
end;

procedure TCsr.SetDebugLogFilePath(AValue: string);
begin
  CkCsr_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCsr.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkCsr_get_VerboseLogging(FHandle));
end;

procedure TCsr.SetVerboseLogging(AValue: Boolean);
begin
  CkCsr_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TCsr.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkCsr_get_LastMethodSuccess(FHandle));
end;

procedure TCsr.SetLastMethodSuccess(AValue: Boolean);
begin
  CkCsr_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TCsr.GetCommonName: string;
begin
  Result := CkToStr(CkCsr_get_CommonName(FHandle));
end;

procedure TCsr.SetCommonName(AValue: string);
begin
  CkCsr_put_CommonName(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCsr.GetCountry: string;
begin
  Result := CkToStr(CkCsr_get_Country(FHandle));
end;

procedure TCsr.SetCountry(AValue: string);
begin
  CkCsr_put_Country(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCsr.GetState: string;
begin
  Result := CkToStr(CkCsr_get_State(FHandle));
end;

procedure TCsr.SetState(AValue: string);
begin
  CkCsr_put_State(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCsr.GetLocality: string;
begin
  Result := CkToStr(CkCsr_get_Locality(FHandle));
end;

procedure TCsr.SetLocality(AValue: string);
begin
  CkCsr_put_Locality(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCsr.GetCompany: string;
begin
  Result := CkToStr(CkCsr_get_Company(FHandle));
end;

procedure TCsr.SetCompany(AValue: string);
begin
  CkCsr_put_Company(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCsr.GetCompanyDivision: string;
begin
  Result := CkToStr(CkCsr_get_CompanyDivision(FHandle));
end;

procedure TCsr.SetCompanyDivision(AValue: string);
begin
  CkCsr_put_CompanyDivision(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCsr.GetEmailAddress: string;
begin
  Result := CkToStr(CkCsr_get_EmailAddress(FHandle));
end;

procedure TCsr.SetEmailAddress(AValue: string);
begin
  CkCsr_put_EmailAddress(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCsr.GetHashAlgorithm: string;
begin
  Result := CkToStr(CkCsr_get_HashAlgorithm(FHandle));
end;

procedure TCsr.SetHashAlgorithm(AValue: string);
begin
  CkCsr_put_HashAlgorithm(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCsr.GetPssPadding: Boolean;
begin
  Result := Boolean(CkCsr_get_PssPadding(FHandle));
end;

procedure TCsr.SetPssPadding(AValue: Boolean);
begin
  CkCsr_put_PssPadding(FHandle, LongBool(AValue));
end;

function TCsr.GetMgfHashAlg: string;
begin
  Result := CkToStr(CkCsr_get_MgfHashAlg(FHandle));
end;

procedure TCsr.SetMgfHashAlg(AValue: string);
begin
  CkCsr_put_MgfHashAlg(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCsr.GenCsrPem(privKey: TChilkatBase): string;
begin
  Result := CkToStr(CkCsr_GenCsrPem(FHandle, privKey.Handle));
end;

function TCsr.GenCsrBd(privKey: TChilkatBase; csrData: TChilkatBase): Boolean;
begin
  Result := Boolean(CkCsr_GenCsrBd(FHandle, privKey.Handle, csrData.Handle));
end;

function TCsr.SetSubjectField(const oid: string; const value: string; const asnType: string): Boolean;
begin
  Result := Boolean(CkCsr_SetSubjectField(FHandle, PAnsiChar(StrToCk(oid)), PAnsiChar(StrToCk(value)), PAnsiChar(StrToCk(asnType))));
end;

function TCsr.LoadCsrPem(const csrPemStr: string): Boolean;
begin
  Result := Boolean(CkCsr_LoadCsrPem(FHandle, PAnsiChar(StrToCk(csrPemStr))));
end;

function TCsr.GetSubjectField(const oid: string): string;
begin
  Result := CkToStr(CkCsr_GetSubjectField(FHandle, PAnsiChar(StrToCk(oid))));
end;

function TCsr.GetPublicKey(pubkey: TChilkatBase): Boolean;
begin
  Result := Boolean(CkCsr_GetPublicKey(FHandle, pubkey.Handle));
end;

function TCsr.VerifyCsr: Boolean;
begin
  Result := Boolean(CkCsr_VerifyCsr(FHandle));
end;

function TCsr.AddSan(const sanType: string; const sanValue: string): Boolean;
begin
  Result := Boolean(CkCsr_AddSan(FHandle, PAnsiChar(StrToCk(sanType)), PAnsiChar(StrToCk(sanValue))));
end;

function TCsr.GetSans(sans: TChilkatBase): Boolean;
begin
  Result := Boolean(CkCsr_GetSans(FHandle, sans.Handle));
end;

function TCsr.SetExtensionRequest(extensionReqXml: TChilkatBase): Boolean;
begin
  Result := Boolean(CkCsr_SetExtensionRequest(FHandle, extensionReqXml.Handle));
end;

function TCsr.GetExtensionRequest(extensionReqXml: TChilkatBase): Boolean;
begin
  Result := Boolean(CkCsr_GetExtensionRequest(FHandle, extensionReqXml.Handle));
end;

initialization
  Chilkat_GetProcedureAddress(CkCsr_Create,  'CkCsr_Create');
  Chilkat_GetProcedureAddress(CkCsr_Dispose, 'CkCsr_Dispose');
  Chilkat_GetProcedureAddress(CkCsr_get_LastErrorHtml, 'CkCsr_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkCsr_get_LastErrorText, 'CkCsr_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkCsr_get_LastErrorXml, 'CkCsr_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkCsr_get_Version, 'CkCsr_get_Version');
  Chilkat_GetProcedureAddress(CkCsr_get_DebugLogFilePath, 'CkCsr_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkCsr_put_DebugLogFilePath, 'CkCsr_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkCsr_get_VerboseLogging, 'CkCsr_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkCsr_put_VerboseLogging, 'CkCsr_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkCsr_get_LastMethodSuccess, 'CkCsr_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkCsr_put_LastMethodSuccess, 'CkCsr_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkCsr_get_CommonName, 'CkCsr_get_CommonName');
  Chilkat_GetProcedureAddress(CkCsr_put_CommonName, 'CkCsr_put_CommonName');
  Chilkat_GetProcedureAddress(CkCsr_get_Country, 'CkCsr_get_Country');
  Chilkat_GetProcedureAddress(CkCsr_put_Country, 'CkCsr_put_Country');
  Chilkat_GetProcedureAddress(CkCsr_get_State, 'CkCsr_get_State');
  Chilkat_GetProcedureAddress(CkCsr_put_State, 'CkCsr_put_State');
  Chilkat_GetProcedureAddress(CkCsr_get_Locality, 'CkCsr_get_Locality');
  Chilkat_GetProcedureAddress(CkCsr_put_Locality, 'CkCsr_put_Locality');
  Chilkat_GetProcedureAddress(CkCsr_get_Company, 'CkCsr_get_Company');
  Chilkat_GetProcedureAddress(CkCsr_put_Company, 'CkCsr_put_Company');
  Chilkat_GetProcedureAddress(CkCsr_get_CompanyDivision, 'CkCsr_get_CompanyDivision');
  Chilkat_GetProcedureAddress(CkCsr_put_CompanyDivision, 'CkCsr_put_CompanyDivision');
  Chilkat_GetProcedureAddress(CkCsr_get_EmailAddress, 'CkCsr_get_EmailAddress');
  Chilkat_GetProcedureAddress(CkCsr_put_EmailAddress, 'CkCsr_put_EmailAddress');
  Chilkat_GetProcedureAddress(CkCsr_get_HashAlgorithm, 'CkCsr_get_HashAlgorithm');
  Chilkat_GetProcedureAddress(CkCsr_put_HashAlgorithm, 'CkCsr_put_HashAlgorithm');
  Chilkat_GetProcedureAddress(CkCsr_get_PssPadding, 'CkCsr_get_PssPadding');
  Chilkat_GetProcedureAddress(CkCsr_put_PssPadding, 'CkCsr_put_PssPadding');
  Chilkat_GetProcedureAddress(CkCsr_get_MgfHashAlg, 'CkCsr_get_MgfHashAlg');
  Chilkat_GetProcedureAddress(CkCsr_put_MgfHashAlg, 'CkCsr_put_MgfHashAlg');
  Chilkat_GetProcedureAddress(CkCsr_GenCsrPem, 'CkCsr_GenCsrPem');
  Chilkat_GetProcedureAddress(CkCsr_GenCsrBd, 'CkCsr_GenCsrBd');
  Chilkat_GetProcedureAddress(CkCsr_SetSubjectField, 'CkCsr_SetSubjectField');
  Chilkat_GetProcedureAddress(CkCsr_LoadCsrPem, 'CkCsr_LoadCsrPem');
  Chilkat_GetProcedureAddress(CkCsr_GetSubjectField, 'CkCsr_GetSubjectField');
  Chilkat_GetProcedureAddress(CkCsr_GetPublicKey, 'CkCsr_GetPublicKey');
  Chilkat_GetProcedureAddress(CkCsr_VerifyCsr, 'CkCsr_VerifyCsr');
  Chilkat_GetProcedureAddress(CkCsr_AddSan, 'CkCsr_AddSan');
  Chilkat_GetProcedureAddress(CkCsr_GetSans, 'CkCsr_GetSans');
  Chilkat_GetProcedureAddress(CkCsr_SetExtensionRequest, 'CkCsr_SetExtensionRequest');
  Chilkat_GetProcedureAddress(CkCsr_GetExtensionRequest, 'CkCsr_GetExtensionRequest');

end.
