download pgpGroups.pas
Language: Delphi
License: MPL11
Copyright: (C) 2000 Steven R. Heller } (C) 1997 Network Associates Inc. and affiliated companies. }
LOC: 231
Project Info
WinJab
Server: SourceForge
Type: cvs
...rge\w\winjab\winjab\winjab\
   .cvsignore
   About1.pas
   avatars.pas
   Bmplbox.pas
   Bookmark.dfm
   Bookmark.pas
   BrowseClass.pas
   Browser.dfm
   Browser.pas
   Callbacks.pas
   cbrowsedir.pas
   ChatWin.dfm
   ChatWin.pas
   cipher.inc
   cipher1.inc
   Common.pas
   Config.dfm
   Config.pas
   CustomPres.dfm
   CustomPres.pas
   DECConst.pas
   DECUtil.pas
   Dialog.dfm
   Dialog.pas
   FieldFrame.dfm
   FieldFrame.pas
   fListbox.dfm
   fListbox.pas
   fService.dfm
   fService.pas
   GetRoster.dfm
   GetRoster.pas
   GroupWin.dfm
   GroupWin.pas
   GrpJoin.dfm
   GrpJoin.pas
   GrpUtils.pas
   Hash.inc
   Hash.pas
   Header.dfm
   Header.pas
   Headlines.dfm
   Headlines.pas
   History.dfm
   History.pas
   imGauge.pas
   Jabber1.dfm
   Jabber1.pas
   JabUtils.pas
   JCL.INC
   jclmime.pas
   JEDI.INC
   lang-english.xml
   lang.xml
   manifest.rc
   ModGroups.pas
   NewRoster.dfm
   NewRoster.pas
   Password.dfm
   Password.pas
   pgpBase.pas
   pgpEncodePas.pas
   pgpErrors.pas
   pgpFeatures.pas
   pgpGroups.pas
   pgpKeys.pas
   pgpKeyServer.pas
   pgpmain.pas
   pgpOptionList.pas
   pgpPubTypes.pas
   pgpRandomPool.pas
   PGPsdk.pas
   pgpSDKPrefs.pas
   pgpTLS.pas
   pgpUserInterface.pas
   pgpUtilities.pas
   presence.dfm
   presence.pas
   readme.html
   Recips.dfm
   Recips.pas
   register.dfm
   register.pas
   RFC1760.inc
   RosItem.dfm
   RosItem.pas
   roster.dfm
   roster.pas
   RosterClass.pas
   RuleInfo.dfm
   RuleInfo.pas
   RuleList.dfm
   RuleList.pas
   rules.dfm
   rules.pas
   RuleUtils.pas
   Sha1.inc
   Sha1.pas
   splash.dfm
   splash.pas
   Square.inc
   Status.dfm
   Status.pas
   Stringtable.pas
   ThdSaveProfile.pas
   TOVCard.pas
   TrayIcon.pas
   vcard.dfm
   vcard.pas
   Ver.inc
   vlists.pas
   winjab-all.bpg
   WinJab.dpr
   Winjab.manifest
   WinJab.todo
   WinJab_Setup.wse
   wjUtils.pas
   xfer.dfm
   xfer.pas
   xml1.pas
   xmlutils.pas

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
{************************************************************************}
{                                                                        }
{       Borland Delphi Runtime Library                                   }
{       PGPsdk/pgpTLS interface unit                                     }
{                                                                        }
{ Portions created by PGP/NAI are                                        }
{ Copyright (C) 1997 Network Associates Inc. and affiliated companies.   }
{ All Rights Reserved.                                                   }
{                                                                        }
{ The original file is: pgpGroups.h, released 10 Mar 1999.               }
{ The original Pascal code is: pgpGroups.pas, released 10 May 2000.      }
{ The initial developer of the Pascal code is Steven R. Heller           }
{ <srheller@oz.net>                                                      }
{                                                                        }
{ Portions created by Steven R. Heller are                               }
{ Copyright (C) 2000 Steven R. Heller                                    }
{                                                                        }
{ Contributors:                                                          }
{ The ASM technique for accessing open arrays is based on the            }
{ original work of Graham Grieve in Kestral Computing's                  }
{ PGPAPI.PAS file: <http://www.kestral.com.au/devtools/pgp>              }
{                                                                        }
{ You may retrieve the latest version of this file here:                 }
{ <http://www.oz.net/~srheller/pgpsdk>                                   }
{                                                                        }
{ Please see                                                             }
{  <http://www.oz.net/~srheller/pgpsdk/index.html#groups> for            }
{  information on using this unit.                                       }
{                                                                        }
{ The contents of this file are used with permission, subject to         }
{ the Mozilla Public License Version 1.1 (the "License"); you may        }
{ not use this file except in compliance with the License. You may       }
{ obtain a copy of the License at                                        }
{ <http://www.mozilla.org/MPL/MPL-1.1.html>                              }
{                                                                        }
{ Software distributed under the License is distributed on an            }
{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or         }
{ implied. See the License for the specific language governing           }
{ rights and limitations under the License.                              }
{                                                                        }
{************************************************************************}

unit pgpGroups;

interface

uses
  pgpBase, pgpPubTypes;

const
  kPGPMaxGroupNameLength           = 63;
  kPGPMaxGroupDescriptionLength    = 63;

type
  PGPGroupName = array[0..kPGPMaxGroupNameLength] of char;
  PGPGroupDescription = array[0..kPGPMaxGroupDescriptionLength] of char;

  pPGPGroupSet = pointer;
  pPGPGroupItemIter = pointer;

  // any type will do that is distinct
  PGPGroupID = PGPUInt32;

type
  PGPGroupItemType = PGPEnumType;
const
  kPGPGroupItem_KeyID = 1;
  kPGPGroupItem_Group = 2;

{____________________________________________________________________________
  A run-time group item, used when iterating through a group.
  For client use; not necessarily the internal storage format.

  'userValue' is *not* saved to disk.
____________________________________________________________________________}
(*
typedef struct PGPGroupItem
{
  PGPGroupItemType  type;
  PGPUserValue    userValue;

  union
  {
    { type selects which substructure }
    struct  { if kGroupItem_Group }
    {
      PGPGroupID  id;
    } group;

    struct  { if kGroupItem_KeyID }
    {
      PGPPublicKeyAlgorithm  algorithm;
      PGPKeyID        keyID;
    } key;
  } u;
  
  PGPUInt32 reserved[4];

} PGPGroupItem;
*)

// substructures for TPGPGroupItem union, added by SRH
type
  TSubstructGroup = packed record
    Id: PGPGroupID;
  end;
type
  TSubstructKey = packed record
    Algorithm: PGPPublicKeyAlgorithm;
    KeyID: TPGPKeyID;
  end;
type
  pPGPGroupItem = ^TPGPGroupItem;
  TPGPGroupItem = packed record
    aType: PGPGroupItemType;
    UserValue: PGPUserValue;
    u:
      record
        { type selects which substructure }
        case Integer of
          1 : { if kGroupItem_Group }
          (Group: TSubstructGroup;);
          2 : { if kGroupItem_KeyID }
          (Key: TSubstructKey;);
        end;// case
    reserved: array[0..3] of PGPUInt32;
  end;
// oh, how I love unions

type
  TPGPGroupItemCompareProc = function(var Group1: pPGPGroupItem;
    Group2: pPGPGroupItem; UserValue: PGPUserValue): PGPInt32 cdecl;

{____________________________________________________________________________
  Info obtained via PGPGetGroupInfo.
____________________________________________________________________________}

type
  TPGPGroupInfo = record
  Id             : PGPGroupID;
  Name           : PGPGroupName;
  Description    : PGPGroupName;
  UserValue      : PGPUserValue;
end;

type
  TPGPGroupItemIterFlags = PGPFlags;
const
  // flag (1 shl 0 ) is reserved
  kPGPGroupIterFlags_Recursive      = (1 shl 1);// (1UL << 1 )
  kPGPGroupIterFlags_Keys           = (1 shl 2);// (1UL << 2 )
  kPGPGroupIterFlags_Groups         = (1 shl 3);// (1UL << 3 )

  kPGPGroupIterFlags_AllKeysRecursive = kPGPGroupIterFlags_Recursive or kPGPGroupIterFlags_Keys;
  kPGPGroupIterFlags_AllGroupsRecursive = kPGPGroupIterFlags_Recursive or kPGPGroupIterFlags_Groups;
  kPGPGroupIterFlags_AllItems = kPGPGroupIterFlags_Keys or kPGPGroupIterFlags_Groups;
  kPGPGroupIterFlags_AllRecursive = kPGPGroupIterFlags_Recursive or kPGPGroupIterFlags_AllItems;

{____________________________________________________________________________
  Manipulating pgp group sets (pPGPGroupSet)
____________________________________________________________________________}
{ create a new, empty groups collection }
var PGPNewGroupSet: function(Context: pPGPContext;
    var OutRef: pPGPGroupSet): PGPError cdecl;

{ file is *not* left open; all data is loaded into memory }
var PGPNewGroupSetFromFile: function(Context: pPGPContext;
    aFile: pPGPFileSpec;
    var OutRef: pPGPGroupSet): PGPError cdecl;

{ overwrites existing.  Don't bother unless PGPGroupSetNeedsCommit() }
var PGPSaveGroupSetToFile: function(TheSet: pPGPGroupSet; aFile: pPGPFileSpec): PGPError cdecl;

{ free all data structures; be sure to save first if you want }
var PGPFreeGroupSet: function(TheSet: pPGPGroupSet): PGPError cdecl;

{ has the group changed? }
var PGPGroupSetNeedsCommit: function(TheSet: pPGPGroupSet): PGPBoolean cdecl;

var PGPGetGroupSetContext: function(TheSet: pPGPGroupSet): pPGPContext cdecl;
    
{ export the groupset to a buffer. Use PGPFreeData to free the buffer }
var PGPExportGroupSetToBuffer: function(TheSet: pPGPGroupSet;
    var Buffer: pointer;
    var BufferSize: PGPSize): PGPError cdecl;

{ import a groupset from a buffer }
var PGPImportGroupSetFromBuffer: function(Context: pPGPContext;
    var Buffer: pointer;
    BufSize: PGPSize;
    var OutSet: pPGPGroupSet): PGPError cdecl;

{____________________________________________________________________________
  Manipulating groups
  
  Groups are always referred to by IDs which remain valid until the set
  is disposed.
____________________________________________________________________________}

{ initial parent ID is kPGPInvalidGroupID }
var PGPNewGroup: function(TheSet: pPGPGroupSet;
    const Name: PChar;
    const Description: PChar;
    var Id: PGPGroupID): PGPError cdecl;

var PGPCountGroupsInSet: function(TheSet: pPGPGroupSet;
    var NumGroups: PGPUInt32): PGPError cdecl;
       
var PGPGetIndGroupID: function(TheSet: pPGPGroupSet;
    GroupIndex: PGPUInt32;
    var Id: PGPGroupID): PGPError cdecl;

{ delete this group from the Set: }
{ All references to it are removed in all sets }
var PGPDeleteGroup: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID): PGPError cdecl;

{ delete the indexed item from the group }
{ the item may be a group or a key }
var PGPDeleteIndItemFromGroup: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    Item: PGPUInt32): PGPError cdecl;

{ same as PGPDeleteIndItemFromGroup, but accepts an item }
var PGPDeleteItemFromGroup: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    const Item: pPGPGroupItem): PGPError cdecl;

var PGPGetGroupInfo: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    var Info: TPGPGroupInfo): PGPError cdecl;
        
var PGPSetGroupName: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    const Name: PChar): PGPError cdecl;
    
var PGPSetGroupUserValue: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    UserValue: PGPUserValue): PGPError cdecl;

