unit Chilkat.SshKey;

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

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

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TSshKey wraps CkSshKey via the C bridge layer. }
  TSshKey = 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  GetComment: string;
    procedure SetComment(AValue: string);
    function  GetIsDsaKey: Boolean;
    function  GetIsPrivateKey: Boolean;
    function  GetIsRsaKey: Boolean;
    function  GetPassword: string;
    procedure SetPassword(AValue: string);
    function  GetKeyType: 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 Comment: string read GetComment write SetComment;
    property IsDsaKey: Boolean read GetIsDsaKey;
    property IsPrivateKey: Boolean read GetIsPrivateKey;
    property IsRsaKey: Boolean read GetIsRsaKey;
    property Password: string read GetPassword write SetPassword;
    property KeyType: string read GetKeyType;
    property UncommonOptions: string read GetUncommonOptions write SetUncommonOptions;

    function  FromOpenSshPrivateKey(const keyStr: string): Boolean;
    function  FromOpenSshPublicKey(const keyStr: string): Boolean;
    function  FromPuttyPrivateKey(const keyStr: string): Boolean;
    function  FromRfc4716PublicKey(const keyStr: string): Boolean;
    function  FromXml(const xmlKey: string): Boolean;
    function  GenFingerprint: string;
    function  GenerateDsaKey(numBits: Integer): Boolean;
    function  GenerateRsaKey(numBits: Integer; exponent: Integer): Boolean;
    function  LoadText(const filename: string): string;
    function  SaveText(const strToSave: string; const filename: string): Boolean;
    function  ToOpenSshPrivateKey(bEncrypt: Boolean): string;
    function  ToOpenSshPublicKey: string;
    function  ToPuttyPrivateKey(bEncrypt: Boolean): string;
    function  ToRfc4716PublicKey: string;
    function  ToXml: string;
    function  GenerateEd25519Key: Boolean;
    function  GenerateEcdsaKey(const curveName: string): Boolean;
    function  UsePkcs11(session: TChilkatBase; privKeyHandle: LongWord; pubKeyHandle: LongWord; const keyType: string): Boolean;
    function  UseSshCertificate(const sshCert: string): Boolean;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkSshKey_Create  = function(): Pointer; cdecl;
  TCkSshKey_Dispose = procedure(handle: Pointer); cdecl;
  TCkSshKey_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkSshKey_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkSshKey_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkSshKey_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkSshKey_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkSshKey_get_Comment = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_put_Comment = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkSshKey_get_IsDsaKey = function(handle: Pointer): LongBool; cdecl;
  TCkSshKey_get_IsPrivateKey = function(handle: Pointer): LongBool; cdecl;
  TCkSshKey_get_IsRsaKey = function(handle: Pointer): LongBool; cdecl;
  TCkSshKey_get_Password = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_put_Password = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkSshKey_get_KeyType = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_get_UncommonOptions = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_put_UncommonOptions = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkSshKey_FromOpenSshPrivateKey = function(handle: Pointer; keyStr: PAnsiChar): LongBool; cdecl;
  TCkSshKey_FromOpenSshPublicKey = function(handle: Pointer; keyStr: PAnsiChar): LongBool; cdecl;
  TCkSshKey_FromPuttyPrivateKey = function(handle: Pointer; keyStr: PAnsiChar): LongBool; cdecl;
  TCkSshKey_FromRfc4716PublicKey = function(handle: Pointer; keyStr: PAnsiChar): LongBool; cdecl;
  TCkSshKey_FromXml = function(handle: Pointer; xmlKey: PAnsiChar): LongBool; cdecl;
  TCkSshKey_GenFingerprint = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_GenerateDsaKey = function(handle: Pointer; numBits: Integer): LongBool; cdecl;
  TCkSshKey_GenerateRsaKey = function(handle: Pointer; numBits: Integer; exponent: Integer): LongBool; cdecl;
  TCkSshKey_LoadText = function(handle: Pointer; filename: PAnsiChar): PAnsiChar; cdecl;
  TCkSshKey_SaveText = function(handle: Pointer; strToSave: PAnsiChar; filename: PAnsiChar): LongBool; cdecl;
  TCkSshKey_ToOpenSshPrivateKey = function(handle: Pointer; bEncrypt: LongBool): PAnsiChar; cdecl;
  TCkSshKey_ToOpenSshPublicKey = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_ToPuttyPrivateKey = function(handle: Pointer; bEncrypt: LongBool): PAnsiChar; cdecl;
  TCkSshKey_ToRfc4716PublicKey = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_ToXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSshKey_GenerateEd25519Key = function(handle: Pointer): LongBool; cdecl;
  TCkSshKey_GenerateEcdsaKey = function(handle: Pointer; curveName: PAnsiChar): LongBool; cdecl;
  TCkSshKey_UsePkcs11 = function(handle: Pointer; session: Pointer; privKeyHandle: LongWord; pubKeyHandle: LongWord; keyType: PAnsiChar): LongBool; cdecl;
  TCkSshKey_UseSshCertificate = function(handle: Pointer; sshCert: PAnsiChar): LongBool; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkSshKey_Create:  TCkSshKey_Create  = nil;
  CkSshKey_Dispose: TCkSshKey_Dispose = nil;
  CkSshKey_get_LastErrorHtml: TCkSshKey_get_LastErrorHtml = nil;
  CkSshKey_get_LastErrorText: TCkSshKey_get_LastErrorText = nil;
  CkSshKey_get_LastErrorXml: TCkSshKey_get_LastErrorXml = nil;
  CkSshKey_get_Version: TCkSshKey_get_Version = nil;
  CkSshKey_get_DebugLogFilePath: TCkSshKey_get_DebugLogFilePath = nil;
  CkSshKey_put_DebugLogFilePath: TCkSshKey_put_DebugLogFilePath = nil;
  CkSshKey_get_VerboseLogging: TCkSshKey_get_VerboseLogging = nil;
  CkSshKey_put_VerboseLogging: TCkSshKey_put_VerboseLogging = nil;
  CkSshKey_get_LastMethodSuccess: TCkSshKey_get_LastMethodSuccess = nil;
  CkSshKey_put_LastMethodSuccess: TCkSshKey_put_LastMethodSuccess = nil;
  CkSshKey_get_Comment: TCkSshKey_get_Comment = nil;
  CkSshKey_put_Comment: TCkSshKey_put_Comment = nil;
  CkSshKey_get_IsDsaKey: TCkSshKey_get_IsDsaKey = nil;
  CkSshKey_get_IsPrivateKey: TCkSshKey_get_IsPrivateKey = nil;
  CkSshKey_get_IsRsaKey: TCkSshKey_get_IsRsaKey = nil;
  CkSshKey_get_Password: TCkSshKey_get_Password = nil;
  CkSshKey_put_Password: TCkSshKey_put_Password = nil;
  CkSshKey_get_KeyType: TCkSshKey_get_KeyType = nil;
  CkSshKey_get_UncommonOptions: TCkSshKey_get_UncommonOptions = nil;
  CkSshKey_put_UncommonOptions: TCkSshKey_put_UncommonOptions = nil;
  CkSshKey_FromOpenSshPrivateKey: TCkSshKey_FromOpenSshPrivateKey = nil;
  CkSshKey_FromOpenSshPublicKey: TCkSshKey_FromOpenSshPublicKey = nil;
  CkSshKey_FromPuttyPrivateKey: TCkSshKey_FromPuttyPrivateKey = nil;
  CkSshKey_FromRfc4716PublicKey: TCkSshKey_FromRfc4716PublicKey = nil;
  CkSshKey_FromXml: TCkSshKey_FromXml = nil;
  CkSshKey_GenFingerprint: TCkSshKey_GenFingerprint = nil;
  CkSshKey_GenerateDsaKey: TCkSshKey_GenerateDsaKey = nil;
  CkSshKey_GenerateRsaKey: TCkSshKey_GenerateRsaKey = nil;
  CkSshKey_LoadText: TCkSshKey_LoadText = nil;
  CkSshKey_SaveText: TCkSshKey_SaveText = nil;
  CkSshKey_ToOpenSshPrivateKey: TCkSshKey_ToOpenSshPrivateKey = nil;
  CkSshKey_ToOpenSshPublicKey: TCkSshKey_ToOpenSshPublicKey = nil;
  CkSshKey_ToPuttyPrivateKey: TCkSshKey_ToPuttyPrivateKey = nil;
  CkSshKey_ToRfc4716PublicKey: TCkSshKey_ToRfc4716PublicKey = nil;
  CkSshKey_ToXml: TCkSshKey_ToXml = nil;
  CkSshKey_GenerateEd25519Key: TCkSshKey_GenerateEd25519Key = nil;
  CkSshKey_GenerateEcdsaKey: TCkSshKey_GenerateEcdsaKey = nil;
  CkSshKey_UsePkcs11: TCkSshKey_UsePkcs11 = nil;
  CkSshKey_UseSshCertificate: TCkSshKey_UseSshCertificate = nil;

