unit Chilkat.Prng;

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

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

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TPrng wraps CkPrng via the C bridge layer. }
  TPrng = 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  GetPrngName: string;
    procedure SetPrngName(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 PrngName: string read GetPrngName write SetPrngName;

    function  AddEntropy(const entropy: string; const encoding: string): Boolean;
    function  ExportEntropy: string;
    function  FirebasePushId: string;
    function  GenRandom(numBytes: Integer; const encoding: string): string;
    function  GetEntropy(numBytes: Integer; const encoding: string): string;
    function  ImportEntropy(const entropy: string): Boolean;
    function  RandomInt(low: Integer; high: Integer): Integer;
    function  RandomPassword(length: Integer; mustIncludeDigit: Boolean; upperAndLowercase: Boolean; const mustHaveOneOf: string; const excludeChars: string): string;
    function  RandomString(length: Integer; bDigits: Boolean; bLower: Boolean; bUpper: Boolean): string;
    function  GenRandomBd(numBytes: Integer; bd: TChilkatBase): Boolean;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkPrng_Create  = function(): Pointer; cdecl;
  TCkPrng_Dispose = procedure(handle: Pointer); cdecl;
  TCkPrng_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPrng_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPrng_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPrng_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPrng_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPrng_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkPrng_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkPrng_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkPrng_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkPrng_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkPrng_get_PrngName = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPrng_put_PrngName = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkPrng_AddEntropy = function(handle: Pointer; entropy: PAnsiChar; encoding: PAnsiChar): LongBool; cdecl;
  TCkPrng_ExportEntropy = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPrng_FirebasePushId = function(handle: Pointer): PAnsiChar; cdecl;
  TCkPrng_GenRandom = function(handle: Pointer; numBytes: Integer; encoding: PAnsiChar): PAnsiChar; cdecl;
  TCkPrng_GetEntropy = function(handle: Pointer; numBytes: Integer; encoding: PAnsiChar): PAnsiChar; cdecl;
  TCkPrng_ImportEntropy = function(handle: Pointer; entropy: PAnsiChar): LongBool; cdecl;
  TCkPrng_RandomInt = function(handle: Pointer; low: Integer; high: Integer): Integer; cdecl;
  TCkPrng_RandomPassword = function(handle: Pointer; length: Integer; mustIncludeDigit: LongBool; upperAndLowercase: LongBool; mustHaveOneOf: PAnsiChar; excludeChars: PAnsiChar): PAnsiChar; cdecl;
  TCkPrng_RandomString = function(handle: Pointer; length: Integer; bDigits: LongBool; bLower: LongBool; bUpper: LongBool): PAnsiChar; cdecl;
  TCkPrng_GenRandomBd = function(handle: Pointer; numBytes: Integer; bd: Pointer): LongBool; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkPrng_Create:  TCkPrng_Create  = nil;
  CkPrng_Dispose: TCkPrng_Dispose = nil;
  CkPrng_get_LastErrorHtml: TCkPrng_get_LastErrorHtml = nil;
  CkPrng_get_LastErrorText: TCkPrng_get_LastErrorText = nil;
  CkPrng_get_LastErrorXml: TCkPrng_get_LastErrorXml = nil;
  CkPrng_get_Version: TCkPrng_get_Version = nil;
  CkPrng_get_DebugLogFilePath: TCkPrng_get_DebugLogFilePath = nil;
  CkPrng_put_DebugLogFilePath: TCkPrng_put_DebugLogFilePath = nil;
  CkPrng_get_VerboseLogging: TCkPrng_get_VerboseLogging = nil;
  CkPrng_put_VerboseLogging: TCkPrng_put_VerboseLogging = nil;
  CkPrng_get_LastMethodSuccess: TCkPrng_get_LastMethodSuccess = nil;
  CkPrng_put_LastMethodSuccess: TCkPrng_put_LastMethodSuccess = nil;
  CkPrng_get_PrngName: TCkPrng_get_PrngName = nil;
  CkPrng_put_PrngName: TCkPrng_put_PrngName = nil;
  CkPrng_AddEntropy: TCkPrng_AddEntropy = nil;
  CkPrng_ExportEntropy: TCkPrng_ExportEntropy = nil;
  CkPrng_FirebasePushId: TCkPrng_FirebasePushId = nil;
  CkPrng_GenRandom: TCkPrng_GenRandom = nil;
  CkPrng_GetEntropy: TCkPrng_GetEntropy = nil;
  CkPrng_ImportEntropy: TCkPrng_ImportEntropy = nil;
  CkPrng_RandomInt: TCkPrng_RandomInt = nil;
  CkPrng_RandomPassword: TCkPrng_RandomPassword = nil;
  CkPrng_RandomString: TCkPrng_RandomString = nil;
  CkPrng_GenRandomBd: TCkPrng_GenRandomBd = nil;

constructor TPrng.Create;
begin
  inherited Create;
  FHandle := CkPrng_Create();
end;

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

function TPrng.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkPrng_get_LastErrorHtml(FHandle));
end;

function TPrng.GetLastErrorText: string;
begin
  Result := CkToStr(CkPrng_get_LastErrorText(FHandle));
end;

function TPrng.GetLastErrorXml: string;
begin
  Result := CkToStr(CkPrng_get_LastErrorXml(FHandle));
end;

function TPrng.GetVersion: string;
begin
  Result := CkToStr(CkPrng_get_Version(FHandle));
