unit Chilkat.Jwt;

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

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

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TJwt wraps CkJwt via the C bridge layer. }
  TJwt = 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  GetAutoCompact: Boolean;
    procedure SetAutoCompact(AValue: Boolean);
    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 AutoCompact: Boolean read GetAutoCompact write SetAutoCompact;
    property UncommonOptions: string read GetUncommonOptions write SetUncommonOptions;

    function  CreateJwt(const header: string; const payload: string; const password: string): string;
    function  CreateJwtPk(const header: string; const payload: string; key: TChilkatBase): string;
    function  GenNumericDate(numSecOffset: Integer): Integer;
    function  GetHeader(const token: string): string;
    function  GetPayload(const token: string): string;
    function  IsTimeValid(const jwt: string; leeway: Integer): Boolean;
    function  VerifyJwt(const token: string; const password: string): Boolean;
    function  VerifyJwtPk(const token: string; key: TChilkatBase): Boolean;
    function  CreateJwtCert(const header: string; const payload: string; cert: TChilkatBase): string;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkJwt_Create  = function(): Pointer; cdecl;
  TCkJwt_Dispose = procedure(handle: Pointer); cdecl;
  TCkJwt_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkJwt_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkJwt_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkJwt_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkJwt_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkJwt_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkJwt_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkJwt_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkJwt_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkJwt_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkJwt_get_AutoCompact = function(handle: Pointer): LongBool; cdecl;
  TCkJwt_put_AutoCompact = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkJwt_get_UncommonOptions = function(handle: Pointer): PAnsiChar; cdecl;
  TCkJwt_put_UncommonOptions = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkJwt_CreateJwt = function(handle: Pointer; header: PAnsiChar; payload: PAnsiChar; password: PAnsiChar): PAnsiChar; cdecl;
  TCkJwt_CreateJwtPk = function(handle: Pointer; header: PAnsiChar; payload: PAnsiChar; key: Pointer): PAnsiChar; cdecl;
  TCkJwt_GenNumericDate = function(handle: Pointer; numSecOffset: Integer): Integer; cdecl;
  TCkJwt_GetHeader = function(handle: Pointer; token: PAnsiChar): PAnsiChar; cdecl;
  TCkJwt_GetPayload = function(handle: Pointer; token: PAnsiChar): PAnsiChar; cdecl;
  TCkJwt_IsTimeValid = function(handle: Pointer; jwt: PAnsiChar; leeway: Integer): LongBool; cdecl;
  TCkJwt_VerifyJwt = function(handle: Pointer; token: PAnsiChar; password: PAnsiChar): LongBool; cdecl;
  TCkJwt_VerifyJwtPk = function(handle: Pointer; token: PAnsiChar; key: Pointer): LongBool; cdecl;
  TCkJwt_CreateJwtCert = function(handle: Pointer; header: PAnsiChar; payload: PAnsiChar; cert: Pointer): PAnsiChar; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkJwt_Create:  TCkJwt_Create  = nil;
  CkJwt_Dispose: TCkJwt_Dispose = nil;
  CkJwt_get_LastErrorHtml: TCkJwt_get_LastErrorHtml = nil;
  CkJwt_get_LastErrorText: TCkJwt_get_LastErrorText = nil;
  CkJwt_get_LastErrorXml: TCkJwt_get_LastErrorXml = nil;
  CkJwt_get_Version: TCkJwt_get_Version = nil;
  CkJwt_get_DebugLogFilePath: TCkJwt_get_DebugLogFilePath = nil;
  CkJwt_put_DebugLogFilePath: TCkJwt_put_DebugLogFilePath = nil;
  CkJwt_get_VerboseLogging: TCkJwt_get_VerboseLogging = nil;
  CkJwt_put_VerboseLogging: TCkJwt_put_VerboseLogging = nil;
  CkJwt_get_LastMethodSuccess: TCkJwt_get_LastMethodSuccess = nil;
  CkJwt_put_LastMethodSuccess: TCkJwt_put_LastMethodSuccess = nil;
  CkJwt_get_AutoCompact: TCkJwt_get_AutoCompact = nil;
  CkJwt_put_AutoCompact: TCkJwt_put_AutoCompact = nil;
  CkJwt_get_UncommonOptions: TCkJwt_get_UncommonOptions = nil;
  CkJwt_put_UncommonOptions: TCkJwt_put_UncommonOptions = nil;
  CkJwt_CreateJwt: TCkJwt_CreateJwt = nil;
  CkJwt_CreateJwtPk: TCkJwt_CreateJwtPk = nil;
  CkJwt_GenNumericDate: TCkJwt_GenNumericDate = nil;
  CkJwt_GetHeader: TCkJwt_GetHeader = nil;
  CkJwt_GetPayload: TCkJwt_GetPayload = nil;
  CkJwt_IsTimeValid: TCkJwt_IsTimeValid = nil;
  CkJwt_VerifyJwt: TCkJwt_VerifyJwt = nil;
  CkJwt_VerifyJwtPk: TCkJwt_VerifyJwtPk = nil;
  CkJwt_CreateJwtCert: TCkJwt_CreateJwtCert = nil;

constructor TJwt.Create;
begin
  inherited Create;
  FHandle := CkJwt_Create();
end;

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

function TJwt.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkJwt_get_LastErrorHtml(FHandle));
end;

function TJwt.GetLastErrorText: string;
begin
  Result := CkToStr(CkJwt_get_LastErrorText(FHandle));
end;

function TJwt.GetLastErrorXml: string;
begin
  Result := CkToStr(CkJwt_get_LastErrorXml(FHandle));
end;

function TJwt.GetVersion: string;
begin
  Result := CkToStr(CkJwt_get_Version(FHandle));