var PGPSetGroupDescription: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    const Name: PChar): PGPError cdecl;

{ 'item' specifies a group or a key id }
{ you must fill the item in completely }
var PGPAddItemToGroup: function(TheSet: pPGPGroupSet;
    const Item: pPGPGroupItem;
    Group: PGPGroupID): PGPError cdecl;

var PGPMergeGroupIntoDifferentSet: function(FromSet: pPGPGroupSet;
    FromId: PGPGroupID;
    ToSet: pPGPGroupSet): PGPError cdecl;

var PGPMergeGroupSets: function(FromSet: pPGPGroupSet;
    IntoSet: pPGPGroupSet): PGPError cdecl;

var PGPCopyGroupSet: function(SourceSet: pPGPGroupSet;
    var DestSet: pPGPGroupSet): PGPError cdecl;
  
{____________________________________________________________________________
  Manipulating group items
____________________________________________________________________________}

{ count how many items there are in a group }
{ totalItems includes keys and groups }
var PGPCountGroupItems: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    Recursive: PGPBoolean;
    var NumKeys: PGPUInt32;
    var TotalItems: PGPUInt32): PGPError cdecl;

{ non-recursive call; index only applies to group itself }
var PGPGetIndGroupItem: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    GroupIndex: PGPUInt32;
    var Item: TPGPGroupItem): PGPError cdecl;