end;

function TPrng.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkPrng_get_DebugLogFilePath(FHandle));
end;

procedure TPrng.SetDebugLogFilePath(AValue: string);
begin
  CkPrng_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TPrng.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkPrng_get_VerboseLogging(FHandle));
end;

procedure TPrng.SetVerboseLogging(AValue: Boolean);
begin
  CkPrng_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TPrng.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkPrng_get_LastMethodSuccess(FHandle));
end;

procedure TPrng.SetLastMethodSuccess(AValue: Boolean);
begin
  CkPrng_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TPrng.GetPrngName: string;
begin
  Result := CkToStr(CkPrng_get_PrngName(FHandle));
end;

procedure TPrng.SetPrngName(AValue: string);
begin
  CkPrng_put_PrngName(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TPrng.AddEntropy(const entropy: string; const encoding: string): Boolean;
begin
  Result := Boolean(CkPrng_AddEntropy(FHandle, PAnsiChar(StrToCk(entropy)), PAnsiChar(StrToCk(encoding))));
end;

function TPrng.ExportEntropy: string;
begin
  Result := CkToStr(CkPrng_ExportEntropy(FHandle));
end;

function TPrng.FirebasePushId: string;
begin
  Result := CkToStr(CkPrng_FirebasePushId(FHandle));
end;

function TPrng.GenRandom(numBytes: Integer; const encoding: string): string;
begin
  Result := CkToStr(CkPrng_GenRandom(FHandle, numBytes, PAnsiChar(StrToCk(encoding))));
end;

function TPrng.GetEntropy(numBytes: Integer; const encoding: string): string;
begin
  Result := CkToStr(CkPrng_GetEntropy(FHandle, numBytes, PAnsiChar(StrToCk(encoding))));
end;

function TPrng.ImportEntropy(const entropy: string): Boolean;
begin
  Result := Boolean(CkPrng_ImportEntropy(FHandle, PAnsiChar(StrToCk(entropy))));
end;

function TPrng.RandomInt(low: Integer; high: Integer): Integer;
begin
  Result := CkPrng_RandomInt(FHandle, low, high);
end;

function TPrng.RandomPassword(length: Integer; mustIncludeDigit: Boolean; upperAndLowercase: Boolean; const mustHaveOneOf: string; const excludeChars: string): string;
begin
  Result := CkToStr(CkPrng_RandomPassword(FHandle, length, LongBool(mustIncludeDigit), LongBool(upperAndLowercase), PAnsiChar(StrToCk(mustHaveOneOf)), PAnsiChar(StrToCk(excludeChars))));
end;

function TPrng.RandomString(length: Integer; bDigits: Boolean; bLower: Boolean; bUpper: Boolean): string;
begin
  Result := CkToStr(CkPrng_RandomString(FHandle, length, LongBool(bDigits), LongBool(bLower), LongBool(bUpper)));
end;

function TPrng.GenRandomBd(numBytes: Integer; bd: TChilkatBase): Boolean;
begin
  Result := Boolean(CkPrng_GenRandomBd(FHandle, numBytes, bd.Handle));
end;

initialization
  Chilkat_GetProcedureAddress(CkPrng_Create,  'CkPrng_Create');
  Chilkat_GetProcedureAddress(CkPrng_Dispose, 'CkPrng_Dispose');
  Chilkat_GetProcedureAddress(CkPrng_get_LastErrorHtml, 'CkPrng_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkPrng_get_LastErrorText, 'CkPrng_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkPrng_get_LastErrorXml, 'CkPrng_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkPrng_get_Version, 'CkPrng_get_Version');
  Chilkat_GetProcedureAddress(CkPrng_get_DebugLogFilePath, 'CkPrng_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkPrng_put_DebugLogFilePath, 'CkPrng_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkPrng_get_VerboseLogging, 'CkPrng_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkPrng_put_VerboseLogging, 'CkPrng_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkPrng_get_LastMethodSuccess, 'CkPrng_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkPrng_put_LastMethodSuccess, 'CkPrng_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkPrng_get_PrngName, 'CkPrng_get_PrngName');
  Chilkat_GetProcedureAddress(CkPrng_put_PrngName, 'CkPrng_put_PrngName');
  Chilkat_GetProcedureAddress(CkPrng_AddEntropy, 'CkPrng_AddEntropy');
  Chilkat_GetProcedureAddress(CkPrng_ExportEntropy, 'CkPrng_ExportEntropy');
  Chilkat_GetProcedureAddress(CkPrng_FirebasePushId, 'CkPrng_FirebasePushId');
  Chilkat_GetProcedureAddress(CkPrng_GenRandom, 'CkPrng_GenRandom');
  Chilkat_GetProcedureAddress(CkPrng_GetEntropy, 'CkPrng_GetEntropy');
  Chilkat_GetProcedureAddress(CkPrng_ImportEntropy, 'CkPrng_ImportEntropy');
  Chilkat_GetProcedureAddress(CkPrng_RandomInt, 'CkPrng_RandomInt');
  Chilkat_GetProcedureAddress(CkPrng_RandomPassword, 'CkPrng_RandomPassword');
  Chilkat_GetProcedureAddress(CkPrng_RandomString, 'CkPrng_RandomString');
  Chilkat_GetProcedureAddress(CkPrng_GenRandomBd, 'CkPrng_GenRandomBd');

end.
