-
Notifications
You must be signed in to change notification settings - Fork 4
/
GPGContext.h
1856 lines (1702 loc) · 91.6 KB
/
GPGContext.h
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// GPGContext.h
// MacGPGME
//
// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
// Copyright (C) 2001-2006 Mac GPG Project.
//
// This code is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 2.1 of the License, or (at your option)
// any later version.
//
// This code 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 Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, visit <http://www.gnu.org/> or write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
// MA 02111-1307, USA.
//
// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGCONTEXT_H
#define GPGCONTEXT_H
#include <MacGPGME/GPGObject.h>
#include <MacGPGME/GPGEngine.h>
#include <MacGPGME/GPGSignatureNotation.h>
#ifdef __cplusplus
extern "C" {
#if 0 /* just to make Emacs auto-indent happy */
}
#endif
#endif
@class NSArray;
@class NSCalendarDate;
@class NSEnumerator;
@class NSMutableDictionary;
@class NSMutableSet;
@class GPGData;
@class GPGKey;
@class GPGOptions;
/*!
* @typedef GPGSignatureMode
* @abstract The GPGSignatureMode type is used to specify the desired type of
* a signature.
* @constant GPGSignatureModeNormal A normal signature is made, the output
* includes the plaintext and the signature.
* @constant GPGSignatureModeDetach A detached signature is made.
* @constant GPGSignatureModeClear A clear text signature is made. The
* <i>ASCII armor</i> and <i>text mode</i>
* settings of the context are ignored.
* @seealso //macgpg/occ/instm/GPGContext/signedData:signatureMode: signedData:signatureMode: (GPGContext)
*/
typedef enum {
GPGSignatureModeNormal = 0,
GPGSignatureModeDetach = 1,
GPGSignatureModeClear = 2
} GPGSignatureMode;
/*!
* @typedef GPGKeyListMode
* @abstract The key listing mode is a combination of one or multiple bit
* values.
* @constant GPGKeyListModeLocal Specifies that the local
* <i>key ring</i> should be
* searched for keys in the key
* listing operation. This is the
* default.
* @constant GPGKeyListModeExtern Specifies that an external
* source should be searched for
* keys in the key listing
* operation. The type of external
* source is dependant on the
* crypto engine used. For
* example, it can be a remote
* <i>key server</i> or LDAP
* certificate server. Currently
* only implemented for the S/MIME
* back-end and ignored for other
* back-ends.
* @constant GPGKeyListModeSignatures Specifies that signatures on
* keys shall be retrieved too.
* This is a time-consuming
* operation, and that mode should
* not be used when retrieving all
* keys, but only a key per key
* basis, like when using
* <code>@link refreshKey: refreshKey:@/link</code>
* (GPGContext).
* @constant GPGKeyListModeSignatureNotations Specifies that the signature
* notations on key signatures
* should be included in the
* listed keys. This only works if
* <code>GPGKeyListModeSignatures</code>
* is also enabled.
* @constant GPGKeyListModeValidate Specifies that the back-end
* should do key or certificate
* validation and not just get the
* validity information from an
* internal cache. This might be
* an expensive operation and is
* in general not useful.
* Currently only implemented for
* the S/MIME back-end and ignored
* for other back-ends.
* @seealso //macgpg/occ/instm/GPGContext/keyListMode keyListMode (GPGContext)
* @seealso //macgpg/occ/instm/GPGContext/setKeyListMode: setKeyListMode: (GPGContext)
*/
typedef unsigned int GPGKeyListMode;
#define GPGKeyListModeLocal 1
#define GPGKeyListModeExtern 2
#define GPGKeyListModeSignatures 4
#define GPGKeyListModeSignatureNotations 8
#define GPGKeyListModeValidate 256
/*!
* @typedef GPGCertificatesInclusion
* @abstract Certificates inclusion (S/MIME only).
* @constant GPGDefaultCertificatesInclusion Use whatever the default
* of the back-end crypto
* engine is.
* @constant GPGAllExceptRootCertificatesInclusion Include all certificates
* except the root
* certificate.
* @constant GPGAllCertificatesInclusion Include all certificates.
* @constant GPGNoCertificatesInclusion Include no certificates.
* @constant GPGOnlySenderCertificateInclusion Include the sender's
* certificate only.
* @constant n > 1 Include the first n
* certificates of the
* certificates path,
* starting from the sender's
* certificate. The
* number <i>n</i> must be
* positive.
* @seealso //macgpg/occ/instm/GPGContext/certificatesInclusion certificatesInclusion (GPGContext)
* @seealso //macgpg/occ/instm/GPGContext/setCertificatesInclusion: setCertificatesInclusion: (GPGContext)
*/
typedef enum {
GPGDefaultCertificatesInclusion = -256,
GPGAllExceptRootCertificatesInclusion = -2,
GPGAllCertificatesInclusion = -1,
GPGNoCertificatesInclusion = -0,
GPGOnlySenderCertificateInclusion = 1
}GPGCertificatesInclusion;
/*!
* @typedef GPGImportStatus
* @abstract The 'status' value of a key import is a combination of bit
* values.
* @constant GPGImportDeletedKeyMask Key has been removed from the
* <i>key ring</i>
* @constant GPGImportNewKeyMask Key is new in the <i>key ring</i>
* @constant GPGImportNewUserIDMask Some new userIDs has been imported, or
* updated
* @constant GPGImportSignatureMask Some new key signatures have been
* imported, or updated
* @constant GPGImportSubkeyMask Some new subkeys have been imported, or
* updated
* @constant GPGImportSecretKeyMask Key is a secret key, and is new in the
* secret <i>key ring</i>
* @seealso GPGKeyringChangedNotification
*/
typedef unsigned int GPGImportStatus;
#define GPGImportDeletedKeyMask 0
#define GPGImportNewKeyMask 1
#define GPGImportNewUserIDMask 2
#define GPGImportSignatureMask 4
#define GPGImportSubkeyMask 8
#define GPGImportSecretKeyMask 16
/*!
* @constant GPGKeyringChangedNotification
* @abstract Posted after a modification to a <i>key ring</i> has been done.
* @discussion Posted after a modification to a <i>key ring</i> has been done.
* For example, after an import or delete operation.
*
* Object is (currently) nil.
*
* This notification is also posted by the distributed notification
* center. object is also nil.
*
* UserInfo:<dl>
* <dt><code>@link GPGContextKey GPGContextKey@/link</code></dt>
* <dd>The <code>@link //macgpg/occ/cl/GPGContext GPGContext@/link</code>
* object in which the operation was executed. Not available in
* distributed notifications.</dd>
* <dt><code>@link GPGChangesKey GPGChangesKey@/link</code></dt>
* <dd>An <code>@link //apple_ref/occ/cl/NSDictionary NSDictionary@/link</code>
* object whose keys are <code>@link //macgpg/occ/cl/GPGKey GPGKey@/link</code>
* objects (secret and public keys) and whose values are
* <code>@link //apple_ref/occ/cl/NSDictionary NSDictionary@/link</code>
* objects containing key-value pair <code>\@"status"</code> with
* a <code>@link GPGImportStatus GPGImportStatus@/link</code> (as
* <code>@link //apple_ref/occ/cl/NSNumber NSNumber@/link</code>),
* and possibly <code>\@"error"</code> with a <code>@link //macgpg/c/tdef/GPGError GPGError@/link</code>
* (as <code>@link //apple_ref/occ/cl/NSNumber NSNumber@/link</code>).
* For distributed notifications, <code>@link //macgpg/occ/cl/GPGKey GPGKey@/link</code>
* objects are replaced by <code>@link //apple_ref/occ/cl/NSString NSString@/link</code>
* objects representing the key fingerprints.</dd></dl>
* @seealso //macgpg/occ/instm/GPGContext(GPGSynchronousOperations)/generateKeyFromDictionary:secretKey:publicKey: generateKeyFromDictionary:secretKey:publicKey: (GPGContext)
* @seealso //macgpg/occ/instm/GPGContext(GPGSynchronousOperations)/importKeyData: importKeyData: (GPGContext)
* @seealso //macgpg/occ/instm/GPGContext(GPGExtendedKeyManagement)/asyncDownloadKeys:serverOptions: asyncDownloadKeys:serverOptions: (GPGContext)
*/
GPG_EXPORT NSString * const GPGKeyringChangedNotification;
/*!
* @const GPGContextKey
* @abstract Key of a <i>userInfo</i> entry in some
* <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exceptions and some notifications.
*/
GPG_EXPORT NSString * const GPGContextKey;
/*!
* @const GPGChangesKey
* @abstract Key of a <i>userInfo</i> entry in a
* <code>@link GPGKeyringChangedNotification GPGKeyringChangedNotification@/link</code>
* local notification and in <code>@link operationResults operationResults@/link</code>
* (GPGContext).
*/
GPG_EXPORT NSString * const GPGChangesKey;
/*!
* @const GPGProgressNotification
* @abstract Name of the notification posted when progress information about
* a cryptographic operation is available, for example during key
* generation.
* @discussion For details on the progress events, see the entry for the
* PROGRESS status in the file doc/DETAILS of the GnuPG
* distribution.
*
* Currently it is used only during key generation.
*
* Notification is always posted in the main thread.
*
* UserInfo:<dl>
* <dt><code>\@"description"</code></dt>
* <dd><code>@link //apple_ref/occ/cl/NSString NSString@/link</code>
* object</dd>
* <dt><code>\@"type"</code></dt>
* <dd><code>@link //apple_ref/occ/cl/NSString NSString@/link</code>
* object containing the letter printed during key generation.</dd>
* <dt><code>\@"current"</code></dt>
* <dd>Amount done, as <code>@link //apple_ref/occ/cl/NSNumber NSNumber@/link</code>
* object.</dd>
* <dt><code>\@"total"</code></dt>
* <dd>Amount to be done, as <code>@link //apple_ref/occ/cl/NSNumber NSNumber@/link</code>
* object. 0 means that the total amount is not known.</dd></dl>
* current/total = 100/100 may be used to detect the end of operation.
* @seealso //macgpg/occ/instm/GPGContext(GPGSynchronousOperations)/generateKeyFromDictionary:secretKey:publicKey: generateKeyFromDictionary:secretKey:publicKey: (GPGContext)
*/
GPG_EXPORT NSString * const GPGProgressNotification;
/*!
* @const GPGAsynchronousOperationDidTerminateNotification
* @abstract Name of the notification posted when an asynchronous operation
* on a context has been terminated.
* @discussion For example during extended key search, or key upload. Object is
* the context whose operation has just terminated, successfully or
* not.
*
* Notification is always posted in the main thread.
*
* UserInfo:<dl>
* <dt><code>@link //macgpg/c/data/GPGErrorKey GPGErrorKey@/link</code></dt>
* <dd>A <code>@link //macgpg/c/tdef/GPGError GPGError@/link</code>
* wrapped in a <code>@link //apple_ref/occ/cl/NSNumber NSNumber@/link</code>
* object</dd>
* <dt><code>@link //macgpg/c/data/GPGAdditionalReasonKey GPGAdditionalReasonKey@/link</code></dt>
* <dd>An optional <code>@link //apple_ref/occ/cl/NSString NSString@/link</code>
* object containing an additional unlocalized error message</dd>
* </dl>
* @seealso //macgpg/occ/instm/GPGContext/operationResults operationResults (GPGContext)
*/
GPG_EXPORT NSString * const GPGAsynchronousOperationDidTerminateNotification;
GPG_EXPORT NSString * const GPGNextKeyNotification;
GPG_EXPORT NSString * const GPGNextKeyKey;
GPG_EXPORT NSString * const GPGNextTrustItemNotification;
GPG_EXPORT NSString * const GPGNextTrustItemKey;
/*!
* @class GPGContext
* @abstract Main object for all cryptographic operations in MacGPGME.
* @discussion All cryptographic operations in MacGPGME are performed within a
* context, which contains the internal state of the operation as
* well as configuration parameters. By using several contexts you
* can run several cryptographic operations in parallel, with
* different configuration.
* <h2>UserID search patterns (for OpenPGP protocol)</h2>
* For search pattern, you can give:<ul>
* <li>a key ID, in short or long form, prefixed or not by
* <code>0x</code></li>
* <li>a key fingerprint</li>
* <li>using <code>"=aString"</code>, where aString must be an
* exact match like
* <code>"=Heinrich Heine <heinrichh\@uni-duesseldorf.de>"</code></li>
* <li>using the email address part, matching exactly:
* <code>"<heinrichh\@uni-duesseldorf.de>"</code></li>
* <li>using a format like this: <code>"+Heinrich Heine duesseldorf"</code>.
* All words must match exactly (not case sensitive) but can
* appear in any order in the user ID. Words are any sequences of
* letters, digits, the underscore and all characters with bit 7
* set.</li>
* <li>or a substring matching format like that: <code>"Heine"</code>
* or <code>"*Heine"</code>. By case insensitive substring
* matching. This is the default mode but applications may want to
* explicitely indicate this by putting the asterisk in front.</li>
* </ul>
* <h2>Notations</h2>
* You can attach arbitrary notation data to a signature. This
* information is then available to the user when the signature is
* verified. Use method
* <code>@link addSignatureNotationWithName:value:flags: addSignatureNotationWithName:value:flags:@/link</code>
* to set notation data to a signature the context will create.
*/
@interface GPGContext : GPGObject <NSCopying>
{
id _passphraseDelegate; // Passphrase delegate, not retained.
int _operationMask;
NSMutableDictionary *_operationData;
id _userInfo; // Object set by user; not used by GPGContext itself.
NSMutableSet *_signerKeys;
NSArray *_engines;
}
/*!
* @method copyWithZone:
* @abstract <code>@link //apple_ref/occ/intf/NSCopying NSCopying@/link</code>
* protocol implementation.
* @discussion Copies engine configurations, as well as all context attributes
* except passphrase delegate, user info dictionary and
* signature notations.
* @param zone Memory zone.
* @result A new retained context with the same parameters.
*/
- (id) copyWithZone:(NSZone *)zone;
/*!
* @methodgroup Initializer
*/
/*!
* @method init
* @abstract Designated initializer
* @discussion Designated initializer. Creates a new context used to hold the
* configuration, status and result of cryptographic operations.
*
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception; in this case, a <code>@link //apple_ref/occ/intfm/NSObject/release release@/link</code>
* is sent to self.
*/
- (id) init;
/*!
* @methodgroup ASCII armor
*/
/*!
* @method setUsesArmor:
* @abstract Enables or disables the use of an <i>ASCII armor</i> for all
* output.
* @discussion Default value is <code>NO</code>.
* @param armor <code>YES</code> or <code>NO</code>.
*/
- (void) setUsesArmor:(BOOL)armor;
/*!
* @method usesArmor
* @abstract Returns whether context uses <i>ASCII armor</i> or not.
* @discussion Default value is <code>NO</code>.
*/
- (BOOL) usesArmor;
/*!
* @methodgroup Text mode
*/
/*!
* @method setUsesTextMode:
* @abstract Enables or disables the use of the special <i>text mode</i>.
* @discussion <i>Text mode</i> is for example used for MIME (RFC2015)
* signatures; note that the updated RFC 3156 mandates that the
* mail user agent does some preparations so that <i>text mode</i>
* is not needed anymore.
*
* This option is only relevant to the OpenPGP crypto engine, and
* ignored by all other engines.
*
* Default value is <code>NO</code>.
* @param mode <code>YES</code> or <code>NO</code>.
*/
- (void) setUsesTextMode:(BOOL)mode;
/*!
* @method usesTextMode
* @abstract Returns whether context uses <i>text mode</i> or not.
* @discussion Default value is <code>NO</code>.
*/
- (BOOL) usesTextMode;
/*!
* @methodgroup Key listing mode
*/
/*!
* @method setKeyListMode:
* @abstract Changes the default behaviour of the key listing methods.
* @discussion The value in <i>mask</i> is a bitwise-OR combination of one or
* multiple bit values like
* <code>@link GPGKeyListModeLocal GPGKeyListModeLocal@/link</code>
* and <code>@link GPGKeyListModeExtern GPGKeyListModeExtern@/link</code>.
*
* At least <code>@link GPGKeyListModeLocal GPGKeyListModeLocal@/link</code>
* or <code>@link GPGKeyListModeExtern GPGKeyListModeExtern@/link</code>
* must be specified. For future binary compatibility, you should
* get the current mode with <code>@link //macgpg/occ/instm/GPGContext/keyListMode keyListMode@/link</code>
* and modify it by setting or clearing the appropriate bits,
* and then using that calculated value in
* <code>@link setKeyListMode: setKeyListMode:@/link</code>. This
* will leave all other bits in the mode value intact (in
* particular those that are not used in the current version of the
* library).
* @param mask Bit field
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* (<code>@link //macgpg/c/econst/GPGErrorInvalidValue GPGErrorInvalidValue@/link</code>)
exception in case <i>mask</i> is not a valid mode.
*/
- (void) setKeyListMode:(GPGKeyListMode)mask;
/*!
* @method keyListMode
* @abstract Returns the current key listing mode of the context.
* @discussion Returns the current key listing mode of the context. This value
* can then be modified and used in a subsequent
* <code>@link setKeyListMode: setKeyListMode:@/link</code>
* invocation to only affect the desired bits (and leave all others
* intact).
*
* <code>@link GPGKeyListModeLocal GPGKeyListModeLocal@/link</code>
* is the default mode.
*/
- (GPGKeyListMode) keyListMode;
/*!
* @methodgroup Protocol selection
*/
/*!
* @method setProtocol:
* @abstract Sets the protocol and thus the crypto engine to be used by the
* context.
* @discussion All crypto operations will be performed by the crypto engine
* configured for that protocol.
*
* Currently, the OpenPGP and the CMS protocols are supported. A
* new context uses the OpenPGP engine by default.
*
* Setting the protocol with <code>@link setProtocol: setProtocol:@/link</code>
* does not check if the crypto engine for that protocol is
* available and installed correctly.
* @param protocol MacGPGME protocol.
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception.
*/
- (void) setProtocol:(GPGProtocol)protocol;
/*!
* @method protocol
* @abstract Returns the protocol currently used by the context.
*/
- (GPGProtocol) protocol;
/*!
* @methodgroup Passphrase delegate
*/
/*!
* @method setPassphraseDelegate:
* @abstract Allows a delegate to be used to pass a passphrase to the
* engine.
* @discussion For OpenPGP, the preferred way to handle passphrases is by using
* the <code>gpg-agent</code>, but because that beast is not ready
* for real use, you can use this passphrase thing.
*
* Not all crypto engines require this callback to retrieve the
* passphrase. It is better if the engine retrieves the passphrase
* from a trusted agent (a daemon process), rather than having each
* user to implement their own passphrase query. Some engines do
* not even support an external passphrase callback at all, in this
* case a <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception with error code <code>@link //macgpg/c/econst/GPGErrorNotSupported GPGErrorNotSupported@/link</code>
* is returned.
*
* <i>delegate</i> must respond to
* <code>@link context:passphraseForKey:again: context:passphraseForKey:again:@/link</code> (<code>@link NSObject(GPGContextDelegate) GPGContextDelegate@/link</code>
* informal protocol). <i>delegate</i> is not retained.
*
* The user can disable the use of a passphrase callback by calling
* <code>@link setPassphraseDelegate: setPassphraseDelegate:@/link</code>
* with nil as argument.
* @param delegate Object implementing
* <code>@link NSObject(GPGContextDelegate) GPGContextDelegate@/link</code>
* informal protocol
*/
- (void) setPassphraseDelegate:(id)delegate;
/*!
* @method passphraseDelegate
* @abstract Returns the delegate providing the passphrase.
* @discussion Initially nil.
*/
- (id) passphraseDelegate;
/*!
* @methodgroup Selecting signers
*/
/*!
* @method clearSignerKeys
* @abstract Removes the list of signers from the context.
* @discussion Every context starts with an empty list.
*/
- (void) clearSignerKeys;
/*!
* @method addSignerKey:
* @abstract Adds <i>key</i> to the list of signers in the context.
* @discussion <i>key</i> is retained.
* @param key Key used for sign operations (retained).
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception.
*/
- (void) addSignerKey:(GPGKey *)key;
/*!
* @method signerKeyEnumerator
* @abstract Returns an enumerator of
* <code>@link //macgpg/occ/cl/GPGKey GPGKey@/link</code> objects,
* from the list of signers.
*/
- (NSEnumerator *) signerKeyEnumerator;
/*!
* @method signerKeys
* @abstract Convenience method. Returns <code>[[self signerKeyEnumerator] allObjects]</code>.
*/
- (NSArray *) signerKeys;
/*!
* @methodgroup Including certificates (S/MIME only)
*/
/*!
* @method setCertificatesInclusion:
* @abstract Specifies how many certificates should be included in an S/MIME
* signed message.
* @discussion By default, only the sender's certificate is included. The
* possible values of <i>includedCertificatesNumber</i> are defined
* in <code>@link GPGCertificatesInclusion GPGCertificatesInclusion@/link</code>
* enum type.
*
* This option is only relevant to the CMS crypto engine, and
* ignored by all other engines.
* @param includedCertificatesNumber Number of certificates
*/
- (void) setCertificatesInclusion:(int)includedCertificatesNumber;
/*!
* @method certificatesInclusion
* @abstract Returns the number of certificates to include in an S/MIME
* message.
*/
- (int) certificatesInclusion;
/*!
* @methodgroup Operation results
*/
/*!
* @method operationResults
* @abstract Returns a dictionary containing results of last operation on
* context.
* @discussion Contents of the dictionary depends on last operation type
* (signing, decrypting, etc.), and method can be called even after
* last operation failed and raised an exception: method could
* return partial valid data. Dictionary always contains the result
* error of the last operation under key <code>@link //macgpg/c/data/GPGErrorKey GPGErrorKey@/link</code>.
*
* If last operation was an <b>encryption</b> operation, dictionary
* can contain:<dl>
* <dt><code><code>\@"keyErrors"</code></code></dt>
* <dd>Dictionary containing <code>@link //macgpg/occ/cl/GPGKey GPGKey@/link</code>
* objects as keys, and <code>@link //apple_ref/occ/cl/NSNumber NSNumber@/link</code>
* objects wrapping <code>@link //macgpg/c/tdef/GPGError GPGError@/link</code>
* as values.</dd>
* <dt><code>\@"cipher"</code></dt>
* <dd><code>@link //macgpg/occ/cl/GPGData GPGData@/link</code> object
* with encrypted data; only valid keys were used.</dd></dl>
*
* If last operation was a <b>signing</b> operation, dictionary can
* contain:<dl>
* <dt><code>\@"signedData"</code></dt>
* <dd><code>@link //macgpg/occ/cl/GPGData GPGData@/link</code>
* object with signed data; only valid secret keys were used.</dd>
* <dt><code>\@"newSignatures"</code></dt>
* <dd>Array of <code>@link //macgpg/occ/cl/GPGSignature GPGSignature@/link</code>
* objects.</dd>
* <dt><code>\@"keyErrors"</code></dt>
* <dd>Dictionary containing <code>@link //macgpg/occ/cl/GPGKey GPGKey@/link</code>
* objects as keys, and <code>@link //apple_ref/occ/cl/NSNumber NSNumber@/link</code>
* objects wrapping <code>@link //macgpg/c/tdef/GPGError GPGError@/link</code>
* as values.</dd></dl>
*
* If last operation was a <b>verification</b> operation,
* dictionary can contain:<dl>
* <dt><code>\@"signatures"</code></dt>
* <dd>An array of <code>@link //macgpg/occ/cl/GPGSignature GPGSignature@/link</code>
* object. Same result is returned by
* <code>@link //macgpg/occ/instm/GPGContext(GPGSynchronousOperations)/signatures signatures@/link</code>.</dd>
* <dt><code>\@"filename"</code></dt>
* <dd>The original file name of the plaintext message, if
* available.</dd></dl>
*
* If last operation was a <b>decryption</b> operation, dictionary
* can contain:<dl>
* <dt><code>\@"unsupportedAlgorithm"</code></dt>
* <dd>A string describing the algorithm used for encryption,
* which is not known by the engine for decryption.</dd>
* <dt><code>\@"wrongKeyUsage"</code></dt>
* <dd>A boolean result as a <code>@link //apple_ref/occ/cl/NSNumber NSNumber@/link</code>
* object indicating that the key should not have been used for
* encryption.</dd>
* <dt><code>\@"filename"</code></dt>
* <dd>The original file name of the plaintext message, if
* available.</dd>
* <dt><code>\@"keyErrors"</code></dt>
* <dd>A dictionary containing <code>@link //macgpg/occ/cl/GPGKey GPGKey@/link</code>
* objects as keys, and <code>@link //apple_ref/occ/cl/NSNumber NSNumber@/link</code>
* objects wrapping <code>@link //macgpg/c/tdef/GPGError GPGError@/link</code>
* as values. Contains all keys used for encryption.</dd></dl>
*
* If last operation was an <b>import</b> operation, dictionary can
* contain:<dl>
* <dt><code>@link GPGChangesKey GPGChangesKey@/link</code></dt>
* <dd>See <code>@link GPGKeyringChangedNotification GPGKeyringChangedNotification@/link</code>
* notification for more information about <code>@link GPGChangesKey GPGChangesKey@/link</code>.</dd>
* <dt><code>\@"consideredKeyCount"</code></dt>
* <dd>Total number of considered keys</dd>
* <dt><code>\@"keysWithoutUserIDCount"</code></dt>
* <dd>Number of keys without user ID</dd>
* <dt><code>\@"importedKeyCount"</code></dt>
* <dd>Total number of imported keys</dd>
* <dt><code>\@"importedRSAKeyCount"</code></dt>
* <dd>Number of imported RSA keys</dd>
* <dt><code>\@"unchangedKeyCount"</code></dt>
* <dd>Number of unchanged keys</dd>
* <dt><code>\@"newUserIDCount"</code></dt>
* <dd>Number of new user IDs</dd>
* <dt><code>\@"newSubkeyCount"</code></dt>
* <dd>Number of new subkeys</dd>
* <dt><code>\@"newSignatureCount"</code></dt>
* <dd>Number of new signatures</dd>
* <dt><code>\@"newRevocationCount"</code></dt>
* <dd>Number of new revocations</dd>
* <dt><code>\@"readSecretKeyCount"</code></dt>
* <dd>Total number of secret keys read</dd>
* <dt><code>\@"importedSecretKeyCount"</code></dt>
* <dd>Number of imported secret keys</dd>
* <dt><code>\@"unchangedSecretKeyCount"</code></dt>
* <dd>Number of unchanged secret keys</dd>
* <dt><code>\@"skippedNewKeyCount"</code></dt>
* <dd>Number of new keys skipped</dd>
* <dt><code>\@"notImportedKeyCount"</code></dt>
* <dd>Number of keys not imported</dd></dl>
*
* If last operation was a <b>key generation</b> operation,
* dictionary can contain:<dl>
* <dt><code>@link GPGChangesKey GPGChangesKey@/link</code></dt>
* <dd>See <code>@link GPGKeyringChangedNotification GPGKeyringChangedNotification@/link</code>
* notification for more information about <code>@link GPGChangesKey GPGChangesKey@/link</code>.</dd></dl>
*
* If last operation was a <b>key deletion</b> operation,
* dictionary can contain:<dl>
* <dt><code>\@"deletedKeyFingerprints"</code></dt>
* <dd>An array of strings representing the fingerprints of the
* deleted keys.</dd></dl>
*
* If last operation was a <b>key enumeration</b> operation,
* dictionary can contain:<dl>
* <dt><code>\@"truncated"</code></dt>
* <dd>A boolean result as a <code>@link //apple_ref/occ/cl/NSNumber NSNumber@/link</code>
* object indicating whether all matching keys were listed or
* not.</dd></dl>
*
* If last operation was a <b>remote key search</b> operation,
* dictionary can contain:<dl>
* <dt><code>\@"keys"</code></dt>
* <dd>An array of <code>@link //macgpg/occ/cl/GPGRemoteKey GPGRemoteKey@/link</code>
* objects: these are not usable keys, they contain no other
* information than key ID, algorithm, algorithm description,
* length, creation date, expiration date, user IDs, revocation;
* user IDs are also <code>@link //macgpg/occ/cl/GPGRemoteUserID GPGRemoteUserID@/link</code>
* objects that contain no other information than user ID
* description. Returned information depends on servers.</dd>
* <dt><code>\@"hostName"</code></dt>
* <dd>Contacted server's host name</dd>
* <dt><code>\@"port"</code></dt>
* <dd>Port used to contact server, if not default one</dd>
* <dt><code>\@"protocol"</code></dt>
* <dd>Protocol used to contact server (ldap, x-hkp, hkp, http,
* finger)</dd>
* <dt><code>\@"options"</code></dt>
* <dd>Options used to contact server</dd></dl>
*
* If last operation was a <b>key download</b> operation,
* dictionary can contain:<dl>
* <dt><code>\@"hostName"</code></dt>
* <dd>Contacted server's host name</dd>
* <dt><code>\@"port"</code></dt>
* <dd>Port used to contact server, if not default one</dd>
* <dt><code>\@"protocol"</code></dt>
* <dd>Protocol used to contact server (ldap, x-hkp, hkp, http,
* finger)</dd>
* <dt><code>\@"options"</code></dt>
* <dd>Options used to contact server</dd></dl>
* and additional results from the import operation.
*/
- (NSDictionary *) operationResults;
/*!
* @methodgroup Contextual information
*/
/*!
* @method setUserInfo:
* @abstract Sets the userInfo object, containing additional data the target
* may use in a callback.
* @discussion Sets the userInfo object, containing additional data the target
* may use in a callback, for example when delegate is asked for
* passphrase. <i>userInfo</i> is simply retained.
* @param userInfo Object that is retained by the context.
*/
- (void) setUserInfo:(id)userInfo;
/*!
* @method userInfo
* @abstract Returns the userInfo object.
* @discussion Returns the userInfo object, containing additional data the
* target may use in a callback, for example when delegate is asked
* for passphrase.
*/
- (id) userInfo;
/*!
* @methodgroup Signature notations
*/
/*!
* @method clearSignatureNotations
* @abstract Clears all notation data from the context.
* @discussion Subsequent signing operations from this context will not include
* any notation data.
*
* Every context starts with an empty notation data list.
*/
- (void) clearSignatureNotations;
/*!
* @method addSignatureNotationWithName:value:flags:
* @abstract Adds the human-readable notation data with <i>name</i> name and
* <i>value</i> value to the context, using the <i>flags</i> flags.
* @discussion If <i>name</i> is nil, then <i>value</i> must be a policy URL,
* as a <code>@link //apple_ref/occ/cl/NSString NSString@/link</code>;
* the notation data is forced not to be a human-readable notation
* data.
*
* If <i>name</i> is not nil, then <i>value</i> may be a <code>@link //apple_ref/occ/cl/NSString NSString@/link</code>
* object (the notation data is forced to be a human-readable
notation data). Else <i>value</i> has to be a
* <code>@link //apple_ref/occ/cl/NSData NSData@/link</code>
* object, and notation data is forced not to be a human-readable
* notation data. Note that a user notation name must contain the
* '<code>\@</code>' character and must have only printable
* characters or spaces.
*
* Subsequent signing operations will include this notation data,
* as well as any other notation data that was added since the
* creation of the context or the last <code>@link clearSignatureNotations clearSignatureNotations@/link</code>
* invocation.
*
* <strong>WARNING:</strong> Non-human-readable notation data is
* currently not supported.
*
* <strong>WARNING:</strong> Notations are silently ignored if user
* configured <code>gpg</code> with <code>force-v3-sigs</code>
* option on.
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception for any error that is reported by the crypto engine
* support routines.
* @param name Notation data name
* @param value Notation data value
* @param flags Notation data flags
*/
- (void) addSignatureNotationWithName:(NSString *)name value:(id)value flags:(GPGSignatureNotationFlags)flags;
/*!
* @method signatureNotations
* @abstract Returns the signature notations (as <code>@link //macgpg/occ/cl/GPGSignatureNotation GPGSignatureNotation@/link</code>
* objects) for this context.
*/
- (NSArray *) signatureNotations;
/*!
* @methodgroup Engines
*/
/*!
* @method engines
* @abstract Returns the engines (as <code>@link //macgpg/occ/cl/GPGEngine GPGEngine@/link</code>
* objects) used by the current context.
*/
- (NSArray *) engines;
/*!
* @method engine
* @abstract Convenience method. Returns the engine for the protocol
* currently used.
*/
- (GPGEngine *) engine;
/*!
* @method options
* @abstract Convenience method. Returns the options file of currently used
* engine.
* @discussion Will return a new instance on each invocation. If you change the
* engine or its home directory, you need to ask for a new
* <code>@link //macgpg/occ/cl/GPGOptions GPGOptions@/link</code>
* instance.
*/
- (GPGOptions *) options;
@end
/*!
* @category GPGContext(GPGAsynchronousOperations)
* @abstract Asynchronous operations (<strong>Note that asynchronous
* operations don't work right now.</strong>)
*/
@interface GPGContext(GPGAsynchronousOperations)
/*!
* @method waitOnAnyRequest:
* @abstract Waits for any finished request.
* @discussion Waits for any finished request. When <i>hang</i> is <code>YES</code>
* the method will wait, otherwise it will return immediately when
* there is no pending finished request.
*
* Returns the context of the finished request or nil if
* <i>hang</i> is <code>NO</code> and no request has finished.
* @param hang <code>NO</code> will return immediately, <code>YES</code>
* will wait.
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception which reflects the termination status of the
* operation (in case of error). The exception's userInfo
* dictionary contains the context (under <code>@link GPGContextKey GPGContextKey@/link</code>
* key) which terminated with the error. An exception without any
* context could also be raised.
*/
+ (GPGContext *) waitOnAnyRequest:(BOOL)hang;
/*!
* @method wait:
* @abstract Continues the pending operation within the context.
* @discussion Continues the pending operation within the context. In
* particular, it ensures the data exchange between MacGPGME and
* the crypto back-end and watches over the run time status of the
* back-end process.
*
* If <i>hang</i> is <code>YES</code> the method does not return
* until the operation is completed or cancelled. Otherwise the
* method will not block for a long time.
*
* Returns <code>YES</code> if there is a finished request for
* context or <code>NO</code> if <i>hang</i> is <code>NO</code> and
* no request (for context) has finished.
* @param hang <code>NO</code> will return immediately, <code>YES</code>
* will wait.
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception which reflects the termination status of the
* operation (in case of error). The exception's userInfo
* dictionary contains the context (under <code>@link GPGContextKey GPGContextKey@/link</code>
* key) which terminated with the error.
*/
- (BOOL) wait:(BOOL)hang;
/*!
* @method cancel
* @abstract Attempts to cancel a pending operation in the context.
* @discussion This only works if you use the global event loop or your own
* event loop.
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception if the cancellation failed (in this case the state of
* context is not modified).
*/
- (void) cancel;
@end
/*!
* @category GPGContext(GPGSynchronousOperations)
* @abstract Synchronous operations
*/
@interface GPGContext(GPGSynchronousOperations)
/*!
* @methodgroup Decrypt
*/
/*!
* @method decryptedData:
* @abstract Decrypts the ciphertext in the <i>inputData</i> data and returns
* the plain data.
* @discussion Returned data's filename is set automatically, when available.
* @param inputData Encrypted data.
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* exception with error code:<dl>
* <dt><code>@link //macgpg/c/econst/GPGErrorNoData GPGErrorNoData@/link</code></dt>
* <dd><i>inputData</i> does not contain any data to decrypt.</dd>
* <dt><code>@link //macgpg/c/econst/GPGErrorDecryptionFailed GPGErrorDecryptionFailed@/link</code></dt>
* <dd><i>inputData</i> is not a valid cipher text.</dd>
* <dt><code>@link //macgpg/c/econst/GPGErrorBadPassphrase GPGErrorBadPassphrase@/link</code></dt>
* <dd>The passphrase for the secret key could not be retrieved.</dd>
* <dt><code>@link //macgpg/c/econst/GPGErrorCancelled GPGErrorCancelled@/link</code></dt>
* <dd>User cancelled operation, e.g. when asked for passphrase</dd></dl>
* Other exceptions could be raised too.
*/
- (GPGData *) decryptedData:(GPGData *)inputData;
/*!
* @methodgroup Verify
*/
/*!
* @method verifySignatureData:againstData:
* @abstract Performs a signature check on the <i>detached</i> signature
* given in <i>signatureData</i> (plaintext). Returns an array of
* <code>@link //macgpg/occ/cl/GPGSignature GPGSignature@/link</code>
* objects, by invoking <code>@link //macgpg/occ/instm/GPGContext(GPGSynchronousOperations)/signatures signatures@/link</code>.
* @param signatureData Detached signature data
* @param inputData Signed data
* @exception <code>@link //macgpg/c/data/GPGException GPGException@/link</code>
* (<code>@link //macgpg/c/econst/GPGErrorNoData GPGErrorNoData@/link</code>)
* exception when <i>inputData</i> does not contain any data to
* verify. Other exceptions could be raised too.
*/
- (NSArray *) verifySignatureData:(GPGData *)signatureData againstData:(GPGData *)inputData;
/*!
* @method verifySignedData:
* @abstract Performs a signature check on <i>signedData</i>.
* @discussion This methods invokes <code>@link verifySignedData:originalData: verifySignedData:originalData:@/link</code>
* with <i>originalDataPtr</i> set to NULL.