{ use PGPGetIndGroupItem() if you want to get the user value }
var PGPSetIndGroupItemUserValue: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    GroupIndex: PGPUInt32;
    UserValue: PGPUserValue): PGPError cdecl;

var PGPSortGroupItems: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    CompareProc: TPGPGroupItemCompareProc;// ?? T or p?
    UserValue: PGPUserValue): PGPError cdecl;

var PGPSortGroupSet: function(TheSet: pPGPGroupSet;
    CompareProc: TPGPGroupItemCompareProc;// ?? T or p?
    UserValue: PGPUserValue): PGPError cdecl;

{____________________________________________________________________________
  PGPGroupItemIterRef--iterator through group items.
  
  Special note: this is not a full-fledged iterator.  You may *not* add
  or delete items while iterating and you may only move forward.  However,
  you may change the values of items.
____________________________________________________________________________}

var PGPNewGroupItemIter: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    Flags: TPGPGroupItemIterFlags;
    var Iter: pPGPGroupItemIter): PGPError cdecl;
        
var PGPFreeGroupItemIter: function(Iter: pPGPGroupItemIter): PGPError cdecl;

{ returns kPGPError_EndOfIteration when done }
var PGPGroupItemIterNext: function(Iter: pPGPGroupItemIter;
    var Item: TPGPGroupItem): PGPError cdecl;

