Ingo Klöcker wrote:
> On Sunday 16 January 2011, Bo Berglund wrote:
>> What is gpgme? I found a very short reference on the GPG website:
>> http://www.gnupg.org/gpgme.html
>> But it talks about a "library" that applications should use to access
>> gpg. What does "library" mean?
> 
> A library is similar to what in Pascal/Delphi is called a unit.
> 
> 
>> I looked at the download, but it looks like a source tree for some
>> kind of C program. :-(
> 
> Well, it's the source tree of a C library.
> 
> 
>> I am programming in Pascal (Delphi or Lazarus with FPC).
> 
> Then you'll need a Pascal-binding for gpgme. A quick Google search 
> yielded bindings for many languages (e.g. Python, Ruby, C#/.NET), but 
> not Pascal.

There's one at the Gnu Pascal site.

http://www.gnu-pascal.de/contrib/nicola/gpgme.pas

I became acquainted with it a little while the Enigmail gang were testing the
English translation of the Adele server. If memory serves, it was written for
gpgme v0.3.4, so it will need some "fixing" to support the API changes
introduced later (0.4 ?) and carried through to modern versions.

-John

-- 
John P. Clizbe                      Inet: John (a) Enigmail DAWT net
FSF Assoc #995 / FSFE Fellow #1797  hkp://keyserver.gingerbear.net  or
     mailto:pgp-public-k...@gingerbear.net?subject=HELP

Q:"Just how do the residents of Haiku, Hawai'i hold conversations?"
A:"An odd melody / island voices on the winds / surplus of vowels"
{ Gpgme unit for accessing Gpgme library routines.

  This unit requires the Gpgme library, version 0.3.4 or 0.3.15.
  (Other versions may work, but have not been tested. 0.3.15 is
  backward compatible to 0.3.4.) This unit supports only the
  features of 0.3.4, even if a newer version of the library is
  present.

  Copyright (C) 2002-2004 Nicola Girardi <nic...@gnu.de>
                          Frank Heckenbach <fr...@pascal.gnu.de>

  This unit is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
  by the Free Software Foundation, version 2.

  This unit is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this unit; see the file COPYING. If not, write to the
  Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  02111-1307, USA. }

{$if __GPC_RELEASE__ >= 20030303}
{$define asmname external name}
{$endif}

unit Gpgme;

interface

uses GPC;

{$if __GPC_RELEASE__ < 20040917}
type
  CInteger = Integer;
  CCardinal = Cardinal;
{$endif}

type
  VoidGpgmeCtx        = restricted Void;
  VoidGpgmeData       = restricted Void;
  VoidGpgmeRecipients = restricted Void;
  VoidGpgmeKey        = restricted Void;
  VoidGpgmeTrustItem  = restricted Void;
  VoidGpgmeIterator   = restricted Void;
  GpgmeCtx            = ^VoidGpgmeCtx;
  GpgmeData           = ^VoidGpgmeData;
  GpgmeRecipients     = ^VoidGpgmeRecipients;
  GpgmeKey            = ^VoidGpgmeKey;
  GpgmeTrustItem      = ^VoidGpgmeTrustItem;
  GpgmeIterator       = ^VoidGpgmeIterator;

const
  GpgmeEOF               = -1;
  GpgmeNoError           = 0;
  GpgmeGeneralError      = 1;
  GpgmeOutOfCore         = 2;
  GpgmeInvalidValue      = 3;
  GpgmeBusy              = 4;
  GpgmeNoRequest         = 5;
  GpgmeExecError         = 6;
  GpgmeTooManyProcs      = 7;
  GpgmePipeError         = 8;
  GpgmeNoRecipients      = 9;
  GpgmeNoData            = 10;
  GpgmeConflict          = 11;
  GpgmeNotImplemented    = 12;
  GpgmeReadError         = 13;
  GpgmeWriteError        = 14;
  GpgmeInvalidType       = 15;
  GpgmeInvalidMode       = 16;
  GpgmeFileError         = 17;  { Errno is set in this case }
  GpgmeDecryptionFailed  = 18;
  GpgmeNoPassphrase      = 19;
  GpgmeCanceled          = 20;
  GpgmeInvalidKey        = 21;
  GpgmeInvalidEngine     = 22;
  GpgmeInvalidRecipients = 23;
type
  PGpgmeError = ^TGpgmeError;
  TGpgmeError = CInteger;

const
  GpgmeDataTypeNone = 0;
  GpgmeDataTypeMem  = 1;
  GpgmeDataTypeFD   = 2;
  GpgmeDataTypeFile = 3;
  GpgmeDataTypeCB   = 4;
type
  PGpgmeDataType = ^TGpgmeDataType;
  TGpgmeDataType = CInteger;

const
  GpgmeSigStatNone  = 0;
  GpgmeSigStatGood  = 1;
  GpgmeSigStatBad   = 2;
  GpgmeSigStatNoKey = 3;
  GpgmeSigStatNoSig = 4;
  GpgmeSigStatError = 5;
  GpgmeSigStatDiff  = 6;
type
  PGpgmeSigStat = ^TGpgmeSigStat;
  TGpgmeSigStat = CInteger;

const
  GpgmeSigModeNormal = 0;
  GpgmeSigModeDetach = 1;
  GpgmeSigModeClear  = 2;
type
  PGpgmeSigMode = ^TGpgmeSigMode;
  TGpgmeSigMode = CInteger;

const
  GpgmeAttrKeyID       = 1;
  GpgmeAttrFPR         = 2;
  GpgmeAttrAlgo        = 3;
  GpgmeAttrLen         = 4;
  GpgmeAttrCreated     = 5;
  GpgmeAttrExpire      = 6;
  GpgmeAttrOTrust      = 7;
  GpgmeAttrUserID      = 8;
  GpgmeAttrName        = 9;
  GpgmeAttrEmail       = 10;
  GpgmeAttrComment     = 11;
  GpgmeAttrValidity    = 12;
  GpgmeAttrLevel       = 13;
  GpgmeAttrType        = 14;
  GpgmeAttrIsSecret    = 15;
  GpgmeAttrKeyRevoked  = 16;
  GpgmeAttrKeyInvalid  = 17;
  GpgmeAttrUidRevoked  = 18;
  GpgmeAttrUidInvalid  = 19;
  GpgmeAttrKeyCaps     = 20;
  GpgmeAttrCanEncrypt  = 21;
  GpgmeAttrCanSign     = 22;
  GpgmeAttrCanCertify  = 23;
  GpgmeAttrKeyExpired  = 24;
  GpgmeAttrKeyDisabled = 25;
type
  PGpgmeAttr = ^TGpgmeAttr;
  TGpgmeAttr = CInteger;

const
  GpgmeValidityUnknown   = 0;
  GpgmeValidityUndefined = 1;
  GpgmeValidityNever     = 2;
  GpgmeValidityMarginal  = 3;
  GpgmeValidityFull      = 4;
  GpgmeValidityUltimate  = 5;
type
  PGpgmeValidity = ^TGpgmeValidity;
  TGpgmeValidity = CInteger;

const
  GpgmeProtocolOpenPGP = 0;  { Default }
  GpgmeProtocolCMS     = 1;
  GpgmeProtocolAuto    = 2;
type
  PGpgmeProtocol = ^TGpgmeProtocol;
  TGpgmeProtocol = CInteger;

const
  GpgmeKeylistModeLocal  = 1;
  GpgmeKeylistModeExtern = 2;

type
  GpgmePassphraseCB = ^function  (var Hook; Desc: CString; var HD: Pointer): CString;
  GpgmeProgressCB   = ^procedure (var Opaque; What: CString; TType, Current, Total: CInteger);

{ Context management }
function GpgmeNew (var Context: GpgmeCtx): TGpgmeError; asmname 'gpgme_new';
procedure GpgmeRelease (Context: GpgmeCtx); asmname 'gpgme_release';
function GpgmeGetNotation (Context: GpgmeCtx): CString; asmname 'gpgme_get_notation';
function GpgmeSetProtocol (Context: GpgmeCtx; Protocol: TGpgmeProtocol): TGpgmeError; asmname 'gpgme_set_protocol';
procedure GpgmeSetArmor (Context: GpgmeCtx; Yes: WordBool); asmname 'gpgme_set_armor';
function GpgmeGetArmor (Context: GpgmeCtx): WordBool; asmname 'gpgme_get_armor';
procedure GpgmeSetTextMode (Context: GpgmeCtx; Yes: WordBool); asmname 'gpgme_set_textmode';
function GpgmeGetTextMode (Context: GpgmeCtx): WordBool; asmname 'gpgme_get_textmode';
procedure GpgmeSetIncludeCerts (Context: GpgmeCtx; NrOfCerts: CInteger); asmname 'gpgme_set_include_certs';
function GpgmeGetIncludeCerts (Context: GpgmeCtx): CInteger; asmname 'gpgme_get_include_certs';
procedure GpgmeSetKeylistMode (Context: GpgmeCtx; Mode: CInteger); asmname 'gpgme_set_keylist_mode';
function GpgmeGetKeylistMode (Context: GpgmeCtx): CInteger; asmname 'gpgme_get_keylist_mode';
procedure GpgmeSetPassphraseCB (Context: GpgmeCtx; CB: GpgmePassphraseCB; var CBValue); asmname 'gpgme_set_passphrase_cb';
procedure GpgmeSetProgressCB (Context: GpgmeCtx; CB: GpgmeProgressCB; var CBValue); asmname 'gpgme_set_progress_cb';

procedure GpgmeSignersClear (Context: GpgmeCtx); asmname 'gpgme_signers_clear';
function GpgmeSignersAdd (Context: GpgmeCtx; protected Key: GpgmeKey): TGpgmeError; asmname 'gpgme_signers_add';
function GpgmeSignersEnum (protected Context: GpgmeCtx; Seq: CInteger): GpgmeKey; asmname 'gpgme_signers_enum';
function GpgmeGetSigStatus (Context: GpgmeCtx; Idx: CInteger; var Stat: TGpgmeSigStat; var Created: MedInt): CString; asmname 'gpgme_get_sig_status';
function GpgmeGetSigKey (Context: GpgmeCtx; Idx: CInteger; var Key: GpgmeKey): TGpgmeError; asmname 'gpgme_get_sig_key';
function GpgmeGetOpInfo (Context: GpgmeCtx; Reserved: CInteger): CString; asmname 'gpgme_get_op_info';

procedure GpgmeCancel (Context: GpgmeCtx); asmname 'gpgme_cancel';
function GpgmeWait (Context: GpgmeCtx; var Status: TGpgmeError; Hang: WordBool): GpgmeCtx; asmname 'gpgme_wait';

{ Functions to handle recipients }
function GpgmeRecipientsNew (var RSet: GpgmeRecipients): TGpgmeError; asmname 'gpgme_recipients_new';
procedure GpgmeRecipientsRelease (RSet: GpgmeRecipients); asmname 'gpgme_recipients_release';
function GpgmeRecipientsAddName (RSet: GpgmeRecipients; NewName: CString): TGpgmeError; asmname 'gpgme_recipients_add_name';
function GpgmeRecipientsAddNameWithValidity (RSet: GpgmeRecipients; NewName: CString; Val: TGpgmeValidity): TGpgmeError; asmname 'gpgme_recipients_add_name_with_validity';
function GpgmeRecipientsCount (const RSet: GpgmeRecipients): CCardinal; asmname 'gpgme_recipients_count';
function GpgmeRecipientsEnumOpen (const RSet: GpgmeRecipients; var Iterator: GpgmeIterator): TGpgmeError; asmname 'gpgme_recipients_enum_open';
function GpgmeRecipientsEnumRead (const RSet: GpgmeRecipients; var Iterator: GpgmeIterator): CString; asmname 'gpgme_recipients_enum_read';
function GpgmeRecipientsEnumClose (const RSet: GpgmeRecipients; var Iterator: GpgmeIterator): TGpgmeError; asmname 'gpgme_recipients_enum_close';

{ Functions to handle data objects }
function GpgmeDataNew (var Data: GpgmeData): TGpgmeError; asmname 'gpgme_data_new';
function GpgmeDataNewFromMem (var Data: GpgmeData; const Buffer; Size: SizeType; Copy: WordBool): TGpgmeError; asmname 'gpgme_data_new_from_mem';
type
  ReadCBType = function (var a1; a2: CString; a3: SizeType; var a4: SizeType): CInteger;
function GpgmeDataNewWithReadCb (var Data: GpgmeData; ReadCB: ReadCBType; ReadCBValue: Pointer): TGpgmeError; asmname 'gpgme_data_new_with_read_cb';
function GpgmeDataNewFromFile (var Data: GpgmeData; FName: CString; Copy: WordBool): TGpgmeError; asmname 'gpgme_data_new_from_file';
{ @@ The following `f' is FILE* in C, I didn't bother to wrap it up because
     it's just OK to pass a NULL value for it. }
function GpgmeDataNewFromFilePart (var Data: GpgmeData; FileName: CString; f: Pointer; Offset, Count: SizeType): TGpgmeError; asmname 'gpgme_data_new_from_filepart';
procedure GpgmeDataRelease (Data: GpgmeData); asmname 'gpgme_data_release';
function GpgmeDataReleaseAndGetMem (Data: GpgmeData; var Size: SizeType): Pointer; asmname 'gpgme_data_release_and_get_mem';
function GpgmeDataGetType (Data: GpgmeData): TGpgmeDataType; asmname 'gpgme_data_get_type';
function GpgmeDataRewind (Data: GpgmeData): TGpgmeError; asmname 'gpgme_data_rewind';
function GpgmeDataRead (Data: GpgmeData; var Buffer; Size: SizeType; var SizeRead: SizeType): TGpgmeError; asmname 'gpgme_data_read';
function GpgmeDataWrite (Data: GpgmeData; var Buffer; Size: SizeType): TGpgmeError; asmname 'gpgme_data_write';

{ Key and trust functions }
procedure GpgmeKeyRef (Key: GpgmeKey); asmname 'gpgme_key_ref';
procedure GpgmeKeyUnref (Key: GpgmeKey); asmname 'gpgme_key_unref';
procedure GpgmeKeyRelease (Key: GpgmeKey); asmname 'gpgme_key_release';
function GpgmeKeyGetAsXml (Key: GpgmeKey): CString; asmname 'gpgme_key_get_as_xml';
function GpgmeKeyGetStringAttr (Key: GpgmeKey; What: TGpgmeAttr; const Reserved; Idx: CInteger): CString; asmname 'gpgme_key_get_string_attr';
function GpgmeKeyGetULongAttr (Key: GpgmeKey; What: TGpgmeAttr; const Reserved; Idx: CInteger): MedCard; asmname 'gpgme_key_get_string_attr';
procedure GpgmeTrustItemRelease (Item: GpgmeTrustItem); asmname 'gpgme_trust_item_release';
function GpgmeTrustItemGetStringAttr (Item: GpgmeTrustItem; What: TGpgmeAttr; const Reserved; Idx: CInteger): CString; asmname 'gpgme_trust_item_get_string_attr';
function GpgmeTrustItemGetIntAttr (Item: GpgmeTrustItem; What: TGpgmeAttr; const Reserved; Idx: CInteger): CInteger; asmname 'gpgme_trust_item_get_string_attr';

{ Crypto operation functions }
function GpgmeOpEncryptStart (c: GpgmeCtx; Recp: GpgmeRecipients; Input, Output: GpgmeData): TGpgmeError; asmname 'gpgme_op_encrypt_start';
function GpgmeOpEncrypt (c: GpgmeCtx; Recp: GpgmeRecipients; Input, Output: GpgmeData): TGpgmeError; asmname 'gpgme_op_encrypt';
function GpgmeOpEncryptSignStart (c: GpgmeCtx; Recp: GpgmeRecipients; Plain, Cipher: GpgmeData): TGpgmeError; asmname 'gpgme_op_encrypt_sign_start';
function GpgmeOpEncryptSign (c: GpgmeCtx; Recp: GpgmeRecipients; Plain, Cipher: GpgmeData): TGpgmeError; asmname 'gpgme_op_encrypt_sign';
function GpgmeOpDecryptStart (c: GpgmeCtx; Ciph, Plain: GpgmeData): TGpgmeError; asmname 'gpgme_op_decrypt_start';
function GpgmeOpDecrypt (c: GpgmeCtx; Input, Output: GpgmeData): TGpgmeError; asmname 'gpgme_op_decrypt';
function GpgmeOpDecryptVerifyStart (c: GpgmeCtx; Ciph, Plain: GpgmeData): TGpgmeError; asmname 'gpgme_op_decrypt_verify_start';
function GpgmeOpDecryptVerify (c: GpgmeCtx; Input, Output: GpgmeData; var Status: TGpgmeSigStat): TGpgmeError; asmname 'gpgme_op_decrypt_verify';
function GpgmeOpSignStart (c: GpgmeCtx; Input, Output: GpgmeData; Mode: TGpgmeSigMode): TGpgmeError; asmname 'gpgme_op_sign_start';
function GpgmeOpSign (c: GpgmeCtx; Input, Output: GpgmeData; Mode: TGpgmeSigMode): TGpgmeError; asmname 'gpgme_op_sign';
function GpgmeOpVerifyStart (c: GpgmeCtx; Sig, TText: GpgmeData): TGpgmeError; asmname 'gpgme_op_verify_start';
function GpgmeOpVerify (c: GpgmeCtx; Sig, TText: GpgmeData; var Status: TGpgmeSigStat): TGpgmeError; asmname 'gpgme_op_verify';
function GpgmeOpImportStart (c: GpgmeCtx; KeyData: GpgmeData): TGpgmeError; asmname 'gpgme_op_import_start';
function GpgmeOpImport (c: GpgmeCtx; KeyData: GpgmeData): TGpgmeError; asmname 'gpgme_op_import';
function GpgmeOpExportStart (c: GpgmeCtx; Recp: GpgmeRecipients; KeyData: GpgmeData): TGpgmeError; asmname 'gpgme_op_export_start';
function GpgmeOpExport (c: GpgmeCtx; Recp: GpgmeRecipients; KeyData: GpgmeData): TGpgmeError; asmname 'gpgme_op_export';
function GpgmeOpGenkeyStart (c: GpgmeCtx; Parms: CString; PubKey, SecKey: GpgmeData): TGpgmeError; asmname 'gpgme_op_genkey_start';
function GpgmeOpGenkey (c: GpgmeCtx; Parms: CString; PubKey, SecKey: GpgmeData): TGpgmeError; asmname 'gpgme_op_genkey';
function GpgmeOpDeleteStart (c: GpgmeCtx; protected Key: GpgmeKey; AllowSecret: WordBool): TGpgmeError; asmname 'gpgme_op_delete_start';
function GpgmeOpDelete (c: GpgmeCtx; protected Key: GpgmeKey; AllowSecret: WordBool): TGpgmeError; asmname 'gpgme_op_delete';

{ Key management functions }
function GpgmeOpKeylistStart (c: GpgmeCtx; Pattern: CString; SecretOnly: WordBool): TGpgmeError; asmname 'gpgme_op_keylist_start';
function GpgmeOpKeylistNext (c: GpgmeCtx; var Key: GpgmeKey): TGpgmeError; asmname 'gpgme_op_keylist_next';
function GpgmeOpKeylistEnd (c: GpgmeCtx): TGpgmeError; asmname 'gpgme_op_keylist_end';
function GpgmeOpTrustlistStart (c: GpgmeCtx; Pattern: CString; MaxLevel: CInteger): TGpgmeError; asmname 'gpgme_op_trustlist_start';
function GpgmeOpTrustlistNext (c: GpgmeCtx; var Item: GpgmeTrustItem): TGpgmeError; asmname 'gpgme_op_trustlist_next';
function GpgmeOpTrustlistEnd (c: GpgmeCtx): TGpgmeError; asmname 'gpgme_op_trustlist_end';

{ Miscellaneous functions }
function GpgmeCheckEngine: TGpgmeError; asmname 'gpgme_check_engine';
function GpgmeGetEngineInfo: CString; asmname 'gpgme_get_engine_info';
function GpgmeStrError (Error: TGpgmeError): CString; asmname 'gpgme_strerror';

type
  PProc = ^procedure;

procedure GpgmeRegisterIdle (Proc: PProc); asmname 'gpgme_register_idle';

{ Engine support functions }
function GpgmeEngineCheckVersion (Proto: TGpgmeProtocol): TGpgmeError; asmname 'gpgme_engine_check_version';

implementation

uses Strings;

{$L gpgme}

function GpgmeCheckVersion (Requested: CString): CString; asmname 'gpgme_check_version';

const
  Required1 = '0.3.4';
  Required2 = '0.3.15';

to begin do
  begin
    var Version: CString;
    Version := GpgmeCheckVersion (nil);
    if (CString2String (Version) <> Required1) and (CString2String (Version) <> Required2) then
      begin
        WriteLn (StdErr, 'The GPC interface for Gpgme was only written for version ', Required1, ' or');
        WriteLn (StdErr, Required2, '. The installed library is version ', CString2String (Version), '.');
        WriteLn (StdErr, 'Please get a matching version of the Gpgme library or check for a version of the');
        WriteLn (StdErr, 'GPC interface matching your version of Gpgme.');
        Halt (1)
      end
  end;

end.

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Gnupg-users mailing list
Gnupg-users@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-users

Reply via email to