constructor TSshKey.Create;
begin
  inherited Create;
  FHandle := CkSshKey_Create();
end;

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

function TSshKey.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkSshKey_get_LastErrorHtml(FHandle));
end;

function TSshKey.GetLastErrorText: string;
begin
  Result := CkToStr(CkSshKey_get_LastErrorText(FHandle));
end;

function TSshKey.GetLastErrorXml: string;
begin
  Result := CkToStr(CkSshKey_get_LastErrorXml(FHandle));
end;

function TSshKey.GetVersion: string;
begin
  Result := CkToStr(CkSshKey_get_Version(FHandle));
end;

function TSshKey.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkSshKey_get_DebugLogFilePath(FHandle));
end;

procedure TSshKey.SetDebugLogFilePath(AValue: string);
begin
  CkSshKey_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TSshKey.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkSshKey_get_VerboseLogging(FHandle));
end;

procedure TSshKey.SetVerboseLogging(AValue: Boolean);
begin
  CkSshKey_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TSshKey.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkSshKey_get_LastMethodSuccess(FHandle));
end;

procedure TSshKey.SetLastMethodSuccess(AValue: Boolean);
begin
  CkSshKey_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TSshKey.GetComment: string;
begin
  Result := CkToStr(CkSshKey_get_Comment(FHandle));