{____________________________________________________________________________
  Group utilities
____________________________________________________________________________}

{____________________________________________________________________________
  Return the lowest validity of any item in the group
  keyset should contain all keys available
  It is not an error if keys can't be found; you may want to check
  the not found count.
  
  The lowest validity is kPGPValidity_Invalid and kPGPValidity_Unknown
  is never returned.
____________________________________________________________________________}
var PGPGetGroupLowestValidity: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    KeySet: pPGPKeySet;
    var LowestValidity: PGPValidity;
    var NumKeysNotFound: PGPUInt32): PGPError cdecl;

{____________________________________________________________________________
  All all the keys in the group (and its subgroups) to the keyset
____________________________________________________________________________}
var PGPNewKeySetFromGroup: function(TheSet: pPGPGroupSet;
    Id: PGPGroupID;
    MasterSet: pPGPKeySet;
    var ResultSet: pPGPKeySet;
    var NumKeysNotFound: PGPUInt32): PGPError cdecl;

{____________________________________________________________________________
  Create a simple, flattened group of unique key IDs from the source group.
  Note that sourceSet and destSet must be different.
____________________________________________________________________________}
var PGPNewFlattenedGroupFromGroup: function(SourceSet: pPGPGroupSet;
    SourceId: PGPGroupID;
    DestSet: pPGPGroupSet;
    var DestID: PGPGroupID): PGPError cdecl;

{____________________________________________________________________________
  Perform a "standard" sort on a group
____________________________________________________________________________}
var PGPSortGroupSetStd: function(TheSet: pPGPGroupSet;
    Keys: pPGPKeySet): PGPError cdecl;

{did this unit load the DLL successfully?}
//var pgpGroupsLoaded: Boolean = False;
function LoadpgpGroups: Boolean; //returns True if API successfully loaded
procedure UnLoadpgpGroups;
function pgpGroupsLoaded: Boolean; //returns if the API is loaded

implementation

uses
  Windows;

var
  PGPsdkLib: HModule;

function pgpGroupsLoaded: boolean;
begin
  result := PGPsdkLib >= 32;
end;

