unit Chilkat.CodeSign;

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

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

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TCodeSign wraps CkCodeSign via the C bridge layer. }
  TCodeSign = class(TChilkatBase)
  private
    FOnAbortCheck: TChilkatAbortCheckEvent;
    FOnPercentDone: TChilkatPercentDoneEvent;
    FOnProgressInfo: TChilkatProgressInfoEvent;
    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  GetUncommonOptions: string;
    procedure SetUncommonOptions(AValue: string);
    function  GetHeartbeatMs: Integer;
    procedure SetHeartbeatMs(AValue: Integer);
    procedure SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
    procedure SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
    procedure SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
  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 UncommonOptions: string read GetUncommonOptions write SetUncommonOptions;
    property HeartbeatMs: Integer read GetHeartbeatMs write SetHeartbeatMs;

    { Event callbacks.  Return True from OnAbortCheck / OnPercentDone
      to abort the running method.  Callbacks are invoked on the
      thread that called the Chilkat method.  The HeartbeatMs
      property controls the AbortCheck frequency. }
    property OnAbortCheck: TChilkatAbortCheckEvent read FOnAbortCheck write SetOnAbortCheck;
    property OnPercentDone: TChilkatPercentDoneEvent read FOnPercentDone write SetOnPercentDone;
    property OnProgressInfo: TChilkatProgressInfoEvent read FOnProgressInfo write SetOnProgressInfo;

    function  VerifySignature(const path: string; sigInfo: TChilkatBase): Boolean;
    function  RemoveSignature(const path: string): Boolean;
    function  AddSignature(const path: string; cert: TChilkatBase; options: TChilkatBase): Boolean;
    function  GetSignerCert(cert: TChilkatBase): Boolean;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkCodeSign_Create  = function(): Pointer; cdecl;
  TCkCodeSign_Dispose = procedure(handle: Pointer); cdecl;
  TCkBridgeAbortCheckCb   = function(userData: Pointer): Integer; cdecl;
  TCkBridgePercentDoneCb  = function(pctDone: Integer; userData: Pointer): Integer; cdecl;
  TCkBridgeProgressInfoCb = procedure(name: PAnsiChar; value: PAnsiChar; userData: Pointer); cdecl;
  TCkCodeSign_SetAbortCheckCallback   = procedure(handle: Pointer; cb: TCkBridgeAbortCheckCb; userData: Pointer); cdecl;
  TCkCodeSign_SetPercentDoneCallback  = procedure(handle: Pointer; cb: TCkBridgePercentDoneCb; userData: Pointer); cdecl;
  TCkCodeSign_SetProgressInfoCallback = procedure(handle: Pointer; cb: TCkBridgeProgressInfoCb; userData: Pointer); cdecl;
  TCkCodeSign_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCodeSign_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCodeSign_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCodeSign_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCodeSign_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCodeSign_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCodeSign_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkCodeSign_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkCodeSign_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkCodeSign_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkCodeSign_get_UncommonOptions = function(handle: Pointer): PAnsiChar; cdecl;
  TCkCodeSign_put_UncommonOptions = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkCodeSign_get_HeartbeatMs = function(handle: Pointer): Integer; cdecl;
  TCkCodeSign_put_HeartbeatMs = procedure(handle: Pointer; value: Integer); cdecl;
  TCkCodeSign_VerifySignature = function(handle: Pointer; path: PAnsiChar; sigInfo: Pointer): LongBool; cdecl;
  TCkCodeSign_RemoveSignature = function(handle: Pointer; path: PAnsiChar): LongBool; cdecl;
  TCkCodeSign_AddSignature = function(handle: Pointer; path: PAnsiChar; cert: Pointer; options: Pointer): LongBool; cdecl;
  TCkCodeSign_GetSignerCert = function(handle: Pointer; cert: Pointer): LongBool; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkCodeSign_Create:  TCkCodeSign_Create  = nil;
  CkCodeSign_Dispose: TCkCodeSign_Dispose = nil;
  CkCodeSign_SetAbortCheckCallback:   TCkCodeSign_SetAbortCheckCallback   = nil;
  CkCodeSign_SetPercentDoneCallback:  TCkCodeSign_SetPercentDoneCallback  = nil;
  CkCodeSign_SetProgressInfoCallback: TCkCodeSign_SetProgressInfoCallback = nil;
  CkCodeSign_get_LastErrorHtml: TCkCodeSign_get_LastErrorHtml = nil;
  CkCodeSign_get_LastErrorText: TCkCodeSign_get_LastErrorText = nil;
  CkCodeSign_get_LastErrorXml: TCkCodeSign_get_LastErrorXml = nil;
  CkCodeSign_get_Version: TCkCodeSign_get_Version = nil;
  CkCodeSign_get_DebugLogFilePath: TCkCodeSign_get_DebugLogFilePath = nil;
  CkCodeSign_put_DebugLogFilePath: TCkCodeSign_put_DebugLogFilePath = nil;
  CkCodeSign_get_VerboseLogging: TCkCodeSign_get_VerboseLogging = nil;
  CkCodeSign_put_VerboseLogging: TCkCodeSign_put_VerboseLogging = nil;
  CkCodeSign_get_LastMethodSuccess: TCkCodeSign_get_LastMethodSuccess = nil;
  CkCodeSign_put_LastMethodSuccess: TCkCodeSign_put_LastMethodSuccess = nil;
  CkCodeSign_get_UncommonOptions: TCkCodeSign_get_UncommonOptions = nil;
  CkCodeSign_put_UncommonOptions: TCkCodeSign_put_UncommonOptions = nil;
  CkCodeSign_get_HeartbeatMs: TCkCodeSign_get_HeartbeatMs = nil;
  CkCodeSign_put_HeartbeatMs: TCkCodeSign_put_HeartbeatMs = nil;
  CkCodeSign_VerifySignature: TCkCodeSign_VerifySignature = nil;
  CkCodeSign_RemoveSignature: TCkCodeSign_RemoveSignature = nil;
  CkCodeSign_AddSignature: TCkCodeSign_AddSignature = nil;
  CkCodeSign_GetSignerCert: TCkCodeSign_GetSignerCert = nil;