end;

procedure TSshKey.SetComment(AValue: string);
begin
  CkSshKey_put_Comment(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TSshKey.GetIsDsaKey: Boolean;
begin
  Result := Boolean(CkSshKey_get_IsDsaKey(FHandle));
end;

function TSshKey.GetIsPrivateKey: Boolean;
begin
  Result := Boolean(CkSshKey_get_IsPrivateKey(FHandle));
end;

function TSshKey.GetIsRsaKey: Boolean;
begin
  Result := Boolean(CkSshKey_get_IsRsaKey(FHandle));
end;

function TSshKey.GetPassword: string;
begin
  Result := CkToStr(CkSshKey_get_Password(FHandle));
end;

procedure TSshKey.SetPassword(AValue: string);
begin
  CkSshKey_put_Password(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TSshKey.GetKeyType: string;
begin
  Result := CkToStr(CkSshKey_get_KeyType(FHandle));
end;

function TSshKey.GetUncommonOptions: string;
begin
  Result := CkToStr(CkSshKey_get_UncommonOptions(FHandle));
end;

procedure TSshKey.SetUncommonOptions(AValue: string);
begin
  CkSshKey_put_UncommonOptions(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TSshKey.FromOpenSshPrivateKey(const keyStr: string): Boolean;
begin
  Result := Boolean(CkSshKey_FromOpenSshPrivateKey(FHandle, PAnsiChar(StrToCk(keyStr))));
end;

function TSshKey.FromOpenSshPublicKey(const keyStr: string): Boolean;
begin
  Result := Boolean(CkSshKey_FromOpenSshPublicKey(FHandle, PAnsiChar(StrToCk(keyStr))));
end;

function TSshKey.FromPuttyPrivateKey(const keyStr: string): Boolean;
begin
  Result := Boolean(CkSshKey_FromPuttyPrivateKey(FHandle, PAnsiChar(StrToCk(keyStr))));
end;

function TSshKey.FromRfc4716PublicKey(const keyStr: string): Boolean;
begin
  Result := Boolean(CkSshKey_FromRfc4716PublicKey(FHandle, PAnsiChar(StrToCk(keyStr))));
end;

function TSshKey.FromXml(const xmlKey: string): Boolean;
begin
  Result := Boolean(CkSshKey_FromXml(FHandle, PAnsiChar(StrToCk(xmlKey))));
end;

function TSshKey.GenFingerprint: string;
begin
  Result := CkToStr(CkSshKey_GenFingerprint(FHandle));
end;

function TSshKey.GenerateDsaKey(numBits: Integer): Boolean;
begin
  Result := Boolean(CkSshKey_GenerateDsaKey(FHandle, numBits));
end;

function TSshKey.GenerateRsaKey(numBits: Integer; exponent: Integer): Boolean;
begin
  Result := Boolean(CkSshKey_GenerateRsaKey(FHandle, numBits, exponent));
end;

function TSshKey.LoadText(const filename: string): string;
begin
  Result := CkToStr(CkSshKey_LoadText(FHandle, PAnsiChar(StrToCk(filename))));
end;

function TSshKey.SaveText(const strToSave: string; const filename: string): Boolean;
begin
  Result := Boolean(CkSshKey_SaveText(FHandle, PAnsiChar(StrToCk(strToSave)), PAnsiChar(StrToCk(filename))));
end;

function TSshKey.ToOpenSshPrivateKey(bEncrypt: Boolean): string;
begin
  Result := CkToStr(CkSshKey_ToOpenSshPrivateKey(FHandle, LongBool(bEncrypt)));
end;

function TSshKey.ToOpenSshPublicKey: string;
begin
  Result := CkToStr(CkSshKey_ToOpenSshPublicKey(FHandle));
end;

function TSshKey.ToPuttyPrivateKey(bEncrypt: Boolean): string;
begin
  Result := CkToStr(CkSshKey_ToPuttyPrivateKey(FHandle, LongBool(bEncrypt)));
end;

function TSshKey.ToRfc4716PublicKey: string;
begin
  Result := CkToStr(CkSshKey_ToRfc4716PublicKey(FHandle));
end;

function TSshKey.ToXml: string;
begin
  Result := CkToStr(CkSshKey_ToXml(FHandle));
end;

function TSshKey.GenerateEd25519Key: Boolean;
begin
  Result := Boolean(CkSshKey_GenerateEd25519Key(FHandle));
end;

function TSshKey.GenerateEcdsaKey(const curveName: string): Boolean;
begin
  Result := Boolean(CkSshKey_GenerateEcdsaKey(FHandle, PAnsiChar(StrToCk(curveName))));
end;

function TSshKey.UsePkcs11(session: TChilkatBase; privKeyHandle: LongWord; pubKeyHandle: LongWord; const keyType: string): Boolean;
begin
  Result := Boolean(CkSshKey_UsePkcs11(FHandle, session.Handle, privKeyHandle, pubKeyHandle, PAnsiChar(StrToCk(keyType))));
end;

function TSshKey.UseSshCertificate(const sshCert: string): Boolean;
begin
  Result := Boolean(CkSshKey_UseSshCertificate(FHandle, PAnsiChar(StrToCk(sshCert))));
end;

initialization
  Chilkat_GetProcedureAddress(CkSshKey_Create,  'CkSshKey_Create');
  Chilkat_GetProcedureAddress(CkSshKey_Dispose, 'CkSshKey_Dispose');
  Chilkat_GetProcedureAddress(CkSshKey_get_LastErrorHtml, 'CkSshKey_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkSshKey_get_LastErrorText, 'CkSshKey_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkSshKey_get_LastErrorXml, 'CkSshKey_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkSshKey_get_Version, 'CkSshKey_get_Version');
  Chilkat_GetProcedureAddress(CkSshKey_get_DebugLogFilePath, 'CkSshKey_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkSshKey_put_DebugLogFilePath, 'CkSshKey_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkSshKey_get_VerboseLogging, 'CkSshKey_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkSshKey_put_VerboseLogging, 'CkSshKey_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkSshKey_get_LastMethodSuccess, 'CkSshKey_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkSshKey_put_LastMethodSuccess, 'CkSshKey_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkSshKey_get_Comment, 'CkSshKey_get_Comment');
  Chilkat_GetProcedureAddress(CkSshKey_put_Comment, 'CkSshKey_put_Comment');
  Chilkat_GetProcedureAddress(CkSshKey_get_IsDsaKey, 'CkSshKey_get_IsDsaKey');
  Chilkat_GetProcedureAddress(CkSshKey_get_IsPrivateKey, 'CkSshKey_get_IsPrivateKey');
  Chilkat_GetProcedureAddress(CkSshKey_get_IsRsaKey, 'CkSshKey_get_IsRsaKey');
  Chilkat_GetProcedureAddress(CkSshKey_get_Password, 'CkSshKey_get_Password');
  Chilkat_GetProcedureAddress(CkSshKey_put_Password, 'CkSshKey_put_Password');
  Chilkat_GetProcedureAddress(CkSshKey_get_KeyType, 'CkSshKey_get_KeyType');
  Chilkat_GetProcedureAddress(CkSshKey_get_UncommonOptions, 'CkSshKey_get_UncommonOptions');
  Chilkat_GetProcedureAddress(CkSshKey_put_UncommonOptions, 'CkSshKey_put_UncommonOptions');
  Chilkat_GetProcedureAddress(CkSshKey_FromOpenSshPrivateKey, 'CkSshKey_FromOpenSshPrivateKey');
  Chilkat_GetProcedureAddress(CkSshKey_FromOpenSshPublicKey, 'CkSshKey_FromOpenSshPublicKey');
  Chilkat_GetProcedureAddress(CkSshKey_FromPuttyPrivateKey, 'CkSshKey_FromPuttyPrivateKey');
  Chilkat_GetProcedureAddress(CkSshKey_FromRfc4716PublicKey, 'CkSshKey_FromRfc4716PublicKey');
  Chilkat_GetProcedureAddress(CkSshKey_FromXml, 'CkSshKey_FromXml');
  Chilkat_GetProcedureAddress(CkSshKey_GenFingerprint, 'CkSshKey_GenFingerprint');
  Chilkat_GetProcedureAddress(CkSshKey_GenerateDsaKey, 'CkSshKey_GenerateDsaKey');
  Chilkat_GetProcedureAddress(CkSshKey_GenerateRsaKey, 'CkSshKey_GenerateRsaKey');
  Chilkat_GetProcedureAddress(CkSshKey_LoadText, 'CkSshKey_LoadText');
  Chilkat_GetProcedureAddress(CkSshKey_SaveText, 'CkSshKey_SaveText');
  Chilkat_GetProcedureAddress(CkSshKey_ToOpenSshPrivateKey, 'CkSshKey_ToOpenSshPrivateKey');
  Chilkat_GetProcedureAddress(CkSshKey_ToOpenSshPublicKey, 'CkSshKey_ToOpenSshPublicKey');
  Chilkat_GetProcedureAddress(CkSshKey_ToPuttyPrivateKey, 'CkSshKey_ToPuttyPrivateKey');
  Chilkat_GetProcedureAddress(CkSshKey_ToRfc4716PublicKey, 'CkSshKey_ToRfc4716PublicKey');
  Chilkat_GetProcedureAddress(CkSshKey_ToXml, 'CkSshKey_ToXml');
  Chilkat_GetProcedureAddress(CkSshKey_GenerateEd25519Key, 'CkSshKey_GenerateEd25519Key');
  Chilkat_GetProcedureAddress(CkSshKey_GenerateEcdsaKey, 'CkSshKey_GenerateEcdsaKey');
  Chilkat_GetProcedureAddress(CkSshKey_UsePkcs11, 'CkSshKey_UsePkcs11');
  Chilkat_GetProcedureAddress(CkSshKey_UseSshCertificate, 'CkSshKey_UseSshCertificate');

end.