function LoadpgpGroups: boolean;
begin
  // groups aren't in pgp 5, try to load pgp 6 only 
  PGPsdkLib := LoadLibrary('pgp_sdk.dll');

  if pgpGroupsLoaded then
  begin
    result := True;
    @PGPNewGroupSet                := GetProcAddress(PGPsdkLib,'PGPNewGroupSet');
    @PGPNewGroupSetFromFile        := GetProcAddress(PGPsdkLib,'PGPNewGroupSetFromFile');
    @PGPSaveGroupSetToFile         := GetProcAddress(PGPsdkLib,'PGPSaveGroupSetToFile');
    @PGPFreeGroupSet               := GetProcAddress(PGPsdkLib,'PGPFreeGroupSet');
    @PGPGroupSetNeedsCommit        := GetProcAddress(PGPsdkLib,'PGPGroupSetNeedsCommit');
    @PGPGetGroupSetContext         := GetProcAddress(PGPsdkLib,'PGPGetGroupSetContext');
    @PGPExportGroupSetToBuffer     := GetProcAddress(PGPsdkLib,'PGPExportGroupSetToBuffer');
    @PGPImportGroupSetFromBuffer   := GetProcAddress(PGPsdkLib,'PGPImportGroupSetFromBuffer');
    @PGPNewGroup                   := GetProcAddress(PGPsdkLib,'PGPNewGroup');
    @PGPCountGroupsInSet           := GetProcAddress(PGPsdkLib,'PGPCountGroupsInSet');
    @PGPGetIndGroupID              := GetProcAddress(PGPsdkLib,'PGPGetIndGroupID');
    @PGPDeleteGroup                := GetProcAddress(PGPsdkLib,'PGPDeleteGroup');
    @PGPDeleteIndItemFromGroup     := GetProcAddress(PGPsdkLib,'PGPDeleteIndItemFromGroup');
    @PGPDeleteItemFromGroup        := GetProcAddress(PGPsdkLib,'PGPDeleteItemFromGroup');
    @PGPGetGroupInfo               := GetProcAddress(PGPsdkLib,'PGPGetGroupInfo');
    @PGPSetGroupName               := GetProcAddress(PGPsdkLib,'PGPSetGroupName');
    @PGPSetGroupUserValue          := GetProcAddress(PGPsdkLib,'PGPSetGroupUserValue');
    @PGPSetGroupDescription        := GetProcAddress(PGPsdkLib,'PGPSetGroupDescription');
    @PGPAddItemToGroup             := GetProcAddress(PGPsdkLib,'PGPAddItemToGroup');
    @PGPMergeGroupIntoDifferentSet := GetProcAddress(PGPsdkLib,'PGPMergeGroupIntoDifferentSet');
    @PGPMergeGroupSets             := GetProcAddress(PGPsdkLib,'PGPMergeGroupSets');
    @PGPCopyGroupSet               := GetProcAddress(PGPsdkLib,'PGPCopyGroupSet');
    @PGPCountGroupItems            := GetProcAddress(PGPsdkLib,'PGPCountGroupItems');
    @PGPGetIndGroupItem            := GetProcAddress(PGPsdkLib,'PGPGetIndGroupItem');
    @PGPSetIndGroupItemUserValue   := GetProcAddress(PGPsdkLib,'PGPSetIndGroupItemUserValue');
    @PGPSortGroupItems             := GetProcAddress(PGPsdkLib,'PGPSortGroupItems');
    @PGPSortGroupSet               := GetProcAddress(PGPsdkLib,'PGPSortGroupSet');
    @PGPNewGroupItemIter           := GetProcAddress(PGPsdkLib,'PGPNewGroupItemIter');
    @PGPFreeGroupItemIter          := GetProcAddress(PGPsdkLib,'PGPFreeGroupItemIter');
    @PGPGroupItemIterNext          := GetProcAddress(PGPsdkLib,'PGPGroupItemIterNext');
    @PGPGetGroupLowestValidity     := GetProcAddress(PGPsdkLib,'PGPGetGroupLowestValidity');
    @PGPNewKeySetFromGroup         := GetProcAddress(PGPsdkLib,'PGPNewKeySetFromGroup');
    @PGPNewFlattenedGroupFromGroup := GetProcAddress(PGPsdkLib,'PGPNewFlattenedGroupFromGroup');
    @PGPSortGroupSetStd            := GetProcAddress(PGPsdkLib,'PGPSortGroupSetStd');
  end
  else
    result := false;
end;

procedure UnLoadpgpGroups;
begin
  if pgpGroupsLoaded then
  begin
    if PGPsdkLib <> 0 then
      FreeLibrary(PGPsdkLib);
    PGPsdkLib := 0;
  end;
end;

initialization
  LoadpgpGroups;
  
finalization
  if pgpGroupsLoaded then
    UnloadpgpGroups;

end.

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us