end;

function TJwt.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkJwt_get_DebugLogFilePath(FHandle));
end;

procedure TJwt.SetDebugLogFilePath(AValue: string);
begin
  CkJwt_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TJwt.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkJwt_get_VerboseLogging(FHandle));
end;

procedure TJwt.SetVerboseLogging(AValue: Boolean);
begin
  CkJwt_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TJwt.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkJwt_get_LastMethodSuccess(FHandle));
end;

procedure TJwt.SetLastMethodSuccess(AValue: Boolean);
begin
  CkJwt_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TJwt.GetAutoCompact: Boolean;
begin
  Result := Boolean(CkJwt_get_AutoCompact(FHandle));
end;

procedure TJwt.SetAutoCompact(AValue: Boolean);
begin
  CkJwt_put_AutoCompact(FHandle, LongBool(AValue));
end;

function TJwt.GetUncommonOptions: string;
begin
  Result := CkToStr(CkJwt_get_UncommonOptions(FHandle));
end;

procedure TJwt.SetUncommonOptions(AValue: string);
begin
  CkJwt_put_UncommonOptions(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TJwt.CreateJwt(const header: string; const payload: string; const password: string): string;
begin
  Result := CkToStr(CkJwt_CreateJwt(FHandle, PAnsiChar(StrToCk(header)), PAnsiChar(StrToCk(payload)), PAnsiChar(StrToCk(password))));
end;

function TJwt.CreateJwtPk(const header: string; const payload: string; key: TChilkatBase): string;
begin
  Result := CkToStr(CkJwt_CreateJwtPk(FHandle, PAnsiChar(StrToCk(header)), PAnsiChar(StrToCk(payload)), key.Handle));
end;

function TJwt.GenNumericDate(numSecOffset: Integer): Integer;
begin
  Result := CkJwt_GenNumericDate(FHandle, numSecOffset);
end;

function TJwt.GetHeader(const token: string): string;
begin
  Result := CkToStr(CkJwt_GetHeader(FHandle, PAnsiChar(StrToCk(token))));
end;

function TJwt.GetPayload(const token: string): string;
begin
  Result := CkToStr(CkJwt_GetPayload(FHandle, PAnsiChar(StrToCk(token))));
end;

function TJwt.IsTimeValid(const jwt: string; leeway: Integer): Boolean;
begin
  Result := Boolean(CkJwt_IsTimeValid(FHandle, PAnsiChar(StrToCk(jwt)), leeway));
end;

function TJwt.VerifyJwt(const token: string; const password: string): Boolean;
begin
  Result := Boolean(CkJwt_VerifyJwt(FHandle, PAnsiChar(StrToCk(token)), PAnsiChar(StrToCk(password))));
end;

function TJwt.VerifyJwtPk(const token: string; key: TChilkatBase): Boolean;
begin
  Result := Boolean(CkJwt_VerifyJwtPk(FHandle, PAnsiChar(StrToCk(token)), key.Handle));
end;

function TJwt.CreateJwtCert(const header: string; const payload: string; cert: TChilkatBase): string;
begin
  Result := CkToStr(CkJwt_CreateJwtCert(FHandle, PAnsiChar(StrToCk(header)), PAnsiChar(StrToCk(payload)), cert.Handle));
end;

initialization
  Chilkat_GetProcedureAddress(CkJwt_Create,  'CkJwt_Create');
  Chilkat_GetProcedureAddress(CkJwt_Dispose, 'CkJwt_Dispose');
  Chilkat_GetProcedureAddress(CkJwt_get_LastErrorHtml, 'CkJwt_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkJwt_get_LastErrorText, 'CkJwt_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkJwt_get_LastErrorXml, 'CkJwt_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkJwt_get_Version, 'CkJwt_get_Version');
  Chilkat_GetProcedureAddress(CkJwt_get_DebugLogFilePath, 'CkJwt_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkJwt_put_DebugLogFilePath, 'CkJwt_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkJwt_get_VerboseLogging, 'CkJwt_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkJwt_put_VerboseLogging, 'CkJwt_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkJwt_get_LastMethodSuccess, 'CkJwt_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkJwt_put_LastMethodSuccess, 'CkJwt_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkJwt_get_AutoCompact, 'CkJwt_get_AutoCompact');
  Chilkat_GetProcedureAddress(CkJwt_put_AutoCompact, 'CkJwt_put_AutoCompact');
  Chilkat_GetProcedureAddress(CkJwt_get_UncommonOptions, 'CkJwt_get_UncommonOptions');
  Chilkat_GetProcedureAddress(CkJwt_put_UncommonOptions, 'CkJwt_put_UncommonOptions');
  Chilkat_GetProcedureAddress(CkJwt_CreateJwt, 'CkJwt_CreateJwt');
  Chilkat_GetProcedureAddress(CkJwt_CreateJwtPk, 'CkJwt_CreateJwtPk');
  Chilkat_GetProcedureAddress(CkJwt_GenNumericDate, 'CkJwt_GenNumericDate');
  Chilkat_GetProcedureAddress(CkJwt_GetHeader, 'CkJwt_GetHeader');
  Chilkat_GetProcedureAddress(CkJwt_GetPayload, 'CkJwt_GetPayload');
  Chilkat_GetProcedureAddress(CkJwt_IsTimeValid, 'CkJwt_IsTimeValid');
  Chilkat_GetProcedureAddress(CkJwt_VerifyJwt, 'CkJwt_VerifyJwt');
  Chilkat_GetProcedureAddress(CkJwt_VerifyJwtPk, 'CkJwt_VerifyJwtPk');
  Chilkat_GetProcedureAddress(CkJwt_CreateJwtCert, 'CkJwt_CreateJwtCert');

end.