constructor TCodeSign.Create;
begin
  inherited Create;
  FHandle := CkCodeSign_Create();
end;

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

{ ---- Event callback thunks ---- }
{ Standalone cdecl functions registered with the C bridge.  The bridge
  passes back the userData pointer, which carries the Pascal object
  instance.  A non-zero return value aborts the running method. }

function TCodeSign_AbortCheckThunk(userData: Pointer): Integer; cdecl;
var
  obj: TCodeSign;
begin
  Result := 0;
  obj := TCodeSign(userData);
  if Assigned(obj) and Assigned(obj.FOnAbortCheck) then
    if obj.FOnAbortCheck(obj) then Result := 1;
end;

function TCodeSign_PercentDoneThunk(pctDone: Integer; userData: Pointer): Integer; cdecl;
var
  obj: TCodeSign;
begin
  Result := 0;
  obj := TCodeSign(userData);
  if Assigned(obj) and Assigned(obj.FOnPercentDone) then
    if obj.FOnPercentDone(obj, pctDone) then Result := 1;
end;

procedure TCodeSign_ProgressInfoThunk(name: PAnsiChar; value: PAnsiChar; userData: Pointer); cdecl;
var
  obj: TCodeSign;
begin
  obj := TCodeSign(userData);
  if Assigned(obj) and Assigned(obj.FOnProgressInfo) then
    obj.FOnProgressInfo(obj, CkToStr(name), CkToStr(value));
end;

procedure TCodeSign.SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
begin
  FOnAbortCheck := AValue;
  if Assigned(AValue) then
    CkCodeSign_SetAbortCheckCallback(FHandle, @TCodeSign_AbortCheckThunk, Self)
  else
    CkCodeSign_SetAbortCheckCallback(FHandle, nil, nil);
end;

procedure TCodeSign.SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
begin
  FOnPercentDone := AValue;
  if Assigned(AValue) then
    CkCodeSign_SetPercentDoneCallback(FHandle, @TCodeSign_PercentDoneThunk, Self)
  else
    CkCodeSign_SetPercentDoneCallback(FHandle, nil, nil);
end;

procedure TCodeSign.SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
begin
  FOnProgressInfo := AValue;
  if Assigned(AValue) then
    CkCodeSign_SetProgressInfoCallback(FHandle, @TCodeSign_ProgressInfoThunk, Self)
  else
    CkCodeSign_SetProgressInfoCallback(FHandle, nil, nil);
end;

function TCodeSign.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkCodeSign_get_LastErrorHtml(FHandle));
end;

function TCodeSign.GetLastErrorText: string;
begin
  Result := CkToStr(CkCodeSign_get_LastErrorText(FHandle));
end;

function TCodeSign.GetLastErrorXml: string;
begin
  Result := CkToStr(CkCodeSign_get_LastErrorXml(FHandle));
end;

function TCodeSign.GetVersion: string;
begin
  Result := CkToStr(CkCodeSign_get_Version(FHandle));
end;

function TCodeSign.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkCodeSign_get_DebugLogFilePath(FHandle));
end;

procedure TCodeSign.SetDebugLogFilePath(AValue: string);
begin
  CkCodeSign_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCodeSign.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkCodeSign_get_VerboseLogging(FHandle));
end;

procedure TCodeSign.SetVerboseLogging(AValue: Boolean);
begin
  CkCodeSign_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TCodeSign.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkCodeSign_get_LastMethodSuccess(FHandle));
end;

procedure TCodeSign.SetLastMethodSuccess(AValue: Boolean);
begin
  CkCodeSign_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TCodeSign.GetUncommonOptions: string;
begin
  Result := CkToStr(CkCodeSign_get_UncommonOptions(FHandle));
end;

procedure TCodeSign.SetUncommonOptions(AValue: string);
begin
  CkCodeSign_put_UncommonOptions(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TCodeSign.GetHeartbeatMs: Integer;
begin
  Result := CkCodeSign_get_HeartbeatMs(FHandle);
end;

procedure TCodeSign.SetHeartbeatMs(AValue: Integer);
begin
  CkCodeSign_put_HeartbeatMs(FHandle, AValue);
end;

function TCodeSign.VerifySignature(const path: string; sigInfo: TChilkatBase): Boolean;
begin
  Result := Boolean(CkCodeSign_VerifySignature(FHandle, PAnsiChar(StrToCk(path)), sigInfo.Handle));
end;

function TCodeSign.RemoveSignature(const path: string): Boolean;
begin
  Result := Boolean(CkCodeSign_RemoveSignature(FHandle, PAnsiChar(StrToCk(path))));
end;

function TCodeSign.AddSignature(const path: string; cert: TChilkatBase; options: TChilkatBase): Boolean;
begin
  Result := Boolean(CkCodeSign_AddSignature(FHandle, PAnsiChar(StrToCk(path)), cert.Handle, options.Handle));
end;

function TCodeSign.GetSignerCert(cert: TChilkatBase): Boolean;
begin
  Result := Boolean(CkCodeSign_GetSignerCert(FHandle, cert.Handle));
end;

initialization
  Chilkat_GetProcedureAddress(CkCodeSign_Create,  'CkCodeSign_Create');
  Chilkat_GetProcedureAddress(CkCodeSign_Dispose, 'CkCodeSign_Dispose');
  Chilkat_GetProcedureAddress(CkCodeSign_SetAbortCheckCallback, 'CkCodeSign_SetAbortCheckCallback');
  Chilkat_GetProcedureAddress(CkCodeSign_SetPercentDoneCallback, 'CkCodeSign_SetPercentDoneCallback');
  Chilkat_GetProcedureAddress(CkCodeSign_SetProgressInfoCallback, 'CkCodeSign_SetProgressInfoCallback');
  Chilkat_GetProcedureAddress(CkCodeSign_get_LastErrorHtml, 'CkCodeSign_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkCodeSign_get_LastErrorText, 'CkCodeSign_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkCodeSign_get_LastErrorXml, 'CkCodeSign_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkCodeSign_get_Version, 'CkCodeSign_get_Version');
  Chilkat_GetProcedureAddress(CkCodeSign_get_DebugLogFilePath, 'CkCodeSign_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkCodeSign_put_DebugLogFilePath, 'CkCodeSign_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkCodeSign_get_VerboseLogging, 'CkCodeSign_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkCodeSign_put_VerboseLogging, 'CkCodeSign_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkCodeSign_get_LastMethodSuccess, 'CkCodeSign_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkCodeSign_put_LastMethodSuccess, 'CkCodeSign_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkCodeSign_get_UncommonOptions, 'CkCodeSign_get_UncommonOptions');
  Chilkat_GetProcedureAddress(CkCodeSign_put_UncommonOptions, 'CkCodeSign_put_UncommonOptions');
  Chilkat_GetProcedureAddress(CkCodeSign_get_HeartbeatMs, 'CkCodeSign_get_HeartbeatMs');
  Chilkat_GetProcedureAddress(CkCodeSign_put_HeartbeatMs, 'CkCodeSign_put_HeartbeatMs');
  Chilkat_GetProcedureAddress(CkCodeSign_VerifySignature, 'CkCodeSign_VerifySignature');
  Chilkat_GetProcedureAddress(CkCodeSign_RemoveSignature, 'CkCodeSign_RemoveSignature');
  Chilkat_GetProcedureAddress(CkCodeSign_AddSignature, 'CkCodeSign_AddSignature');
  Chilkat_GetProcedureAddress(CkCodeSign_GetSignerCert, 'CkCodeSign_GetSignerCert');

end.
