Update of /cvsroot/macgpg/GPGME
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14755
Modified Files:
GPGContext.h GPGContext.m GPGData.h GPGData.m GPGDefines.h
GPGEngine.h GPGEngine.m GPGExceptions.h GPGExceptions.m
GPGInternals.h GPGKey.h GPGKey.m GPGME.h GPGObject.h
GPGObject.m GPGPrettyInfo.h GPGPrettyInfo.m GPGSignature.h
GPGSignature.m GPGTrustItem.h GPGTrustItem.m IntroGPGME.html
LocalizableStrings.h README
Log Message:
Applied changes in GPGME_0_4 branch to the trunk
Index: GPGContext.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGContext.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- GPGContext.h 27 Sep 2003 14:27:24 -0000 1.11
+++ GPGContext.h 23 Jan 2005 13:20:01 -0000 1.12
@@ -2,25 +2,27 @@
// GPGContext.h
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGCONTEXT_H
@@ -28,7 +30,6 @@
#include <GPGME/GPGObject.h>
#include <GPGME/GPGEngine.h>
-#include <GPGME/GPGSignature.h>
#ifdef __cplusplus
extern "C" {
@@ -42,18 +43,20 @@
@class NSCalendarDate;
@class NSEnumerator;
@class NSMutableDictionary;
+@class NSMutableSet;
@class GPGData;
@class GPGKey;
-@... GPGRecipients;
/*"
- * The #GPGSignatureMode type is used to specify the desired type of a signature.
- * The following modes are available:
- * _{GPGSignatureModeNormal A normal signature is made, the output includes the plaintext and the signature.}
+ * The #GPGSignatureMode type is used to specify the desired type of a
+ * signature. The following modes are available:
+ * _{GPGSignatureModeNormal A normal signature is made, the output includes
+ * the plaintext and the signature.}
* _{GPGSignatureModeDetach A detached signature is made.}
- * _{GPGSignatureModeClear A clear text signature is made.
- * The %{ASCII armor} and %{text mode} settings of the context are ignored.}
+ * _{GPGSignatureModeClear A clear text signature is made. The %ASCII %armor
+ * and %{text mode} settings of the context are
+ * ignored.}
"*/
typedef enum {
GPGSignatureModeNormal = 0,
@@ -63,33 +66,50 @@
/*"
- * The key listing mode is a combination of one or multiple of the following bit values:
- * _{GPGKeyListModeLocal Specifies that the local %{key ring} should be searched
- * for keys in the key listing operation.
+ * The key listing mode is a combination of one or multiple of the following
+ * bit values:
+ * _{GPGKeyListModeLocal Specifies that the local %{key-ring} should be
+ * searched for keys in the key listing operation.
* This is the default.}
- * _{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 %{key server} or LDAP
- * certificate server.}
- * _{GPGKeyListModeSignatures .}
+ * _{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 %{key server} or LDAP certificate
+ * server.}
+ * _{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 #{-refreshKey:}.
+ * _{GPGKeyListModeValidate Specifies that the backend 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 backend and ignored for other
+ * backends.}
"*/
-typedef enum {
- GPGKeyListModeLocal = 1 << 0,
- GPGKeyListModeExtern = 1 << 1,
- GPGKeyListModeSignatures = 1 << 2
-}GPGKeyListMode;
+typedef unsigned int GPGKeyListMode;
+
+#define GPGKeyListModeLocal 1
+#define GPGKeyListModeExtern 2
+#define GPGKeyListModeSignatures 4
+#define GPGKeyListModeValidate 256
/*"
* Certificates inclusion (S/MIME only):
- * _{GPGAllExceptRootCertificatesInclusion Include all certificates except the root certificate.}
+ * _{GPGAllExceptRootCertificatesInclusion Include all certificates except
+ * the root certificate.}
* _{GPGAllCertificatesInclusion Include all certificates.}
* _{GPGNoCertificatesInclusion Include no certificates.}
- * _{GPGOnlySenderCertificateInclusion Include the sender's certificate only.}
- * _{n Include the first n certificates of the certificates path,
- * starting from the sender's certificate.
- * The number n must be positive.}
+ * _{GPGOnlySenderCertificateInclusion Include the sender's certificate
+ * only.}
+ * _{n Include the first n certificates
+ * of the certificates path, starting
+ * from the sender's certificate. The
+ * number n must be positive.}
"*/
typedef enum {
GPGAllExceptRootCertificatesInclusion = -2,
@@ -100,50 +120,96 @@
/*"
- * Posted whenever GPGME thinks that it is idle and time can be better
- * spent elsewhere.
- *
- * Object is nil; no userInfo.
+ * The 'status' value of a key import is a combination of the following bit
+ * values:
+ * _{GPGImportNewKeyMask Key is new in the key-ring}
+ * _{GPGImportNewUserIDMask Some new userIDs has been imported, or updated}
+ * _{GPGImportSignatureMask Some new key signatures have been imported, or
+ * updated}
+ * _{GPGImportSubkeyMask Some new subkeys have been imported, or updated}
+ * _{GPGImportSecretKeyMask Key is a secret key, and is new in the secret
+ * key-ring}
"*/
-GPG_EXPORT NSString * const GPGIdleNotification;
+typedef unsigned int GPGImportStatus;
+
+#define GPGImportNewKeyMask 1
+#define GPGImportNewUserIDMask 2
+#define GPGImportSignatureMask 4
+#define GPGImportSubkeyMask 8
+#define GPGImportSecretKeyMask 16
/*"
- * Posted after a modification to a keyring has been done. For example,
+ * Posted after a modification to a key-ring has been done. For example,
* after an import or delete operation.
*
* Object is (currently) nil.
*
* UserInfo:
- * _{GPGContextKey The #GPGContext instance in which the operation was executed.}
- *
+ * _{GPGContextKey The #GPGContext instance in which the operation was
+ * executed.}
+ * _{GPGChangesKey An #NSDictionary whose keys are GPGKey instances
+ * (secret and public keys) and whose values are NSDictionary
+ * instances containing key-value pair @"status" with a
+ * GPGImportStatus (as NSNumber), and possibly @"error"
+ * with a GPGError (as NSNumber).}
"*/
GPG_EXPORT NSString * const GPGKeyringChangedNotification;
GPG_EXPORT NSString * const GPGContextKey;
+GPG_EXPORT NSString * const GPGChangesKey;
/*"
- * Posted when progress information about a cryptographic operation is available,
- * for example during key generation.
+ * Posted when progress information about a cryptographic operation is
+ * available, for example during key generation.
*
* 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:
- * _{description String...}
- * _{type String containing the letter printed during key generation.}
- * _{current Amount done, as #NSNumber.}
- * _{total Amount to be done, as #NSNumber. 0 means that the total amount is not known.}
+ * _{@"description" String...}
+ * _{@"type" String containing the letter printed during key
+ * generation.}
+ * _{@"current" Amount done, as #NSNumber.}
+ * _{@"total" Amount to be done, as #NSNumber. 0 means that the total
+ * amount is not known.}
* current/total = 100/100 may be used to detect the end of operation.
"*/
GPG_EXPORT NSString * const GPGProgressNotification;
+/*"
+ * Posted when an asynchronous operation on a context has been terminated,
+ * 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:
+ * _{GPGErrorKey A #NSNumber containing a #GPGError value}
+"*/
+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;
+
+
@interface GPGContext : GPGObject /*"NSObject"*/
{
- id _passphraseDelegate; /*"Passphrase delegate, not retained."*/
+ id _passphraseDelegate; /*"Passphrase delegate, not retained."*/
+ int _operationMask;
+ NSMutableDictionary *_operationData;
+ id _userInfo; /*"Object set by user; not used by GPGContext itself."*/
+ NSMutableSet *_signerKeys;
}
/*"
@@ -152,11 +218,6 @@
- (id) init;
/*"
- * Notations
-"*/
-- (NSString *) notationsAsXMLString;
-
-/*"
* ASCII armor
"*/
- (void) setUsesArmor:(BOOL)armor;
@@ -181,11 +242,6 @@
- (GPGProtocol) protocol;
/*"
- * Operation status
-"*/
-- (NSString *) statusAsXMLString;
-
-/*"
* Passphrase delegate
"*/
- (void) setPassphraseDelegate:(id)delegate;
@@ -197,6 +253,7 @@
- (void) clearSignerKeys;
- (void) addSignerKey:(GPGKey *)key;
- (NSEnumerator *) signerKeyEnumerator;
+- (NSArray *) signerKeys;
/*"
* Including certificates (S/MIME only)
@@ -204,6 +261,17 @@
- (void) setCertificatesInclusion:(int)includedCertificatesNumber;
- (int) certificatesInclusion;
+/*"
+ * Operation results
+"*/
+- (NSDictionary *) operationResults;
+
+/*"
+ * Contextual information
+"*/
+- (void) setUserInfo:(id)userInfo;
+- (id) userInfo;
+
@end
@@ -211,15 +279,15 @@
/*"
* Asynchronous operations (#{NOTE THAT ASYNCHRONOUS OPERATIONS DON'T WORK RIGHT NOW.})
"*/
-- (void) cancelOperation;
+ (GPGContext *) waitOnAnyRequest:(BOOL)hang;
- (BOOL) wait:(BOOL)hang;
+- (void) cancel;
@end
@interface GPGContext(GPGSynchronousOperations)
/*"
- * Crypto operations
+ * #{Crypto operations}
"*/
/*"
* Decrypt
@@ -228,15 +296,14 @@
/*"
* Verify
"*/
-- (GPGSignatureStatus) verifySignatureData:(GPGData *)signatureData againstData:(GPGData *)inputData;
-- (GPGSignatureStatus) verifySignedData:(GPGData *)signedData;
-- (GPGSignatureStatus) statusOfSignatureAtIndex:(int)index creationDate:(NSCalendarDate **)creationDatePtr fingerprint:(NSString **)fingerprint;
-- (GPGKey *) keyOfSignatureAtIndex:(int)index;
+- (NSArray *) verifySignatureData:(GPGData *)signatureData againstData:(GPGData *)inputData;
+- (NSArray *) verifySignedData:(GPGData *)signedData;
+- (NSArray *) verifySignedData:(GPGData *)signedData originalData:(GPGData **)originalDataPtr;
- (NSArray *) signatures;
/*"
* Decrypt and verify
"*/
-- (GPGData *) decryptedData:(GPGData *)inputData signatureStatus:(GPGSignatureStatus *)statusPtr;
+- (GPGData *) decryptedData:(GPGData *)inputData signatures:(NSArray **)signaturesPtr;
/*"
* Sign
"*/
@@ -244,22 +311,28 @@
/*"
* Encrypt
"*/
-- (GPGData *) encryptedData:(GPGData *)inputData forRecipients:(GPGRecipients *)recipients allRecipientsAreValid:(BOOL *)allRecipientsAreValidPtr;
+- (GPGData *) encryptedData:(GPGData *)inputData withKeys:(NSArray *)recipientKeys trustAllKeys:(BOOL)trustAllKeys;
/*"
* Encrypt and Sign
"*/
-- (GPGData *) encryptedSignedData:(GPGData *)inputData forRecipients:(GPGRecipients *)recipients allRecipientsAreValid:(BOOL *)allRecipientsAreValidPtr;
+- (GPGData *) encryptedSignedData:(GPGData *)inputData withKeys:(NSArray *)keys trustAllKeys:(BOOL)trustAllKeys;
/*"
* Symmetric Encryption (no key needed)
"*/
- (GPGData *) encryptedData:(GPGData *)inputData;
/*"
- * Managing keyring
+ * Managing key-ring
"*/
-- (GPGData *) exportedKeysForRecipients:(GPGRecipients *)recipients;
-- (void) importKeyData:(GPGData *)keyData;
-//- (void) generateKeyWithXMLString:(NSString *)params secretKey:(GPGData **)secretKeyPtr publicKey:(GPGData **)publicKeyPtr;
+- (GPGData *) exportedKeys:(NSArray *)recipientKeys;
+- (NSDictionary *) importKeyData:(GPGData *)keyData;
+- (NSDictionary *) generateKeyFromDictionary:(NSDictionary *)params secretKey:(GPGData *)secretKeyData publicKey:(GPGData *)publicKeyData;
- (void) deleteKey:(GPGKey *)key evenIfSecretKey:(BOOL)allowSecret;
+/*"
+ * Finding/refreshing a single key
+"*/
+- (GPGKey *) keyFromFingerprint:(NSString *)fingerprint secretKey:(BOOL)secretKey;
+- (GPGKey *) refreshKey:(GPGKey *)key;
+
@end
@@ -278,10 +351,38 @@
@end
+@interface GPGContext(GPGExtendedKeyManagement)
+/*"
+ * Searching keys on a key server
+"*/
+- (void) asyncSearchForKeysMatchingPatterns:(NSArray *)searchPatterns serverOptions:(NSDictionary *)options;
+- (void) asyncDownloadKeys:(NSArray *)keys serverOptions:(NSDictionary *)options;
+/*"
+ * Uploading keys on a key server
+"*/
+- (void) asyncUploadKeys:(NSArray *)keys serverOptions:(NSDictionary *)options;
+
+/*"
+ * Interrupting async operations
+"*/
+- (void) interruptAsyncOperation;
+
+@end
+
+
+@interface GPGContext(GPGKeyGroups)
+/*"
+ * Getting key groups
+"*/
+- (NSArray *) keyGroups;
+@end
+
+
@interface NSObject(GPGContextDelegate)
- (NSString *) context:(GPGContext *)context passphraseForKey:(GPGKey *)key again:(BOOL)again;
@end
+
#ifdef __cplusplus
}
#endif
Index: GPGContext.m
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGContext.m,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- GPGContext.m 27 Sep 2003 14:27:24 -0000 1.19
+++ GPGContext.m 23 Jan 2005 13:20:01 -0000 1.20
@@ -2,25 +2,27 @@
// GPGContext.m
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code is free software; you can redistribute it and/or modify it under
[...3831 lines suppressed...]
#ifdef FAKE_IMPLEMENTATION_FOR_AUTODOC
+
@implementation NSObject(GPGContextDelegate)
- (NSString *) context:(GPGContext *)context passphraseForKey:(GPGKey *)key again:(BOOL)again
/*"
- * key is the secret key for which the user is asked a passphrase.
- * key is nil only in case of symmetric encryption/decryption.
- * again is set to YES if user type a wrong passphrase the previous time.
+ * key is the secret key for which the user is asked a passphrase. key is nil
+ * only in case of symmetric encryption/decryption. again is set to YES if
+ * user typed a wrong passphrase the previous time(s).
*
* If you return nil, it means that user cancelled passphrase request.
"*/
{
}
@end
+
#endif
Index: GPGData.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGData.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- GPGData.h 27 Sep 2003 14:27:24 -0000 1.7
+++ GPGData.h 23 Jan 2005 13:20:01 -0000 1.8
@@ -2,25 +2,27 @@
// GPGData.h
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGDATA_H
@@ -37,42 +39,26 @@
@class NSData;
+@class NSFileHandle;
@class NSMutableData;
@class NSString;
/*"
- * The #GPGDataType type specifies the type of a #GPGData instances.
- * The following data types are available:
- * _{GPGDataTypeNone This specifies that the type is not yet determined.}
- * _{GPGDataTypeData This specifies that the data is stored in memory.}
- * _{GPGDataTypeFileHandle This type is not implemented.}
- * _{GPGDataTypeFile This type is not implemented.}
- * _{GPGDataTypeDataSource This type specifies that the data is provided by a data source implemented by the user.}
-"*/
-typedef enum {
- GPGDataTypeNone = 0,
- GPGDataTypeData = 1,
- GPGDataTypeFileHandle = 2,
- GPGDataTypeFile = 3,
- GPGDataTypeDataSource = 4
-} GPGDataType;
-
-
-/*"
- * The #GPGDataEncoding type specifies the encoding of a #GPGData object.
- * This encoding is useful to give the backend a hint on the type of data.
- * The following data types are available:
+ * The #GPGDataEncoding type specifies the encoding of a #GPGData object. This
+ * encoding is useful to give the backend a hint on the type of data. The
+ * following data types are available:
* _{GPGDataEncodingNone This specifies that the encoding is not known.
- * This is the default for a new data object.
- * The backend will try its best to detect the
- * encoding automatically.}
- * _{GPGDataEncodingBinary This specifies that the data is encoding in binary form;
- * i.e. there is no special encoding.}
- * _{GPGDataEncodingBase64 This specifies that the data is encoded using the Base-64
- * encoding scheme as used by MIME and other protocols.}
- * _{GPGDataEncodingArmor This specifies that the data is encoded in an armored
- * form as used by OpenPGP and PEM.}
+ * This is the default for a new data object. The
+ * backend will try its best to detect the encoding
+ * automatically.}
+ * _{GPGDataEncodingBinary This specifies that the data is encoding in binary
+ * form; i.e. there is no special encoding.}
+ * _{GPGDataEncodingBase64 This specifies that the data is encoded using the
+ * Base-64 encoding scheme as used by MIME and other
+ * protocols.}
+ * _{GPGDataEncodingArmor This specifies that the data is encoded in an
+ * armored form as used by OpenPGP and PEM.}
"*/
typedef enum {
GPGDataEncodingNone = 0,
@@ -82,47 +68,102 @@
} GPGDataEncoding;
+/*"
+ * The #GPGDataOffsetType type specifies how the offset should be interpreted
+ * when repositioning read/write (#{-seekToFileOffset:offsetType:} and
+ * #{-data:seekToFileOffset:offsetType:}). It must be one of the following
+ * symbolic constants:
+ * _{GPGDataStartPosition Offset is a count of characters from the
+ * beginning of the data object.}
+ * _{GPGDataCurrentPosition Offset is a count of characters from the current
+ * file position. This count may be positive or
+ * negative.}
+ * _{GPGDataEndPosition Offset is a count of characters from the end of
+ * the data object. A negative count specifies a
+ * position within the current extent of the data
+ * object; a positive count specifies a position
+ * past the current end. If you set the position
+ * past the current end, and actually write data,
+ * you will extend the data object with zeros up to
+ * that position.}
+"*/
+typedef enum {
+ GPGDataStartPosition = 0,
+ GPGDataCurrentPosition = 1,
+ GPGDataEndPosition = 2
+} GPGDataOffsetType;
+
+
@interface GPGData : GPGObject /*"NSObject"*/
{
- id _dataSource;
- NSMutableData *_retainedData;
+ id _objectReference;
+ void *_callbacks;
}
-/*"Creating data buffers"*/
+/*"
+ * Creating memory based data buffers
+"*/
- (id) init;
- (id) initWithData:(NSData *)someData;
-- (id) initWithDataNoCopy:(NSMutableData *)someData;
-- (id) initWithString:(NSString *)string;
-- (id) initWithDataSource:(id)dataSource;
+- (id) initWithDataNoCopy:(NSData *)someData;
- (id) initWithContentsOfFile:(NSString *)filename;
//- (id) initWithContentsOfFileNoCopy:(NSString *)filename;
- (id) initWithContentsOfFile:(NSString *)filename atOffset:(unsigned long long)offset length:(unsigned long long)length;
-/*"Attributes"*/
+/*"
+ * Creating file based data buffers
+"*/
+- (id) initWithFileHandle:(NSFileHandle *)fileHandle;
+
+/*"
+ * Creating callback based data buffers
+"*/
+- (id) initWithDataSource:(id)dataSource;
+
+/*"
+ * Encoding
+"*/
+- (GPGDataEncoding) encoding;
+- (void) setEncoding:(GPGDataEncoding)encoding;
+
+/*"
+ * Manipulating data buffers
+"*/
+- (unsigned long long) seekToFileOffset:(unsigned long long)offset offsetType:(GPGDataOffsetType)offsetType;
+
+- (NSData *) readDataOfLength:(unsigned long long)length;
+- (unsigned long long) writeData:(NSData *)data;
+
+@end
+
+
+@interface GPGData(GPGExtensions)
+/*"
+ * Convenience initializer
+"*/
+- (id) initWithString:(NSString *)string;
+
+/*"
+ * Convenience methods
+"*/
+- (unsigned long long) length;
- (NSData *) data;
- (NSString *) string;
-- (unsigned long long) length;
- (NSData *) availableData;
- (unsigned long long) availableDataLength;
-- (BOOL) isAtEnd;
-
-- (GPGDataType) type;
-/*"Encoding"*/
-- (GPGDataEncoding) encoding;
-- (void) setEncoding:(GPGDataEncoding)encoding;
+- (BOOL) isAtEnd;
-/*"Manipulating data buffers"*/
- (void) rewind;
-- (NSData *) readDataOfLength:(unsigned int)length;
-- (void) writeData:(NSData *)data;
-
@end
@interface NSObject(GPGDataSource)
-- (NSData *) data:(GPGData *)data readLength:(unsigned int)maxLength;
+- (NSData *) data:(GPGData *)data readDataOfLength:(unsigned int)maxLength;
+- (unsigned long long) data:(GPGData *)data writeData:(NSData *)writeData;
+- (unsigned long long) data:(GPGData *)data seekToFileOffset:(unsigned long long)fileOffset offsetType:(GPGDataOffsetType)offsetType;
+- (void) dataRelease:(GPGData *)data;
@end
#ifdef __cplusplus
Index: GPGData.m
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGData.m,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- GPGData.m 27 Sep 2003 14:27:24 -0000 1.8
+++ GPGData.m 23 Jan 2005 13:20:01 -0000 1.9
@@ -2,62 +2,98 @@
// GPGData.m
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#include <GPGME/GPGData.h>
#include <GPGME/GPGExceptions.h>
+#include <GPGME/GPGInternals.h>
#include <Foundation/Foundation.h>
#include <gpgme.h>
-#define _data ((GpgmeData)_internalRepresentation)
-#define _dataPtr ((GpgmeData *)&_internalRepresentation)
+#define _data ((gpgme_data_t)_internalRepresentation)
@implementation GPGData
/*"
* A lot of data has to be exchanged between the user and the crypto engine,
- * like plaintext messages, ciphertext, signatures and information about the keys.
- * The technical details about exchanging the data information are completely
- * abstracted by GPGME. The user provides and receives the data via #GPGData instances,
- * regardless of the communication protocol between GPGME and the crypto engine in use.
+ * like plaintext messages, ciphertext, signatures and information about the
+ * keys. The technical details about exchanging the data information are
+ * completely abstracted by GPGME. The user provides and receives the data via
+ * #GPGData instances, regardless of the communication protocol between GPGME
+ * and the crypto engine in use.
+ *
+ * Data objects can be based on memory, files, or callback methods provided by
+ * the user (data source). Not all operations are supported by all objects.
+ *
+ * #{Memory Based Data Buffers}
+ *
+ * Memory based data objects store all data in allocated memory. This is
+ * convenient, but only practical for an amount of data that is a fraction of
+ * the available physical memory. The data has to be copied from its source
+ * and to its destination, which can often be avoided by using one of the
+ * other data object.
+ * Here are the methods to initialize memory based data buffers:
+ * _{-init }
+ * _{-initWithData:}
+ * _{-initWithDataNoCopy:}
+ * _{-initWithContentsOfFile:}
+ * _{-initWithContentsOfFile:atOffset:length:}
+ *
+ * #{File Based Data Buffers}
+ *
+ * File based data objects operate directly on file descriptors or streams.
+ * Only a small amount of data is stored in core at any time, so the size of
+ * the data objects is not limited by GPGME.
+ * Here are the methods to initialize file based data buffers:
+ * _{-initWithFileHandle:}
+ *
+ * #{Callback Based Data Buffers}
+ *
+ * If neither memory nor file based data objects are a good fit for your
+ * application, you can provide a data source implementing
+ * #{NSObject(GPGDataSource)} methods and create a data object with this data
+ * source.
+ * Here are the methods to initialize callback based data buffers:
+ * _{-initWithDataSource: }
"*/
- (id) init
/*"
- * Data is created without content. Type is set to #GPGDataTypeNone; it can later
- * be set to #GPGDataTypeData.
+ * Data is created without content and is memory based.
*
* Can raise a #GPGException; in this case, a #release is sent to self.
"*/
{
- GpgmeError anError = gpgme_data_new(_dataPtr);
+ gpgme_data_t aData;
+ gpgme_error_t anError = gpgme_data_new(&aData);
- if(anError != GPGME_No_Error){
- _data = NULL;
+ if(anError != GPG_ERR_NO_ERROR){
[self release];
[[NSException exceptionWithGPGError:anError userInfo:nil] raise];
}
- self = [self initWithInternalRepresentation:_data];
+ self = [self initWithInternalRepresentation:aData];
return self;
}
@@ -65,161 +101,224 @@
- (id) initWithData:(NSData *)someData
/*"
* Copies someData's bytes.
- * Type is set to #GPGDataTypeData.
*
* Can raise a #GPGException; in this case, a #release is sent to self.
"*/
{
- GpgmeError anError = gpgme_data_new_from_mem(_dataPtr, [someData bytes], [someData length], 1);
+ gpgme_data_t aData;
+ gpgme_error_t anError = gpgme_data_new_from_mem(&aData, [someData bytes], [someData length], 1);
- if(anError != GPGME_No_Error){
- _data = NULL;
+ if(anError != GPG_ERR_NO_ERROR){
[self release];
[[NSException exceptionWithGPGError:anError userInfo:nil] raise];
}
- self = [self initWithInternalRepresentation:_data];
+ self = [self initWithInternalRepresentation:aData];
return self;
}
-- (id) initWithDataNoCopy:(NSMutableData *)someData
+- (id) initWithDataNoCopy:(NSData *)someData
/*"
- * Doesn't copy someData, but user needs to make sure that someData remains valid
- * until #dealloc. Type is set to #GPGDataTypeData.
+ * Doesn't copy someData, but retains it.
*
* Can raise a #GPGException; in this case, a #release is sent to self.
"*/
{
-#warning Is someData really to be modified??? Ask Werner.
- // No, it seems that data is not modified, because
- // there is a const char *buffer => buffer is not modified
- // => No difference with -initWithData: ???
- // Difference is that with this initialization, we know that
- // Gpgme_data will not be modified.
- // The same applies for gpgme_data_new_from_file()
- ////////// NOT SURE ABOUT THIS... ////////////////
- GpgmeError anError = gpgme_data_new_from_mem(_dataPtr, [someData mutableBytes], [someData length], 0);
+ gpgme_data_t aData;
+ gpgme_error_t anError = gpgme_data_new_from_mem(&aData, ([someData respondsToSelector:@selector(mutableBytes)] ? [(NSMutableData *)someData mutableBytes]:[someData bytes]), [someData length], 0);
- if(anError != GPGME_No_Error){
- _data = NULL;
+ if(anError != GPG_ERR_NO_ERROR){
[self release];
[[NSException exceptionWithGPGError:anError userInfo:nil] raise];
}
- self = [self initWithInternalRepresentation:_data];
- [_retainedData retain];
+ self = [self initWithInternalRepresentation:aData];
+ ((GPGData *)self)->_objectReference = [someData retain];
return self;
}
-static int readCallback(void *object, char *destinationBuffer, size_t destinationBufferSize, size_t *readLengthPtr)
+static ssize_t readCallback(void *object, void *destinationBuffer, size_t destinationBufferSize)
{
- // Returns GPGME_No_Error if it could read anything, else any other value.
- // In case of rewinding (destinationBuffer = NULL), returns GPGME_No_Error if implemented, else any other value.
- volatile NSData *readData = nil;
+ // Returns the number of bytes read, or -1 on error. Sets errno in case of error.
+ NSData *readData = nil;
+ ssize_t readLength = 0;
- NSCParameterAssert(destinationBufferSize != 0 || (destinationBuffer == NULL && readLengthPtr == NULL));
+ NSCParameterAssert(destinationBufferSize != 0 && destinationBuffer != NULL);
NS_DURING
- readData = [((GPGData *)object)->_dataSource data:((GPGData *)object) readLength:destinationBufferSize];
+ readData = [((GPGData *)object)->_objectReference data:((GPGData *)object) readDataOfLength:destinationBufferSize];
NS_HANDLER
if([[localException name] isEqualToString:GPGException]){
- NSNumber *errorCodeNumber = [[localException userInfo] objectForKey:GPGErrorCodeKey];
-
- NSCAssert1(errorCodeNumber != nil && [errorCodeNumber intValue] == GPGErrorNotImplemented, @"### GPGException raised by GPGData dataSource is not GPGErrorNotImplemented (%@)", errorCodeNumber);
+ NSNumber *errorNumber = [[localException userInfo] objectForKey:GPGErrorKey];
+ int errorCodeAsErrno;
- // Rewinding not implemented
+ NSCAssert(errorNumber != nil, @"### GPGException raised by GPGData dataSource has no error");
+ errorCodeAsErrno = gpg_err_code_to_errno(gpgme_err_code([errorNumber intValue]));
+ NSCAssert2(errorCodeAsErrno != 0, @"### GPGException raised by GPGData dataSource has not a system error errorCode (%@: %@)", errorNumber, GPGErrorDescription([errorNumber intValue]));
+
+ errno = errorCodeAsErrno;
- return !GPGME_No_Error;
+ return -1;
}
else
[localException raise];
NS_ENDHANDLER
- if(readData == nil){
- // Rewinding or EOF
- if(readLengthPtr != NULL)
- *readLengthPtr = 0;
-
- return (destinationBuffer == NULL ? GPGME_No_Error:!GPGME_No_Error);
- }
- else{
- size_t aLength = [(NSData *)readData length];
-
- if(readLengthPtr != NULL)
- *readLengthPtr = aLength;
- NSCAssert(aLength <= destinationBufferSize, @"### GPGData dataSource may not return more bytes than given capacity!");
- [(NSData *)readData getBytes:destinationBuffer];
-
- return GPGME_No_Error;
+ if(readData != nil){
+ readLength = [readData length];
+
+ if(readLength > 0){
+ NSCAssert(((size_t)readLength) <= destinationBufferSize, @"### GPGData dataSource may not return more bytes than given capacity!");
+ [readData getBytes:destinationBuffer];
+ }
}
+
+ return readLength;
+}
+
+static ssize_t writeCallback(void *object, const void *buffer, size_t size)
+{
+ // Returns the number of bytes written, or -1 on error. Sets errno in case of error.
+ unsigned long long writeLength = 0;
+ NSData *data = [NSData dataWithBytesNoCopy:(void *)buffer length:size freeWhenDone:NO];
+
+ NS_DURING
+ writeLength = [((GPGData *)object)->_objectReference data:((GPGData *)object) writeData:data];
+ NS_HANDLER
+ if([[localException name] isEqualToString:GPGException]){
+ NSNumber *errorNumber = [[localException userInfo] objectForKey:GPGErrorKey];
+ int errorCodeAsErrno;
+
+ NSCAssert(errorNumber != nil, @"### GPGException raised by GPGData dataSource has no error");
+ errorCodeAsErrno = gpg_err_code_to_errno(gpgme_err_code([errorNumber intValue]));
+ NSCAssert2(errorCodeAsErrno != 0, @"### GPGException raised by GPGData dataSource has not a system error errorCode (%@: %@)", errorNumber, GPGErrorDescription([errorNumber intValue]));
+
+ errno = errorCodeAsErrno;
+
+ return -1;
+ }
+ else
+ [localException raise];
+ NS_ENDHANDLER
+
+ return writeLength;
+}
+
+static off_t seekCallback(void *object, off_t offset, int whence)
+{
+ // Returns the number of bytes written, or -1 on error. Sets errno in case of error.
+ off_t newPosition = 0;
+
+ NS_DURING
+ newPosition = [((GPGData *)object)->_objectReference data:((GPGData *)object) seekToFileOffset:offset offsetType:whence];
+ NS_HANDLER
+ if([[localException name] isEqualToString:GPGException]){
+ NSNumber *errorNumber = [[localException userInfo] objectForKey:GPGErrorKey];
+ int errorCodeAsErrno;
+
+ NSCAssert(errorNumber != nil, @"### GPGException raised by GPGData dataSource has no error");
+ errorCodeAsErrno = gpg_err_code_to_errno(gpgme_err_code([errorNumber intValue]));
+ NSCAssert2(errorCodeAsErrno != 0, @"### GPGException raised by GPGData dataSource has not a system error errorCode (%@: %@)", errorNumber, GPGErrorDescription([errorNumber intValue]));
+
+ errno = errorCodeAsErrno;
+
+ return -1;
+ }
+ else
+ [localException raise];
+ NS_ENDHANDLER
+
+ return newPosition;
+}
+
+static void releaseCallback(void *object)
+{
+ [((GPGData *)object)->_objectReference dataRelease:((GPGData *)object)];
}
- (id) initWithDataSource:(id)dataSource
/*"
- * dataSource must respond to selector #{data:readLength:}. dataSource is not
- * retained. dataSource is invoked to retrieve data on-demand, and it can
+ * dataSource must implement some of the methods declared in
+ * #{NSObject(GPGDataSource)} informal protocol. dataSource is not retained.
+ * dataSource is invoked to read/write data on-demand, and it can
* supply the data in any way it wants; this is the most flexible data type
- * GPGME provides. However it cannot be used to write data.
+ * GPGME provides.
*
* Can raise a #GPGException; in this case, a #release is sent to self.
"*/
{
- GpgmeError anError;
+ gpgme_data_t aData;
+ gpgme_error_t anError;
+ gpgme_data_cbs_t callbacks;
- NSParameterAssert(dataSource != nil && [dataSource respondsToSelector:@selector(data:readLength:)]);
+ NSParameterAssert(dataSource != nil);
- anError = gpgme_data_new_with_read_cb(_dataPtr, readCallback, self);
+ callbacks = (gpgme_data_cbs_t)NSZoneMalloc([self zone], sizeof(struct gpgme_data_cbs));
+ if([dataSource respondsToSelector:@selector(data:readDataOfLength:)])
+ callbacks->read = readCallback;
+ if([dataSource respondsToSelector:@selector(data:writeData:)])
+ callbacks->write = writeCallback;
+ if([dataSource respondsToSelector:@selector(data:seekToFileOffset:offsetType:)])
+ callbacks->seek = seekCallback;
+ if([dataSource respondsToSelector:@selector(data:dataRelease:)])
+ callbacks->release = releaseCallback;
+
+ NSParameterAssert(callbacks->read != NULL || callbacks->write != NULL);
- if(anError != GPGME_No_Error){
- _data = NULL;
+ anError = gpgme_data_new_from_cbs(&aData, callbacks, self);
+
+ if(anError != GPG_ERR_NO_ERROR){
+ NSZoneFree([self zone], callbacks);
[self release];
[[NSException exceptionWithGPGError:anError userInfo:nil] raise];
}
- self = [self initWithInternalRepresentation:_data];
- _dataSource = dataSource; // We don't retain dataSource
+ NSAssert(self == [self initWithInternalRepresentation:aData], @"Tried to change self! Impossible due to callback registration.");
+ _objectReference = dataSource; // We don't retain dataSource
+ _callbacks = callbacks;
return self;
}
- (id) initWithContentsOfFile:(NSString *)filename
/*"
- * Immediately opens file and copies content into memory; then it closes file.
+ * Immediately opens file named filename (which must be an absolute path) and
+ * copies content into memory; then it closes file.
*
* Can raise a #GPGException; in this case, a #release is sent to self.
"*/
{
- GpgmeError anError = gpgme_data_new_from_file(_dataPtr, [filename fileSystemRepresentation], 1);
+ gpgme_data_t aData;
+ gpgme_error_t anError = gpgme_data_new_from_file(&aData, [filename fileSystemRepresentation], 1);
- if(anError != GPGME_No_Error){
- _data = NULL;
+ if(anError != GPG_ERR_NO_ERROR){
[self release];
[[NSException exceptionWithGPGError:anError userInfo:nil] raise];
}
- self = [self initWithInternalRepresentation:_data];
+ self = [self initWithInternalRepresentation:aData];
return self;
}
- (id) initWithContentsOfFileNoCopy:(NSString *)filename
-// Not yet supported as of 0.3.3
+#warning Not yet supported as of 1.0.x
// Can raise a GPGException; in this case, a release is sent to self
{
- GpgmeError anError = gpgme_data_new_from_file(_dataPtr, [filename fileSystemRepresentation], 0);
+ gpgme_data_t aData;
+ gpgme_error_t anError = gpgme_data_new_from_file(&aData, [filename fileSystemRepresentation], 0);
- if(anError != GPGME_No_Error){
- _data = NULL;
+ if(anError != GPG_ERR_NO_ERROR){
[self release];
[[NSException exceptionWithGPGError:anError userInfo:nil] raise];
}
- self = [self initWithInternalRepresentation:_data];
+ self = [self initWithInternalRepresentation:aData];
return self;
}
- (id) initWithContentsOfFile:(NSString *)filename atOffset:(unsigned long long)offset length:(unsigned long long)length
/*"
- * Immediately opens file and copies partial content into memory; then it closes
- * file.
+ * Immediately opens file and copies partial content into memory; then it
+ * closes file.
*
* Can raise a #GPGException; in this case, a #release is sent to self.
"*/
@@ -227,24 +326,56 @@
// We don't provide a method to match the case where filename is NULL
// and filePtr (FILE *) is not NULL (both arguments are exclusive),
// because we generally don't manipulate FILE * types in Cocoa.
- GpgmeError anError = gpgme_data_new_from_filepart(_dataPtr, [filename fileSystemRepresentation], NULL, offset, length);
+ gpgme_data_t aData;
+ gpgme_error_t anError = gpgme_data_new_from_filepart(&aData, [filename fileSystemRepresentation], NULL, offset, length);
- if(anError != GPGME_No_Error){
- _data = NULL;
+ if(anError != GPG_ERR_NO_ERROR){
[self release];
[[NSException exceptionWithGPGError:anError userInfo:nil] raise];
}
- self = [self initWithInternalRepresentation:_data];
+ self = [self initWithInternalRepresentation:aData];
+
+ return self;
+}
+
+// We don't support gpgme_data_new_from_stream(), because there is
+// no STREAM handling in Cocoa, yet(?).
+// Maybe in Panther with NSStream?
+
+- (id) initWithFileHandle:(NSFileHandle *)fileHandle
+/*"
+ * Uses fileHandle to read from (if used as an input data object) and write to
+ * (if used as an output data object). fileHandle is retained.
+ *
+ * When using the data object as an input buffer, the method might read a bit
+ * more from the file handle than is actually needed by the crypto engine in
+ * the desired operation because of internal buffering.
+ *
+ * Can raise a #GPGException; in this case, a #release is sent to self.
+"*/
+{
+ gpgme_data_t aData;
+ gpgme_error_t anError = gpgme_data_new_from_fd(&aData, [fileHandle fileDescriptor]);
+
+ if(anError != GPG_ERR_NO_ERROR){
+ [self release];
+ [[NSException exceptionWithGPGError:anError userInfo:nil] raise];
+ }
+ self = [self initWithInternalRepresentation:aData];
+ ((GPGData *)self)->_objectReference = [fileHandle retain];
return self;
}
- (void) dealloc
{
- GpgmeData cachedData = _data;
+ gpgme_data_t cachedData = _data;
- if(_retainedData != nil)
- [_retainedData release];
+ if(_callbacks != NULL)
+ NSZoneFree([self zone], _callbacks);
+ // If _callbacks is not NULL, it means that _objectReference was a non-retained dataSource
+ else if(_objectReference != nil)
+ [_objectReference release];
[super dealloc];
// We could have a problem here if we set ourself as callback
@@ -254,6 +385,7 @@
gpgme_data_release(cachedData);
}
+#if 0
- (id) copyWithZone:(NSZone *)zone
{
GPGData *aCopy = nil;
@@ -270,7 +402,7 @@
[copiedData release];
}
else
- aCopy = [[[self class] allocWithZone:zone] initWithData:[self data]]; // WARNING: his rewinds myself and reads until EOF!
+ aCopy = [[[self class] allocWithZone:zone] initWithData:[self data]]; // WARNING: this rewinds myself and reads until EOF!
break;
case GPGDataTypeFileHandle:
// We don't provide a way in GPGME to create such data types
@@ -290,228 +422,239 @@
return aCopy;
}
+#endif
-- (unsigned long long) availableDataLength
+- (GPGDataEncoding) encoding
/*"
- * Returns the amount of bytes available without changing the read pointer.
- * This is not supported by all types of data objects.
- *
- * If this method is not supported, a #GPGException is raised, with error
- * #GPGErrorInvalidType.
- *
- * If end of data object is reached or no data is currently available,
- * it returns 0. To know if there are more bytes to read, you must
- * invoke #{-isAtEnd}.
+ * Returns the encoding of the data object.
"*/
{
- size_t availableDataLength;
- GpgmeError anError = gpgme_data_read(_data, NULL, 0, &availableDataLength);
-
- if(anError != GPGME_No_Error && anError != GPGErrorEOF)
- [[NSException exceptionWithGPGError:anError userInfo:nil] raise];
+ GPGDataEncoding encoding = gpgme_data_get_encoding(_data);
- return availableDataLength;
+ return encoding;
}
-- (unsigned long long) length
+- (void) setEncoding:(GPGDataEncoding)encoding
/*"
- * Convenience method. Returns length of all data.
- * It rewinds receiver, then reads available data length
- * and returns it. Read pointer is reset.
- *
- * If this method is not supported, a #GPGException is raised, with error
- * #GPGErrorInvalidType.
+ * Sets the encoding of the data object.
*
* Can raise a #GPGException.
"*/
{
- [self rewind];
-
- return [self availableDataLength];
+ gpgme_error_t anError = gpgme_data_set_encoding(_data, encoding);
+
+ if(anError != GPG_ERR_NO_ERROR)
+ [[NSException exceptionWithGPGError:anError userInfo:nil] raise];
}
-- (BOOL) isAtEnd
+- (unsigned long long) seekToFileOffset:(unsigned long long)offset offsetType:(GPGDataOffsetType)offsetType
/*"
- * Returns YES if there are no more bytes to read (EOF). If #{-availableDataLength} returns 0,
- * it means that either there is nothing more to read, or there is currently nothing to read.
- * Read pointer is not moved.
- *
- * If this method is not supported, a #GPGException is raised, with error
- * #GPGErrorInvalidType.
+ * Sets the current position from where the next read or write starts in the
+ * data object to offset, relativ to offsetType. Returns the resulting file
+ * position, measured in bytes from the beginning of the data object. You can
+ * use this feature together with #GPGDataCurrentPosition to read the current
+ * read/write position.
*
- * Can raise a #GPGException.
+ * Can raise a #GPGException of type #{GPGError_E*}.
"*/
{
- size_t availableDataLength;
- GpgmeError anError = gpgme_data_read(_data, NULL, 0, &availableDataLength);
+ off_t newPosition = gpgme_data_seek(_data, offset, offsetType);
- if(anError != GPGME_No_Error)
- if(anError != GPGErrorEOF)
- [[NSException exceptionWithGPGError:anError userInfo:nil] raise];
- else
- return YES;
+ if(newPosition < 0)
+ [[NSException exceptionWithGPGError:gpgme_err_make_from_errno(GPG_GPGMEFrameworkErrorSource, errno) userInfo:nil] raise];
- return NO;
+ return newPosition;
}
-- (NSData *) availableData
+- (NSData *) readDataOfLength:(unsigned long long)length
/*"
- * Returns a copy of data, read from current position, up to end of data.
+ * Reads up to length bytes and returns them wrapped in a #NSData. Reading
+ * starts from the current position. Returned data has the appropriate size,
+ * smaller or equal to length. Returns nil when there isn't anything more to
+ * read (EOF).
*
- * Can raise a #GPGException.
+ * Can raise a #GPGException of type #{GPGError_E*}.
"*/
{
- GpgmeError anError;
- size_t bufferSize = NSPageSize();
- NSZone *aZone = NSDefaultMallocZone();
- char *bufferPtr = (char *)NSZoneMalloc(aZone, bufferSize);
- NSMutableData *readData = [NSMutableData dataWithCapacity:bufferSize];
+ NSMutableData *readData = [NSMutableData dataWithLength:length];
+ ssize_t aReadLength = gpgme_data_read(_data, [readData mutableBytes], length);
- do{
- size_t aReadLength;
-
- anError = gpgme_data_read(_data, bufferPtr, bufferSize, &aReadLength);
- // CAUTION: function can return a length of 0, without being at EOF
- // => could potentially turn into a dead-lock here!
- if(anError == GPGME_No_Error && aReadLength > 0)
- [readData appendBytes:bufferPtr length:aReadLength];
- }while(anError == GPGME_No_Error);
-
- NSZoneFree(aZone, bufferPtr);
- if(anError != GPGME_EOF)
- [[NSException exceptionWithGPGError:anError userInfo:nil] raise];
+ if(aReadLength == 0)
+ return nil;
+ if(aReadLength < 0)
+ [[NSException exceptionWithGPGError:gpgme_err_make_from_errno(GPG_GPGMEFrameworkErrorSource, errno) userInfo:nil] raise];
+ [readData setLength:aReadLength];
return readData;
}
-- (NSData *) data
+- (unsigned long long) writeData:(NSData *)data
/*"
- * Convenience method. Returns a copy of all data.
- * It rewinds receiver, then reads data
- * until EOF, and returns it.
+ * Writes data bytes by copying them. Writing starts from the current
+ * position. Returns the number of bytes written.
*
- * Can raise a #GPGException.
+ * Can raise a #GPGException of type #{GPGError_E*}.
"*/
{
- [self rewind];
+ ssize_t writtenByteCount = gpgme_data_write(_data, [data bytes], [data length]);
- return [self availableData];
+ if(writtenByteCount < 0)
+ [[NSException exceptionWithGPGError:gpgme_err_make_from_errno(GPG_GPGMEFrameworkErrorSource, errno) userInfo:nil] raise];
+
+ return writtenByteCount;
}
-- (GPGDataType) type
+@end
+
+
+@implementation GPGData(GPGExtensions)
+
+- (id) initWithString:(NSString *)string
/*"
- * Returns the type of the data object.
+ * Convenience method. Gets data from string using UTF8 encoding, and invokes
+ * #{-initWithData:}.
+ *
+ * Can raise a #GPGException; in this case, a #release is sent to self.
"*/
{
- GPGDataType type = gpgme_data_get_type(_data);
-
- NSAssert(type != GPGME_DATA_TYPE_NONE, @"### _data is not a valid pointer");
-
- return type;
+ NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
+
+ return [self initWithData:data];
}
-- (GPGDataEncoding) encoding
+- (NSString *) string
/*"
- * Returns the encoding of the data object.
+ * Convenience method. Returns a copy of all data as string, using UTF8 string
+ * encoding (or ISOLatin1 if it cannot be decoded as UTF8). It rewinds
+ * receiver, then reads data until EOF, and returns a string initialized with
+ * it.
+ *
+ * Invoking this method has sense only when you know that data corresponds to
+ * a string!
+ *
+ * Can raise a #GPGException.
"*/
{
- GPGDataEncoding encoding = gpgme_data_get_encoding(_data);
+ NSData *data = [self data];
- return encoding;
+ return GPGStringFromChars([data bytes]);
}
-- (void) setEncoding:(GPGDataEncoding)encoding
+- (unsigned long long) availableDataLength
/*"
- * Sets the encoding of the data object.
+ * Returns the amount of bytes available without changing the read pointer.
+ * This is not supported by all types of data objects.
*
- * Can raise a #GPGException.
+ * If this method is not supported, a #GPGException is raised, with error
+ * #GPGErrorInvalidType.
+ *
+ * If end of data object is reached or no data is currently available, it
+ * returns 0. To know if there are more bytes to read, you must invoke
+ * #{-isAtEnd}.
+ *
+ * Can raise a #GPGException of type #{GPGError_E*}.
"*/
{
- GpgmeError anError = gpgme_data_set_encoding(_data, encoding);
+ ssize_t availableDataLength = gpgme_data_read(_data, NULL, 0);
- if(anError != GPGME_No_Error)
- [[NSException exceptionWithGPGError:anError userInfo:nil] raise];
+ if(availableDataLength < 0)
+ [[NSException exceptionWithGPGError:gpgme_err_make_from_errno(GPG_GPGMEFrameworkErrorSource, errno) userInfo:nil] raise];
+
+ return availableDataLength;
}
-- (void) rewind
+- (unsigned long long) length
/*"
- * Prepares data in a way that the next call to #{-readDataOfLength:} starts at
- * the beginning of the data. This has to be done for all types of #GPGData instances.
+ * Convenience method. Returns length of all data. It rewinds receiver, then
+ * reads available data length and returns it. Read pointer is reset.
+ *
+ * If this method is not supported, a #GPGException is raised, with error
+ * #GPGErrorInvalidType.
*
* Can raise a #GPGException.
"*/
{
- GpgmeError anError = gpgme_data_rewind(_data);
-
- if(anError != GPGME_No_Error)
- [[NSException exceptionWithGPGError:anError userInfo:nil] raise];
+ [self rewind];
+
+ return [self availableDataLength];
}
-- (NSData *) readDataOfLength:(unsigned int)length
+- (BOOL) isAtEnd
/*"
- * Reading starts from the current position. Returned data has the
- * appropriate size, smaller or equal to length. Returns nil when there isn't
- * anything more to read (EOF). Read data should be copied, not referenced.
+ * Returns YES if there are no more bytes to read (EOF). Read pointer is not
+ * moved.
*
- * Can raise a #GPGException (but never a #GPGErrorEOF one).
+ * If this method is not supported, a #GPGException is raised, with error
+ * #GPGErrorInvalidType.
+ *
+ * Can raise a #GPGException of type #{GPGError_E*}.
"*/
{
- GpgmeError anError;
- NSMutableData *readData = [NSMutableData dataWithLength:length];
- size_t aReadLength;
-
- anError = gpgme_data_read(_data, [readData mutableBytes], length, &aReadLength);
- if(anError == GPGME_EOF)
- return nil;
- if(anError != GPGME_No_Error)
- [[NSException exceptionWithGPGError:anError userInfo:nil] raise];
- [readData setLength:aReadLength];
+ ssize_t availableDataLength = gpgme_data_read(_data, NULL, 0);
- return readData;
+ if(availableDataLength < 0)
+ [[NSException exceptionWithGPGError:gpgme_err_make_from_errno(GPG_GPGMEFrameworkErrorSource, errno) userInfo:nil] raise];
+ else if(availableDataLength == 0)
+ return YES;
+
+ return NO;
}
-- (void) writeData:(NSData *)data
+- (NSData *) availableData
/*"
- * Writing starts from the current position. Writes all data (makes a copy of it).
+ * Returns a copy of data, read from current position, up to end of data.
*
- * Can raise a #GPGException.
+ * Can raise a #GPGException of type #{GPGError_E*}.
"*/
{
- GpgmeError anError = gpgme_data_write(_data, [data bytes], [data length]);
+ size_t bufferSize = NSPageSize();
+ NSZone *aZone = NSDefaultMallocZone();
+ char *bufferPtr = (char *)NSZoneMalloc(aZone, bufferSize);
+ NSMutableData *readData = [NSMutableData dataWithCapacity:bufferSize];
+ ssize_t aReadLength;
- if(anError != GPGME_No_Error)
- [[NSException exceptionWithGPGError:anError userInfo:nil] raise];
+ do{
+ aReadLength = gpgme_data_read(_data, bufferPtr, bufferSize);
+
+ if(aReadLength > 0)
+ [readData appendBytes:bufferPtr length:aReadLength];
+ }while(aReadLength > 0);
+
+ NSZoneFree(aZone, bufferPtr);
+ if(aReadLength < 0)
+ [[NSException exceptionWithGPGError:gpgme_err_make_from_errno(GPG_GPGMEFrameworkErrorSource, errno) userInfo:nil] raise];
+
+ return readData;
}
-- (id) initWithString:(NSString *)string
+- (NSData *) data
/*"
- * Convenience method.
- * Gets data from string, and invokes #{-initWithData:}.
- * Type is set to #GPGDataTypeData.
+ * Convenience method. Returns a copy of all data. It rewinds receiver, then
+ * reads data until EOF, and returns it.
*
- * Can raise a #GPGException; in this case, a #release is sent to self.
+ * If this method is not supported, a #GPGException is raised, with error
+ * #GPGErrorInvalidType.
+ *
+ * Can raise a #GPGException.
"*/
{
- NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
+ [self rewind];
- return [self initWithData:data];
+ return [self availableData];
}
-- (NSString *) string
+- (void) rewind
/*"
- * Convenience method. Returns a copy of all data as string.
- * It rewinds receiver, then reads data
- * until EOF, and returns a string initialized with it.
- *
- * Invoking this method has sense only when you know
- * that data corresponds to a string!
+ * Prepares data in a way that the next call to #{-readDataOfLength:} or
+ * #{-writeData:} starts at the beginning of the data.
*
- * Can raise a #GPGException.
+ * Can raise a #GPGException of type #{GPGError_E*}.
"*/
{
- NSData *data = [self data];
+ off_t newPosition = gpgme_data_seek(_data, 0, GPGDataStartPosition);
- return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
+ if(newPosition < 0)
+ [[NSException exceptionWithGPGError:gpgme_err_make_from_errno(GPG_GPGMEFrameworkErrorSource, errno) userInfo:nil] raise];
}
@end
@@ -519,7 +662,7 @@
@implementation GPGData(GPGInternals)
-- (GpgmeData) gpgmeData
+- (gpgme_data_t) gpgmeData
{
return _data;
}
@@ -531,17 +674,46 @@
// just to force autodoc to take our comments in account!
#ifdef FAKE_IMPLEMENTATION_FOR_AUTODOC
@implementation NSObject(GPGDataSource)
-- (NSData *) data:(GPGData *)data readLength:(unsigned int)maxLength
/*"
- * Returned data must have a length smaller or equal to maxLength.
- * If there is no data currently available, return an empty data.
- * If there is nothing more to read (EOF), return nil.
- * If maxLength is 0, dataSource is asked to reset/rewind its internal pointer;
- * if it is not possible, raise a #GPGException with error #GPGErrorNotImplemented,
- * else return nil.
+ * This category declares methods that need to be implemented by
+ * #GPGData data sources. Data sources can be readable or writable.
+"*/
+- (NSData *) data:(GPGData *)data readDataOfLength:(unsigned long long)maxLength
+/*"
+ * Reads up to maxLength bytes of data and returns it. Returning an empty data
+ * or nil means that there is nothing more to read (EOF). Only required for
+ * input data objects.
+ *
+ * Reading must be performed from the current position.
+ *
+ * In case of error, raise a #GPGException of type #{GPGError_E*}.
*
* Returned data will be copied.
"*/
{}
+
+- (unsigned long long) data:(GPGData *)data writeData:(NSData *)writeData
+/*"
+ * Writes writeData from the current position. Returns the number of
+ * bytes written. Only required for output data objects.
+ *
+ * In case of error, raise a #GPGException of type #{GPGError_E*}.
+"*/
+{}
+
+- (unsigned long long) data:(GPGData *)data seekToFileOffset:(unsigned long long)fileOffset offsetType:(GPGDataOffsetType)offsetType
+/*"
+ * Changes the read/write position according to fileOffset and offsetType. Returns the new
+ * absolute position. Optional method.
+ *
+ * In case of error, raise a #GPGException of type #{GPGError_E*}.
+"*/
+{}
+
+- (void) dataRelease:(GPGData *)data
+/*"
+ * Releases internal resources owned by the data source. Optional method.
+"*/
+{}
@end
#endif
Index: GPGDefines.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGDefines.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- GPGDefines.h 27 Sep 2003 14:27:24 -0000 1.4
+++ GPGDefines.h 23 Jan 2005 13:20:01 -0000 1.5
@@ -2,25 +2,27 @@
// GPGDefines.h
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGDEFINES_H
Index: GPGEngine.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGEngine.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- GPGEngine.h 27 Sep 2003 14:27:24 -0000 1.6
+++ GPGEngine.h 23 Jan 2005 13:20:01 -0000 1.7
@@ -2,31 +2,34 @@
// GPGEngine.h
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGENGINE_H
#define GPGENGINE_H
-#include <GPGME/GPGDefines.h>
+#include <GPGME/GPGObject.h>
+#include <GPGME/GPGExceptions.h>
#ifdef __cplusplus
extern "C" {
@@ -37,170 +40,40 @@
@class NSString;
+@class NSArray;
/*"
- * The #GPGError type specifies the set of all error values that are used by GPGME.
- * Possible values are:
- * _{GPGErrorEOF This value indicates the end of a list, buffer or file. Not used in GPGME framework.}
- * _{GPGErrorNoError This value indicates success. No #GPGException is raised with this value.}
- * _{GPGErrorGeneralError This value means that something went wrong,
- * but either there is not enough information
- * about the problem to return a more useful error value,
- * or there is no seperate error value for this type of problem.}
- * _{GPGErrorOutOfCore This value means that an out-of-memory condition occured.}
- * _{GPGErrorInvalidValue This value means that some user provided data was out of range.
- * This can also refer to objects. For example, if an empty #GPGData
- * instance was expected, but one containing data was provided,
- * this error value is returned.}
- * _{GPGErrorBusy This value is returned if you try to start a new operation
- * in a context that is already busy with some earlier operation
- * which was not canceled or finished yet.}
- * _{GPGErrorNoRequest This value is in some sense the opposite of #GPGErrorBusy.
- * There is no pending operation, but it is required for the function to succeed.}
- * _{GPGErrorExecError This value means that an error occured when trying to spawn a child process.}
- * _{GPGErrorTooManyProcs This value means that there are too many active backend processes.}
- * _{GPGErrorPipeError This value means that the creation of a pipe failed.}
- * _{GPGErrorNoRecipients This value means that no %recipients for a message have been set.}
- * _{GPGErrorNoData This value means that a #GPGData instance which was expected
- * to have content was found empty.}
- * _{GPGErrorConflict This value means that a conflict of some sort occured.}
- * _{GPGErrorNotImplemented This value indicates that the specific operation is not implemented.
- * This error should never happen. It can only occur if you use certain
- * values or configuration options which do not work, but for which we
- * think that they should work at some later time.}
- * _{GPGErrorReadError This value means that an I/O read operation failed.}
- * _{GPGErrorWriteError This value means that an I/O write operation failed.}
- * _{GPGErrorInvalidType This value means that a user provided object was of a wrong
- * or incompatible type. Usually this refers to the type of a #GPGData instance.}
- * _{GPGErrorInvalidMode This value means that a #GPGData instance has an
- * incorrect mode of operation (for example, doesn't support
- * output although it is attempted to use it as an output buffer).}
- * _{GPGErrorFileError This value means that a file I/O operation failed.
- * The value of #errno contains the system error value.}
- * _{GPGErrorDecryptionFailed This value indicates that a decryption operation was unsuccessful.}
- * _{GPGErrorNoPassphrase This value means that the user did not provide a passphrase when requested.}
- * _{GPGErrorCanceled This value means that the operation was canceled.}
- * _{GPGErrorInvalidKey This value means that a key was invalid.}
- * _{GPGErrorInvalidEngine This value means that the engine that implements the
- * desired protocol is currently not available. This can
- * either be because the sources were configured to exclude
- * support for this engine, or because the engine is not installed properly.}
- * _{GPGErrorInvalidRecipients This value means that some, but not all, recipients
- * for a message have been invalid.}
-"*/
-typedef enum {
- GPGErrorEOF = -1,
- GPGErrorNoError = 0,
- GPGErrorGeneralError = 1,
- GPGErrorOutOfCore = 2,
- GPGErrorInvalidValue = 3,
- GPGErrorBusy = 4,
- GPGErrorNoRequest = 5,
- GPGErrorExecError = 6,
- GPGErrorTooManyProcs = 7,
- GPGErrorPipeError = 8,
- GPGErrorNoRecipients = 9,
- GPGErrorNoData = 10,
- GPGErrorConflict = 11,
- GPGErrorNotImplemented = 12,
- GPGErrorReadError = 13,
- GPGErrorWriteError = 14,
- GPGErrorInvalidType = 15,
- GPGErrorInvalidMode = 16,
- GPGErrorFileError = 17,
- GPGErrorDecryptionFailed = 18,
- GPGErrorNoPassphrase = 19,
- GPGErrorCanceled = 20,
- GPGErrorInvalidKey = 21,
- GPGErrorInvalidEngine = 22,
- GPGErrorInvalidRecipients = 23
-} GPGError;
-
-
-/*"
- * The #GPGProtocol type specifies the set of possible protocol values that are supported by GPGME.
- * The following protocols are supported:
- * _{GPGOpenPGPProtocol Default protocol. OpenPGP is implemented by GnuPG, the GNU Privacy Guard.
- This is the first protocol that was supported by GPGME.}
- * _{GPGCMSProtocol CMS is implemented by GpgSM, the S/MIME implementation for GnuPG.
+ * The #GPGProtocol type specifies the set of possible protocol values that
+ * are supported by GPGME. The following protocols are supported:
+ * _{GPGOpenPGPProtocol Default protocol. OpenPGP is implemented by GnuPG,
+ * the GNU Privacy Guard. This is the first protocol
+ * that was supported by GPGME.}
+ * _{GPGCMSProtocol CMS (Cryptographic Message Syntax) is implemented by
+ * GpgSM, the S/MIME implementation for GnuPG.
* #CAUTION: currently unsupported on MacOS X.}
"*/
typedef enum {
- GPGOpenPGPProtocol = 0,
- GPGCMSProtocol = 1,
- GPGAutomaticProtocol = 2
+ GPGOpenPGPProtocol = 0,
+ GPGCMSProtocol = 1
} GPGProtocol;
-/*"
- * Checks that the version of the framework is at minimum the requested one
- * and returns the version string; returns nil if the condition is not
- * met or requiredVersion is not a valid version number.
- * If requiredVersion is nil, no check is done and
- * the version string is simply returned.
- *
- * Note that this check is automatically performed before any GPGME object/function
- * is used; it is called from #+[GPGObject initialize].
-"*/
-GPG_EXPORT NSString *GPGCheckVersion(NSString *requiredVersion);
+@interface GPGEngine : GPGObject /*"NSObject"*/
+{
+}
-/*"
- * #{OBSOLETE. Use GPGEngineCheckVersion().}
- *
- * Check whether the installed crypto engine for the OpenPGP protocol
- * matches the requirement of GPGME. This function is deprecated,
- * instead use #{GPGEngineCheckVersion()} with the specific protocol you
- * need.
-"*/
-GPG_EXPORT GPGError GPGCheckEngine();
++ (GPGError) checkVersionForProtocol:(GPGProtocol)protocol;
++ (NSString *) checkFrameworkVersion:(NSString *)requiredVersion;
-/*"
- * Checks that the engine implementing the protocol protocol is installed
- * in the expected path and meets the version requirement of GPGME.
- *
- * This function returns #GPGErrorNoError if the engine is available
- * and #GPGErrorInvalidEngine if it is not.
-"*/
-GPG_EXPORT GPGError GPGEngineCheckVersion(GPGProtocol protocol);
++ (NSArray *) availableEngines;
-/*"
- * Returns information about the underlying crypto engines. This is an
- * XML string with various information. To get the version of the
- * crypto engine it should be sufficient to grep for the first
- * version tag and use it's content. A string is
- * always returned even if the crypto engine is not installed; in this
- * case an XML string with some error information is returned.
- *
- * !{<EngineInfo>
- * <engine>
- * <protocol>aString</protocol> (the name of the protocol, OpenPGP or CMS)
- * <version>aString</version> (the version of the engine)
- * <path>aString</path> (the path to the engine binary)
- * </engine>
- * <engine> (optional, for additional engines)
- * <protocol>aString</protocol> (OpenPGP or CMS)
- * <version>aString</version>
- * <path>aString</path>
- * </engine>
- * </EngineInfo>}
- *
- * or
- *
- * !{<EngineInfo>
- * <engine>
- * <error>aString</error> (description of the failure)
- * <path>aString</path> (optional)
- * </engine>
- * </EngineInfo>}
-"*/
-GPG_EXPORT NSString *GPGEngineInfoAsXMLString();
+- (GPGProtocol) engineProtocol;
+- (NSString *) executablePath;
+- (NSString *) version;
+- (NSString *) requestedVersion;
-/*"
- * Returns the (yet unlocalized) description of the error value.
- * This string can be used to output a diagnostic message to the user.
-"*/
-GPG_EXPORT NSString *GPGErrorDescription(GPGError error);
+@end
#ifdef __cplusplus
}
Index: GPGEngine.m
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGEngine.m,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- GPGEngine.m 27 Sep 2003 14:27:24 -0000 1.5
+++ GPGEngine.m 23 Jan 2005 13:20:01 -0000 1.6
@@ -2,81 +2,158 @@
// GPGEngine.m
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#include <GPGME/GPGEngine.h>
#include <GPGME/GPGObject.h>
+#include <GPGME/GPGPrettyInfo.h>
+#include <GPGME/GPGInternals.h>
#include <Foundation/Foundation.h>
#include <gpgme.h>
-NSString *GPGCheckVersion(NSString *requiredVersion)
+#define _engine ((gpgme_engine_info_t)_internalRepresentation)
+
+
+@implementation GPGEngine
+/*"
+ * GPGME supports several cryptographic protocols, however, it does not
+ * implement them. Rather it uses backends (also called engines) which
+ * implement the protocol. GPGME uses inter-process communication to pass data
+ * back and forth between the application and the backend, but the details of
+ * the communication protocol and invocation of the backend is completely
+ * hidden by the interface. All complexity is handled by GPGME. Where an
+ * exchange of information between the application and the backend is
+ * necessary, GPGME provides the necessary callback method hooks and further
+ * interfaces.
+"*/
+
++ (GPGError) checkVersionForProtocol:(GPGProtocol)protocol
+/*"
+ * Checks that the engine implementing the protocol protocol is installed
+ * in the expected path and meets the version requirement of GPGME.
+ *
+ * This method returns #GPGErrorNoError if the engine
+ * is available and an error whose code is #GPGErrorInvalidEngine if it is not.
+"*/
+{
+ return gpgme_engine_check_version(protocol);
+}
+
++ (NSString *) checkFrameworkVersion:(NSString *)requiredVersion
+/*"
+ * Checks that the version of the framework is at minimum the requested one
+ * and returns the version string; returns nil if the condition is not met or
+ * requiredVersion is not a valid version number. If requiredVersion is nil,
+ * no check is done and the version string is simply returned.
+ *
+ * Note that this check is automatically performed before any GPGME
+ * object/function is used; it is called from #{+[GPGObject initialize]}.
+"*/
{
const char *aCString;
- NSString *aString = nil;
- [GPGObject initialize];
- aCString = gpgme_check_version(requiredVersion == nil ? NULL:[requiredVersion UTF8String]);
+ aCString = gpgme_check_version(requiredVersion == nil ? NULL:[requiredVersion UTF8String]); // statically allocated string or NULL
- if(aCString != NULL)
- aString = [NSString stringWithUTF8String:aCString];
-
- return aString;
+ return GPGStringFromChars(aCString);
}
-GPGError GPGCheckEngine()
++ (NSArray *) availableEngines
+/*"
+ * Returns an array of GPGEngine instances. Each instance describes one
+ * configured backend.
+"*/
{
- [GPGObject initialize];
+ gpgme_engine_info_t anEngine = NULL;
+ gpgme_error_t anError = gpgme_get_engine_info(&anEngine); // The memory for the info structures is allocated the first time this function is invoked, and must not be freed by the caller.
+ NSMutableArray *engines;
- return gpgme_check_engine();
+ if(anError != GPG_ERR_NO_ERROR)
+ [[NSException exceptionWithGPGError:anError userInfo:nil] raise];
+
+ engines = [NSMutableArray arrayWithCapacity:2];
+ while(anEngine != NULL){
+ GPGEngine *newEngine = [[GPGEngine alloc] initWithInternalRepresentation:anEngine];
+
+ [engines addObject:newEngine];
+ anEngine = anEngine->next;
+ [newEngine release];
+ }
+
+ return engines;
}
-GPGError GPGEngineCheckVersion(GPGProtocol protocol)
+- (GPGProtocol) engineProtocol
+/*"
+ * Returns the protocol for which the crypto engine is used. You can convert
+ * this to a string with #{GPGProtocolDescription()} or
+ * #{GPGLocalizedProtocolDescription()} for printing
+"*/
{
- [GPGObject initialize];
+ return _engine->protocol;
+}
- return gpgme_engine_check_version(protocol);
+- (NSString *) executablePath
+/*"
+ * Returns a string holding the file name of the executable of the crypto
+ * engine. Currently, it is never nil, but using nil is reserved for future
+ * use, so always check before you use it.
+"*/
+{
+ const char *aCString = _engine->file_name;
+
+ return GPGStringFromChars(aCString);
}
-NSString *GPGEngineInfoAsXMLString()
+- (NSString *) version
+/*"
+ * This is a string containing the version number of the crypto engine. It
+ * might be nil if the version number can not be determined, for example
+ * because the executable doesn't exist or is invalid.
+"*/
{
- const char *aCString;
- NSString *aString = nil;
+ const char *aCString = _engine->version;
- [GPGObject initialize];
- aCString = gpgme_get_engine_info();
- if(aCString != NULL)
- aString = [NSString stringWithUTF8String:aCString];
-
- return aString;
+ return GPGStringFromChars(aCString);
}
-NSString *GPGErrorDescription(GPGError error)
+- (NSString *) requestedVersion
+/*"
+ * Returns a string containing the minimum required version number of the
+ * crypto engine for GPGME to work correctly. This is the version number that
+ * #{+checkVersionForProtocol:} verifies against. Currently, it is never nil,
+ * but using nil is reserved for future use, so always check before you use it.
+"*/
{
- const char *aCString = gpgme_strerror(error);
- NSString *aString = nil;
+ const char *aCString = _engine->req_version;
- if(aCString != NULL)
- aString = [NSString stringWithUTF8String:aCString];
+ return GPGStringFromChars(aCString);
+}
- return aString;
+- (NSString *) debugDescription
+{
+ return [NSString stringWithFormat:@"<%@ %p> %@ %@ (%@), %@", NSStringFromClass([self class]), self, GPGProtocolDescription([self engineProtocol]), [self version], [self requestedVersion], [self executablePath]];
}
+
+@end
Index: GPGExceptions.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGExceptions.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- GPGExceptions.h 27 Sep 2003 14:27:24 -0000 1.5
+++ GPGExceptions.h 23 Jan 2005 13:20:01 -0000 1.6
@@ -2,25 +2,27 @@
// GPGExceptions.h
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGEXCEPTIONS_H
@@ -28,7 +30,6 @@
#include <Foundation/Foundation.h>
#include <GPGME/GPGDefines.h>
-#include <GPGME/GPGEngine.h>
#ifdef __cplusplus
extern "C" {
@@ -42,18 +43,609 @@
/*"
+ * The #GPGErrorCode type indicates the type of an error, or the reason why an
+ * operation failed. Here are the most important ones:
+ * _{GPGErrorEOF This value indicates the end of a
+ * list, buffer or file.}
+ * _{GPGErrorNoError This value indicates success. The
+ * value of this error code is 0. Also,
+ * it is guaranteed that an error value
+ * made from the error code 0 will be 0
+ * itself (as a whole). This means that
+ * the error source information is lost
+ * for this error code, however, as
+ * this error code indicates that no
+ * error occured, this is generally not
+ * a problem. No #GPGException is raised
+ * with this value.}
+ * _{GPGErrorGeneralError This value means that something went
+ * wrong, but either there is not enough
+ * information about the problem to
+ * return a more useful error value, or
+ * there is no separate error value for
+ * this type of problem.}
+ * _{GPGError_ENOMEM This value means that an
+ * out-of-memory condition occurred.}
+ * _{GPGError_E... System errors are mapped to
+ * GPGError_FOO where FOO is the symbol
+ * for the system error.}
+ * _{GPGErrorInvalidValue This value means that some user
+ * provided data was out of range.
+ * This can also refer to objects. For
+ * example, if an empty #GPGData
+ * instance was expected, but one
+ * containing data was provided, this
+ * error value is returned.}
+ * _{GPGErrorUnusablePublicKey This value means that some
+ * recipients for a message were
+ * invalid.}
+ * _{GPGErrorUnusableSecretKey This value means that some signers
+ * were invalid.}
+ * _{GPGErrorNoData This value means that a #GPGData
+ * instance which was expected to have
+ * content was found empty.}
+ * _{GPGErrorConflict This value means that a conflict of
+ * some sort occurred.}
+ * _{GPGErrorNotImplemented This value indicates that the
+ * specific function (or operation) is
+ * not implemented. This error should
+ * never happen. It can only occur if
+ * you use certain values or
+ * configuration options which do not
+ * work, but for which we think that
+ * they should work at some later
+ * time.}
+ * _{GPGErrorDecryptionFailed This value indicates that a
+ * decryption operation was
+ * unsuccessful.}
+ * _{GPGErrorBadPassphrase This value means that the user did
+ * not provide a correct passphrase
+ * when requested.}
+ * _{GPGErrorCancelled This value means that the operation
+ * was cancelled by user.}
+ * _{GPGErrorInvalidEngine This value means that the engine
+ * that implements the desired protocol
+ * is currently not available. This can
+ * either be because the sources were
+ * configured to exclude support for
+ * this engine, or because the engine
+ * is not installed properly.}
+ * _{GPGErrorAmbiguousName This value indicates that a user ID
+ * or other specifier did not specify a
+ * unique key.}
+ * _{GPGErrorWrongKeyUsage This value indicates that a key is
+ * not used appropriately.}
+ * _{GPGErrorCertificateRevoked This value indicates that a key
+ * signature was revoked.}
+ * _{GPGErrorCertificateExpired This value indicates that a key
+ * signature expired.}
+ * _{GPGErrorNoCRLKnown This value indicates that no
+ * certificate revocation list is known
+ * for the certificate.}
+ * _{GPGErrorNoPolicyMatch This value indicates that a policy
+ * issue occured.}
+ * _{GPGErrorNoSecretKey This value indicates that no secret
+ * key for the user ID is available.}
+ * _{GPGErrorInvalidPassphrase The passphrase is invalid, for
+ * example if it is in ISOLatin1
+ * although UTF-8 is expected}
+ * _{GPGErrorMissingCertificate This value indicates that a key
+ * could not be imported because the
+ * issuer certificate is missing.}
+ * _{GPGErrorBadCertificateChain This value indicates that a key
+ * could not be imported because its
+ * certificate chain is not good, for
+ * example it could be too long.}
+ * _{GPGErrorUnsupportedAlgorithm This value means a verification
+ * failed because the cryptographic
+ * algorithm is not supported by the
+ * crypto backend.}
+ * _{GPGErrorBadSignature This value means a verification
+ * failed because the signature is
+ * bad.}
+ * _{GPGErrorNoPublicKey This value means a verification
+ * failed because the public key is not
+ * available.}
+ * _{GPGErrorUser1-GPGErrorUser16 These error codes are not used by
+ * any GnuPG component and can be
+ * freely used by other software.
+ * Applications using GPGME might use
+ * them to mark specific errors
+ * returned by callback handlers if no
+ * suitable error codes (including the
+ * system errors) for these errors
+ * exist already.}
+"*/
+typedef enum {
+ GPGErrorNoError = 0,
+ GPGErrorGeneralError = 1,
+ GPGErrorUnknownPacket = 2,
+ GPGErrorUnknownVersion = 3,
+ GPGErrorInvalidPublicKeyAlgorithm = 4,
+ GPGErrorInvalidDigestAlgorithm = 5,
+ GPGErrorBadPublicKey = 6,
+ GPGErrorBadSecretKey = 7,
+ GPGErrorBadSignature = 8,
+ GPGErrorNoPublicKey = 9,
+ GPGErrorChecksumError = 10,
+ GPGErrorBadPassphrase = 11,
+ GPGErrorInvalidCipherAlgorithm = 12,
+ GPGErrorOpenKeyring = 13,
+ GPGErrorInvalidPacket = 14,
+ GPGErrorInvalidArmor = 15,
+ GPGErrorNoUserID = 16,
+ GPGErrorNoSecretKey = 17,
+ GPGErrorWrongSecretKey = 18,
+ GPGErrorBadSessionKey = 19,
+ GPGErrorUnknownCompressionAlgorithm = 20,
+ GPGErrorNoPrime = 21,
+ GPGErrorNoEncodingMethod = 22,
+ GPGErrorNoEncryptionScheme = 23,
+ GPGErrorNoSignatureScheme = 24,
+ GPGErrorInvalidAttribute = 25,
+ GPGErrorNoValue = 26,
+ GPGErrorNotFound = 27,
+ GPGErrorValueNotFound = 28,
+ GPGErrorSyntax = 29,
+ GPGErrorBadMPI = 30,
+ GPGErrorInvalidPassphrase = 31,
+ GPGErrorSignatureClass = 32,
+ GPGErrorResourceLimit = 33,
+ GPGErrorInvalidKeyring = 34,
+ GPGErrorTrustDBError = 35,
+ GPGErrorBadCertificate = 36,
+ GPGErrorInvalidUserID = 37,
+ GPGErrorUnexpected = 38,
+ GPGErrorTimeConflict = 39,
+ GPGErrorKeyServerError = 40,
+ GPGErrorWrongPublicKeyAlgorithm = 41,
+ GPGErrorTributeToDA = 42,
+ GPGErrorWeakKey = 43,
+ GPGErrorInvalidKeyLength = 44,
+ GPGErrorInvalidArgument = 45,
+ GPGErrorBadURI = 46,
+ GPGErrorInvalidURI = 47,
+ GPGErrorNetworkError = 48,
+ GPGErrorUnknownHost = 49,
+ GPGErrorSelfTestFailed = 50,
+ GPGErrorNotEncrypted = 51,
+ GPGErrorNotProcessed = 52,
+ GPGErrorUnusablePublicKey = 53,
+ GPGErrorUnusableSecretKey = 54,
+ GPGErrorInvalidValue = 55,
+ GPGErrorBadCertificateChain = 56,
+ GPGErrorMissingCertificate = 57,
+ GPGErrorNoData = 58,
+ GPGErrorBug = 59,
+ GPGErrorNotSupported = 60,
+ GPGErrorInvalidOperationCode = 61,
+ GPGErrorTimeout = 62,
+ GPGErrorInternalError = 63,
+ GPGErrorEOFInGCrypt = 64,
+ GPGErrorInvalidObject = 65,
+ GPGErrorObjectTooShort = 66,
+ GPGErrorObjectTooLarge = 67,
+ GPGErrorNoObject = 68,
+ GPGErrorNotImplemented = 69,
+ GPGErrorConflict = 70,
+ GPGErrorInvalidCipherMode = 71,
+ GPGErrorInvalidFlag = 72,
+ GPGErrorInvalidHandle = 73,
+ GPGErrorTruncatedResult = 74,
+ GPGErrorIncompleteLine = 75,
+ GPGErrorInvalidResponse = 76,
+ GPGErrorNoAgent = 77,
+ GPGErrorAgentError = 78,
+ GPGErrorInvalidData = 79,
+ GPGErrorAssuanServerFault = 80,
+ GPGErrorAssuanError = 81,
+ GPGErrorInvalidSessionKey = 82,
+ GPGErrorInvalidSEXP = 83,
+ GPGErrorUnsupportedAlgorithm = 84,
+ GPGErrorNoPINEntry = 85,
+ GPGErrorPINEntryError = 86,
+ GPGErrorBadPIN = 87,
+ GPGErrorInvalidName = 88,
+ GPGErrorBadData = 89,
+ GPGErrorInvalidParameter = 90,
+ GPGErrorWrongCard = 91,
+ GPGErrorNoDirManager = 92,
+ GPGErrorDirManagerError = 93,
+ GPGErrorCertificateRevoked = 94,
+ GPGErrorNoCRLKnown = 95,
+ GPGErrorCRLTooOld = 96,
+ GPGErrorLineTooLong = 97,
+ GPGErrorNotTrusted = 98,
+ GPGErrorCancelled = 99,
+ GPGErrorBadCACertificate = 100,
+ GPGErrorCertificateExpired = 101,
+ GPGErrorCertificateTooYoung = 102,
+ GPGErrorUnsupportedCertificate = 103,
+ GPGErrorUnknownSEXP = 104,
+ GPGErrorUnsupportedProtection = 105,
+ GPGErrorCorruptedProtection = 106,
+ GPGErrorAmbiguousName = 107,
+ GPGErrorCardError = 108,
+ GPGErrorCardReset = 109,
+ GPGErrorCardRemoved = 110,
+ GPGErrorInvalidCard = 111,
+ GPGErrorCardNotPresent = 112,
+ GPGErrorNoPKCS15Application = 113,
+ GPGErrorNotConfirmed = 114,
+ GPGErrorConfigurationError = 115,
+ GPGErrorNoPolicyMatch = 116,
+ GPGErrorInvalidIndex = 117,
+ GPGErrorInvalidID = 118,
+ GPGErrorNoSCDaemon = 119,
+ GPGErrorSCDaemonError = 120,
+ GPGErrorUnsupportedProtocol = 121,
+ GPGErrorBadPINMethod = 122,
+ GPGErrorCardNotInitialized = 123,
+ GPGErrorUnsupportedOperation = 124,
+ GPGErrorWrongKeyUsage = 125,
+ GPGErrorNothingFound = 126,
+ GPGErrorWrongBLOBType = 127,
+ GPGErrorMissingValue = 128,
+ GPGErrorHardware = 129,
+ GPGErrorPINBlocked = 130,
+ GPGErrorUseConditions = 131,
+ GPGErrorPINNotSynced = 132,
+ GPGErrorInvalidCRL = 133,
+ GPGErrorBadBER = 134,
+ GPGErrorInvalidBER = 135,
+ GPGErrorElementNotFound = 136,
+ GPGErrorIdentifierNotFound = 137,
+ GPGErrorInvalidTag = 138,
+ GPGErrorInvalidLength = 139,
+ GPGErrorInvalidKeyInfo = 140,
+ GPGErrorUnexpectedTag = 141,
+ GPGErrorNotDEREncoded = 142,
+ GPGErrorNoCMSObject = 143,
+ GPGErrorInvalidCMSObject = 144,
+ GPGErrorUnknownCMSObject = 145,
+ GPGErrorUnsupportedCMSObject = 146,
+ GPGErrorUnsupportedEncoding = 147,
+ GPGErrorUnsupportedCMSVersion = 148,
+ GPGErrorUnknownAlgorithm = 149,
+ GPGErrorInvalidEngine = 150,
+ GPGErrorPublicKeyNotTrusted = 151,
+ GPGErrorDecryptionFailed = 152,
+ GPGErrorKeyExpired = 153,
+ GPGErrorSignatureExpired = 154,
+ GPGErrorEncodingProblem = 155,
+ GPGErrorInvalidState = 156,
+ GPGErrorDuplicateValue = 157,
+ GPGErrorMissingAction = 158,
+ GPGErrorModuleNotFound = 159,
+ GPGErrorInvalidOIDString = 160,
+ GPGErrorInvalidTime = 161,
+ GPGErrorInvalidCRLObject = 162,
+ GPGErrorUnsupportedCRLVersion = 163,
+ GPGErrorInvalidCertObject = 164,
+ GPGErrorUnknownName = 165,
+ GPGErrorLocaleProblem = 166,
+ GPGErrorNotLocked = 167,
+ GPGErrorProtocolViolation = 168,
+ GPGErrorInvalidMac = 169,
+ GPGErrorInvalidRequest = 170,
+
+ GPGErrorBufferTooShort = 200,
+ GPGErrorSEXPInvalidLengthSpec = 201,
+ GPGErrorSEXPStringTooLong = 202,
+ GPGErrorSEXPUnmatchedParenthese = 203,
+ GPGErrorSEXPNotCanonical = 204,
+ GPGErrorSEXPBadCharacter = 205,
+ GPGErrorSEXPBadQuotation = 206,
+ GPGErrorSEXPZeroPrefix = 207,
+ GPGErrorSEXPNestedDisplayHint = 208,
+ GPGErrorSEXPUnmatchedDisplayHint = 209,
+ GPGErrorSEXPUnexpectedPunctuation = 210,
+ GPGErrorSEXPBadHexCharacter = 211,
+ GPGErrorSEXPOddHexNumbers = 212,
+ GPGErrorSEXPBadOctalCharacter = 213,
+
+ GPGErrorTruncatedKeyListing = 1024,
+ GPGErrorUser2 = 1025,
+ GPGErrorUser3 = 1026,
+ GPGErrorUser4 = 1027,
+ GPGErrorUser5 = 1028,
+ GPGErrorUser6 = 1029,
+ GPGErrorUser7 = 1030,
+ GPGErrorUser8 = 1031,
+ GPGErrorUser9 = 1032,
+ GPGErrorUser10 = 1033,
+ GPGErrorUser11 = 1034,
+ GPGErrorUser12 = 1035,
+ GPGErrorUser13 = 1036,
+ GPGErrorUser14 = 1037,
+ GPGErrorUser15 = 1038,
+ GPGErrorUser16 = 1039,
+
+ GPGErrorUnknownErrno = 16382,
+ GPGErrorEOF = 16383,
+
+ /* The following error codes are used to map system errors. */
+ GPGError_E2BIG = 16384,
+ GPGError_EACCES = 16385,
+ GPGError_EADDRINUSE = 16386,
+ GPGError_EADDRNOTAVAIL = 16387,
+ GPGError_EADV = 16388,
+ GPGError_EAFNOSUPPORT = 16389,
+ GPGError_EAGAIN = 16390,
+ GPGError_EALREADY = 16391,
+ GPGError_EAUTH = 16392,
+ GPGError_EBACKGROUND = 16393,
+ GPGError_EBADE = 16394,
+ GPGError_EBADF = 16395,
+ GPGError_EBADFD = 16396,
+ GPGError_EBADMSG = 16397,
+ GPGError_EBADR = 16398,
+ GPGError_EBADRPC = 16399,
+ GPGError_EBADRQC = 16400,
+ GPGError_EBADSLT = 16401,
+ GPGError_EBFONT = 16402,
+ GPGError_EBUSY = 16403,
+ GPGError_ECANCELLED = 16404,
+ GPGError_ECHILD = 16405,
+ GPGError_ECHRNG = 16406,
+ GPGError_ECOMM = 16407,
+ GPGError_ECONNABORTED = 16408,
+ GPGError_ECONNREFUSED = 16409,
+ GPGError_ECONNRESET = 16410,
+ GPGError_ED = 16411,
+ GPGError_EDEADLK = 16412,
+ GPGError_EDEADLOCK = 16413,
+ GPGError_EDESTADDRREQ = 16414,
+ GPGError_EDIED = 16415,
+ GPGError_EDOM = 16416,
+ GPGError_EDOTDOT = 16417,
+ GPGError_EDQUOT = 16418,
+ GPGError_EEXIST = 16419,
+ GPGError_EFAULT = 16420,
+ GPGError_EFBIG = 16421,
+ GPGError_EFTYPE = 16422,
+ GPGError_EGRATUITOUS = 16423,
+ GPGError_EGREGIOUS = 16424,
+ GPGError_EHOSTDOWN = 16425,
+ GPGError_EHOSTUNREACH = 16426,
+ GPGError_EIDRM = 16427,
+ GPGError_EIEIO = 16428,
+ GPGError_EILSEQ = 16429,
+ GPGError_EINPROGRESS = 16430,
+ GPGError_EINTR = 16431,
+ GPGError_EINVAL = 16432,
+ GPGError_EIO = 16433,
+ GPGError_EISCONN = 16434,
+ GPGError_EISDIR = 16435,
+ GPGError_EISNAM = 16436,
+ GPGError_EL2HLT = 16437,
+ GPGError_EL2NSYNC = 16438,
+ GPGError_EL3HLT = 16439,
+ GPGError_EL3RST = 16440,
+ GPGError_ELIBACC = 16441,
+ GPGError_ELIBBAD = 16442,
+ GPGError_ELIBEXEC = 16443,
+ GPGError_ELIBMAX = 16444,
+ GPGError_ELIBSCN = 16445,
+ GPGError_ELNRNG = 16446,
+ GPGError_ELOOP = 16447,
+ GPGError_EMEDIUMTYPE = 16448,
+ GPGError_EMFILE = 16449,
+ GPGError_EMLINK = 16450,
+ GPGError_EMSGSIZE = 16451,
+ GPGError_EMULTIHOP = 16452,
+ GPGError_ENAMETOOLONG = 16453,
+ GPGError_ENAVAIL = 16454,
+ GPGError_ENEEDAUTH = 16455,
+ GPGError_ENETDOWN = 16456,
+ GPGError_ENETRESET = 16457,
+ GPGError_ENETUNREACH = 16458,
+ GPGError_ENFILE = 16459,
+ GPGError_ENOANO = 16460,
+ GPGError_ENOBUFS = 16461,
+ GPGError_ENOCSI = 16462,
+ GPGError_ENODATA = 16463,
+ GPGError_ENODEV = 16464,
+ GPGError_ENOENT = 16465,
+ GPGError_ENOEXEC = 16466,
+ GPGError_ENOLCK = 16467,
+ GPGError_ENOLINK = 16468,
+ GPGError_ENOMEDIUM = 16469,
+ GPGError_ENOMEM = 16470,
+ GPGError_ENOMSG = 16471,
+ GPGError_ENONET = 16472,
+ GPGError_ENOPKG = 16473,
+ GPGError_ENOPROTOOPT = 16474,
+ GPGError_ENOSPC = 16475,
+ GPGError_ENOSR = 16476,
+ GPGError_ENOSTR = 16477,
+ GPGError_ENOSYS = 16478,
+ GPGError_ENOTBLK = 16479,
+ GPGError_ENOTCONN = 16480,
+ GPGError_ENOTDIR = 16481,
+ GPGError_ENOTEMPTY = 16482,
+ GPGError_ENOTNAM = 16483,
+ GPGError_ENOTSOCK = 16484,
+ GPGError_ENOTSUP = 16485,
+ GPGError_ENOTTY = 16486,
+ GPGError_ENOTUNIQ = 16487,
+ GPGError_ENXIO = 16488,
+ GPGError_EOPNOTSUPP = 16489,
+ GPGError_EOVERFLOW = 16490,
+ GPGError_EPERM = 16491,
+ GPGError_EPFNOSUPPORT = 16492,
+ GPGError_EPIPE = 16493,
+ GPGError_EPROCLIM = 16494,
+ GPGError_EPROCUNAVAIL = 16495,
+ GPGError_EPROGMISMATCH = 16496,
+ GPGError_EPROGUNAVAIL = 16497,
+ GPGError_EPROTO = 16498,
+ GPGError_EPROTONOSUPPORT = 16499,
+ GPGError_EPROTOTYPE = 16500,
+ GPGError_ERANGE = 16501,
+ GPGError_EREMCHG = 16502,
+ GPGError_EREMOTE = 16503,
+ GPGError_EREMOTEIO = 16504,
+ GPGError_ERESTART = 16505,
+ GPGError_EROFS = 16506,
+ GPGError_ERPCMISMATCH = 16507,
+ GPGError_ESHUTDOWN = 16508,
+ GPGError_ESOCKTNOSUPPORT = 16509,
+ GPGError_ESPIPE = 16510,
+ GPGError_ESRCH = 16511,
+ GPGError_ESRMNT = 16512,
+ GPGError_ESTALE = 16513,
+ GPGError_ESTRPIPE = 16514,
+ GPGError_ETIME = 16515,
+ GPGError_ETIMEDOUT = 16516,
+ GPGError_ETOOMANYREFS = 16517,
+ GPGError_ETXTBSY = 16518,
+ GPGError_EUCLEAN = 16519,
+ GPGError_EUNATCH = 16520,
+ GPGError_EUSERS = 16521,
+ GPGError_EWOULDBLOCK = 16522,
+ GPGError_EXDEV = 16523,
+ GPGError_EXFULL = 16524,
+
+ /* This is one more than the largest allowed entry. */
+ GPGError_CODE_DIM = 65536
+} GPGErrorCode;
+
+
+/*"
+ * The #GPGErrorSource type defines the different sources of errors/exceptions
+ * used in GPGME. The error source has not a precisely defined meaning.
+ * Sometimes it is the place where the error happened, sometimes it is the
+ * place where an error was encoded into an error value. Usually the error
+ * source will give an indication to where to look for the problem. This is
+ * not always true, but it is attempted to achieve this goal.
+ * _{GPG_UnknownErrorSource Unknown error source}
+ * _{GPG_GCryptErrorSource Error comes from C library %gcrypt, which
+ * is used by crypto engines to perform
+ * cryptographic operations}
+ * _{GPG_GPGErrorSource Error comes from %GnuPG, which is the
+ * crypto engine used for the OpenPGP
+ * protocol}
+ * _{GPG_GPGSMErrorSource Error comes from %GPGSM, which is the
+ * crypto engine used for the CMS protocol}
+ * _{GPG_GPGAgentErrorSource Error comes from %gpg-agent, which is used
+ * by crypto engines to perform operations
+ * with the secret key}
+ * _{GPG_PINEntryErrorSource Error comes from %pinentry, which is used
+ * by %gpg-agent to query the passphrase to
+ * unlock a secret key}
+ * _{GPG_SCDErrorSource Error comes from the %{SmartCard Daemon},
+ * which is used by %gpg-agent to delegate
+ * operations with the secret key to a
+ * %SmartCard}
+ * _{GPG_GPGMELibErrorSource Error comes from C library %gpgme}
+ * _{GPG_KeyBoxErrorSource Error comes from %libkbx, a library used
+ * by the crypto engines to manage local
+ * key-rings}
+ * _{GPG_KSBAErrorSource Error comes from C library %libksba}
+ * _{GPG_DirMngrErrorSource Error comes from %DirMngr}
+ * _{GPG_GSTIErrorSource Error comes from %GSTI}
+ * _{GPG_GPGMEFrameworkErrorSource Error comes from GPGME framework}
+ * _{GPG_User2ErrorSource (reserved)}
+ * _{GPG_User3ErrorSource (reserved)}
+ * _{GPG_User4ErrorSource (reserved)}
+ * Any other value smaller than 256 can be used for your own purpose.
+"*/
+typedef enum {
+ GPG_UnknownErrorSource = 0,
+ GPG_GCryptErrorSource = 1,
+ GPG_GPGErrorSource = 2,
+ GPG_GPGSMErrorSource = 3,
+ GPG_GPGAgentErrorSource = 4,
+ GPG_PINEntryErrorSource = 5,
+ GPG_SCDErrorSource = 6,
+ GPG_GPGMELibErrorSource = 7,
+ GPG_KeyBoxErrorSource = 8,
+ GPG_KSBAErrorSource = 9,
+ GPG_DirMngrErrorSource = 10,
+ GPG_GSTIErrorSource = 11,
+ GPG_GPGMEFrameworkErrorSource = 32,
+ GPG_User2ErrorSource = 33,
+ GPG_User3ErrorSource = 34,
+ GPG_User4ErrorSource = 35
+}GPGErrorSource;
+
+
+/*"
+ * An error value like this has always two components, an error code and an
+ * error source. Both together form the error value.
+ *
+ * Thus, the error value can not be directly compared against an error code,
+ * but the accessor functions #{GPGErrorSourceFromError()} and
+ * #{GPGErrorCodeFromError()} must be used. However, it is guaranteed that
+ * only 0 is used to indicate success (GPGErrorNoError), and that in this case
+ * all other parts of the error value are set to 0, too.
+ *
+ * Note that in GPGME, the error source is used purely for diagnostical
+ * purposes. Only the error code should be checked to test for a certain
+ * outcome of a function. The manual only documents the error code part of an
+ * error value. The error source is left unspecified and might be anything.
+"*/
+typedef unsigned int GPGError;
+
+/*"
+ * Returns the (yet unlocalized) description of the error value (code).
+ * This string can be used to output a diagnostic message to the user.
+"*/
+GPG_EXPORT NSString *GPGErrorDescription(GPGError error);
+
+
+/*"
+ * Returns the (yet unlocalized) name of the source of the error.
+ * This string can be used to output a diagnostic message to the user.
+"*/
+GPG_EXPORT NSString *GPGErrorSourceDescription(GPGErrorSource errorSource);
+
+/*"
+ * Returns the GPGErrorCode component of the error value err. This function
+ * must be used to extract the error code from an error value in order to
+ * compare it with the GPGError* error code values.
+"*/
+GPG_EXPORT GPGErrorCode GPGErrorCodeFromError(GPGError err);
+
+/*"
+ * Returns the GPGErrorSource component of the error value err. This function
+ * must be used to extract the error source from an error value in order to
+ * compare it with the GPG_*Source error source values.
+"*/
+GPG_EXPORT GPGErrorSource GPGErrorSourceFromError(GPGError err);
+
+/*"
+ * Returns the error value consisting of the error source src and the error
+ * code cde.
+ *
+ * This function can be used in callback methods to construct an error value
+ * to return it to the framework.
+"*/
+GPG_EXPORT GPGError GPGMakeError(GPGErrorSource src, GPGErrorCode cde);
+
+/*"
+ * The function #{GPGMakeErrorFromErrno()} is like #{GPGMakeError()}, but it
+ * takes a system error like errno instead of a #GPGErrorCode error code.
+"*/
+GPG_EXPORT GPGError GPGMakeErrorFromErrno(GPGErrorSource src, int cde);
+
+/*"
* A #GPGException can be raised by nearly any GPGME call...
*
* Reason: description of #GPGError.
*
* UserInfo:
- * _{GPGErrorCodeKey A #NSNumber containing a #GPGError value}
- * _{GPGErrnoKey A #NSNumber containing %errno; present only if #GPGError = #GPGErrorFileError}
- * _{GPGContextKey The #GPGContext which terminated with an error; used only by #{+[GPGContext waitOnAnyRequest:]}}
+ * _{GPGErrorKey A #NSNumber containing a #GPGError value}
+ * _{GPGContextKey The #GPGContext which terminated with an error;
+ * used by #{+[GPGContext waitOnAnyRequest:]} and
+ * for errors on asynchronous operations}
+ * _{GPGAdditionalReasonKey An additional unlocalized error message;
+ * optional}
"*/
GPG_EXPORT NSString * const GPGException;
-GPG_EXPORT NSString * const GPGErrorCodeKey;
-GPG_EXPORT NSString * const GPGErrnoKey;
+GPG_EXPORT NSString * const GPGErrorKey;
+GPG_EXPORT NSString * const GPGAdditionalReasonKey;
@interface NSException(GPGExceptions)
Index: GPGExceptions.m
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGExceptions.m,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- GPGExceptions.m 27 Sep 2003 14:27:24 -0000 1.5
+++ GPGExceptions.m 23 Jan 2005 13:20:02 -0000 1.6
@@ -2,61 +2,112 @@
// GPGExceptions.m
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#include <GPGME/GPGExceptions.h>
+#include <GPGME/GPGInternals.h>
#include <Foundation/Foundation.h>
#include <gpgme.h>
NSString * const GPGException = @"GPGException";
-NSString * const GPGErrorCodeKey = @"GPGErrorCodeKey";
-NSString * const GPGErrnoKey = @"GPGErrnoKey";
+NSString * const GPGErrorKey = @"GPGErrorKey";
+NSString * const GPGAdditionalReasonKey = @"GPGAdditionalReasonKey";
+
+
+GPGErrorCode GPGErrorCodeFromError(GPGError error)
+{
+ return gpgme_err_code(error);
+}
+
+GPGErrorSource GPGErrorSourceFromError(GPGError error)
+{
+ return gpgme_err_source(error);
+}
+
+GPGError GPGMakeError(GPGErrorSource src, GPGErrorCode cde)
+{
+ return gpgme_err_make(src, cde);
+}
+
+GPGError GPGMakeErrorFromErrno(GPGErrorSource src, int cde)
+{
+ return gpgme_err_make_from_errno(src, cde);
+}
+
+NSString *GPGErrorDescription(GPGError error)
+{
+ const size_t bufferIncrement = 128;
+ size_t bufferSize = 128;
+ NSZone *aZone = NSDefaultMallocZone();
+ char *buffer = NSZoneMalloc(aZone, bufferSize);
+ int status;
+ NSString *errorDescription;
+
+ do{
+ status = gpgme_strerror_r(error, buffer, bufferSize);
+ if(status == ERANGE)
+ buffer = NSZoneRealloc(aZone, buffer, (bufferSize += bufferIncrement));
+ }while(status != ERANGE && status != 0);
+
+ NSCAssert(buffer != NULL, @"### Unable to get memory buffer!?");
+
+ errorDescription = GPGStringFromChars(buffer);
+ NSZoneFree(aZone, buffer);
+
+ return errorDescription;
+}
+
+NSString *GPGErrorSourceDescription(GPGErrorSource errorSource)
+{
+ const char *aCString = gpgme_strsource(errorSource);
+
+ return GPGStringFromChars(aCString);
+}
@implementation NSException(GPGExceptions)
+ (NSException *) exceptionWithGPGError:(GPGError)error userInfo:(NSDictionary *)additionalUserInfo
/*"
- * Returns a new NSException instance with name #GPGException,
+ * Returns a new #NSException instance with name #GPGException,
* reason defined as #GPGErrorDescription(error),
- * and userInfo dictionary filled with #GPGErrorCodeKey = error,
- * #GPGErrnoKey = %errno (if error == #GPGErrorFileError), and additional userInfo.
+ * and userInfo dictionary filled with #GPGErrorKey = error
+ * and additional userInfo.
*
- * Used internally by the GPGME framework.
+ * Used internally by the GPGME framework, or by delegates.
"*/
{
- NSParameterAssert(error != GPGME_No_Error);
-
+ NSParameterAssert(error != GPG_ERR_NO_ERROR);
+
if(additionalUserInfo != nil){
additionalUserInfo = [NSMutableDictionary dictionaryWithDictionary:additionalUserInfo];
- [(NSMutableDictionary *)additionalUserInfo setObject:[NSNumber numberWithInt:error] forKey:GPGErrorCodeKey];
+ [(NSMutableDictionary *)additionalUserInfo setObject:[NSNumber numberWithUnsignedInt:error] forKey:GPGErrorKey];
}
else
- additionalUserInfo = [NSMutableDictionary dictionaryWithObject:[NSNumber numberWithInt:error] forKey:GPGErrorCodeKey];
+ additionalUserInfo = [NSMutableDictionary dictionaryWithObject:[NSNumber numberWithUnsignedInt:error] forKey:GPGErrorKey];
- if(error == GPGME_File_Error)
- [(NSMutableDictionary *)additionalUserInfo setObject:[NSNumber numberWithInt:errno] forKey:GPGErrnoKey];
-
return [NSException exceptionWithName:GPGException reason:GPGErrorDescription(error) userInfo:additionalUserInfo];
}
Index: GPGInternals.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGInternals.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- GPGInternals.h 27 Sep 2003 14:27:24 -0000 1.7
+++ GPGInternals.h 23 Jan 2005 13:20:02 -0000 1.8
@@ -2,25 +2,27 @@
// GPGInternals.h
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGINTERNALS_H
@@ -29,8 +31,11 @@
#include <GPGME/GPGContext.h>
#include <GPGME/GPGData.h>
#include <GPGME/GPGKey.h>
-#include <GPGME/GPGRecipients.h>
+#include <GPGME/GPGKeySignature.h>
+#include <GPGME/GPGUserID.h>
+#include <GPGME/GPGSubkey.h>
#include <GPGME/GPGDefines.h>
+#include <GPGME/GPGKeyGroup.h>
#include <gpgme.h>
#ifdef __cplusplus
@@ -42,27 +47,48 @@
@interface GPGContext(GPGInternals)
-- (GpgmeCtx) gpgmeContext;
+- (gpgme_ctx_t) gpgmeContext;
+- (void) setOperationMask:(int)flags;
+- (NSMutableDictionary *) operationData;
@end
@interface GPGData(GPGInternals)
-- (GpgmeData) gpgmeData;
+- (gpgme_data_t) gpgmeData;
@end
@interface GPGKey(GPGInternals)
-- (GpgmeKey) gpgmeKey;
+- (gpgme_key_t) gpgmeKey;
++ (BOOL) usesReferencesCount;
+- (GPGPublicKeyAlgorithm) algorithmFromName:(NSString *)name;
@end
-@... GPGRecipients(GPGInternals)
-- (GpgmeRecipients) gpgmeRecipients;
+@interface GPGSignature(GPGInternals)
+- (id) initWithSignature:(gpgme_signature_t)signature;
+- (id) initWithNewSignature:(gpgme_new_signature_t)signature;
@end
-@... GPGSignature(GPGInternals)
-- (id) initWithContext:(GPGContext *)ctx index:(unsigned)index;
+@interface GPGKeySignature(GPGInternals)
+- (id) initWithKeySignature:(gpgme_key_sig_t)keySignature userID:(GPGUserID *)userID;
+@end
+
+
+@interface GPGUserID(GPGInternals)
+- (id) initWithInternalRepresentation:(void *)aPtr key:(GPGKey *)key;
+- (NSDictionary *) dictionaryRepresentation;
+@end
+
+
+@interface GPGSubkey(GPGInternals)
+- (id) initWithInternalRepresentation:(void *)aPtr key:(GPGKey *)key;
+- (NSDictionary *) dictionaryRepresentation;
+@end
+
+@interface GPGKeyGroup(GPGInternals)
+- (id) initWithName:(NSString *)name keys:(NSArray *)keys;
@end
GPG_EXPORT NSString *GPGStringFromChars(const char * chars);
Index: GPGKey.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGKey.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- GPGKey.h 27 Sep 2003 14:27:24 -0000 1.19
+++ GPGKey.h 23 Jan 2005 13:20:02 -0000 1.20
@@ -2,32 +2,35 @@
// GPGKey.h
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGKEY_H
#define GPGKEY_H
#include <GPGME/GPGObject.h>
-#include <GPGME/GPGRecipients.h>
+#include <GPGME/GPGEngine.h>
+#include <GPGME/GPGContext.h>
#ifdef __cplusplus
extern "C" {
@@ -39,35 +42,60 @@
@class NSArray;
@class NSCalendarDate;
+@class NSData;
@class NSDictionary;
@class NSEnumerator;
@class NSString;
/*"
- * Values returned by #-type
- * _{GPG_PGPKey PGP key}
- * _{GPG_X509Key X.509 key}
+ * The #GPGValidity type is used to specify the validity of a %{user ID} in a
+ * key, or for a #GPGTrustItem instance. The following validities are defined:
+ * _{GPGValidityUnknown The %{user ID} is of unknown validity [?].}
+ * _{GPGValidityUndefined No value assigned. The validity of the %{user ID}
+ * is undefined [q].}
+ * _{GPGValidityNever The %{user ID} is never valid [n].}
+ * _{GPGValidityMarginal The %{user ID} is marginally valid [m].}
+ * _{GPGValidityFull The %{user ID} is fully valid [f].}
+ * _{GPGValidityUltimate The %{user ID} is ultimately valid [u]. Only used
+ * for keys for which the secret key is also
+ * available.}
+ *
+ * Don't assume that higher value means higher validity; this might change in the future.
"*/
typedef enum {
- GPG_PGPKey = 0,
- GPG_X509Key = 1
-}GPGKeyType;
+ GPGValidityUnknown = 0,
+ GPGValidityUndefined = 1,
+ GPGValidityNever = 2,
+ GPGValidityMarginal = 3,
+ GPGValidityFull = 4,
+ GPGValidityUltimate = 5
+} GPGValidity;
/*"
* Algorithm numerical values (taken from OpenPGP, RFC2440)
"*/
/*"
- * Public key algorithms
- * _{GPG_RSAAlgorithm Encrypt or Sign.}
- * _{GPG_RSAEncryptOnlyAlgorithm aka RSA-E.}
- * _{GPG_RSASignOnlyAlgorithm aka RSA-S.}
- * _{GPG_ElgamalEncryptOnlyAlgorithm aka Elgamal-E.}
- * _{GPG_DSAAlgorithm Digital Signature Standard.}
+ * Public key algorithms are used for encryption, decryption, signing and
+ * verification of signatures. You can convert the numerical values to strings
+ * with #{GPGPublicKeyAlgorithmDescription()} and
+ * #{GPGLocalizedPublicKeyAlgorithmDescription()} for printing.
+ * _{GPG_RSAAlgorithm RSA (Rivest, Shamir, Adleman) algorithm.}
+ * _{GPG_RSAEncryptOnlyAlgorithm %Deprecated.
+ * RSA (Rivest, Shamir, Adleman) algorithm
+ * for encryption and decryption only
+ * (aka RSA-E).}
+ * _{GPG_RSASignOnlyAlgorithm %Deprecated.
+ * RSA (Rivest, Shamir, Adleman) algorithm
+ * for signing and verification only
+ * (aka RSA-S).}
+ * _{GPG_ElgamalEncryptOnlyAlgorithm Elgamal (aka Elgamal-E);
+ * used specifically in GnuPG.}
+ * _{GPG_DSAAlgorithm Digital Signature Algorithm.}
* _{GPG_EllipticCurveAlgorithm .}
* _{GPG_ECDSAAlgorithm .}
- * _{GPG_ElgamalAlgorithm .}
+ * _{GPG_ElgamalAlgorithm Elgamal.}
* _{GPG_DiffieHellmanAlgorithm Encrypt or Sign.}
"*/
typedef enum {
@@ -120,6 +148,7 @@
/*"
* Hash algorithms
+ * _{GPG_NoHashAlgorithm .}
* _{GPG_MD5HashAlgorithm .}
* _{GPG_SHA_1HashAlgorithm [SHA1].}
* _{GPG_RIPE_MD160HashAlgorithm [RIPEMD160]}
@@ -127,15 +156,30 @@
* _{GPG_MD2HashAlgorithm .}
* _{GPG_TIGER192HashAlgorithm .}
* _{GPG_HAVALHashAlgorithm 5 pass, 160 bit.}
+ * _{GPG_SHA256HashAlgorithm .}
+ * _{GPG_SHA384HashAlgorithm .}
+ * _{GPG_SHA512HashAlgorithm .}
+ * _{GPG_MD4HashAlgorithm .}
+ * _{GPG_CRC32HashAlgorithm .}
+ * _{GPG_CRC32RFC1510HashAlgorithm .}
+ * _{GPG_CRC32RFC2440HashAlgorithm .}
"*/
typedef enum {
- GPG_MD5HashAlgorithm = 1,
- GPG_SHA_1HashAlgorithm = 2,
- GPG_RIPE_MD160HashAlgorithm = 3,
- GPG_DoubleWidthSHAHashAlgorithm = 4,
- GPG_MD2HashAlgorithm = 5,
- GPG_TIGER192HashAlgorithm = 6,
- GPG_HAVALHashAlgorithm = 7 // 5 pass, 160 bit
+ GPG_NoHashAlgorithm = 0,
+ GPG_MD5HashAlgorithm = 1,
+ GPG_SHA_1HashAlgorithm = 2,
+ GPG_RIPE_MD160HashAlgorithm = 3,
+ GPG_DoubleWidthSHAHashAlgorithm = 4,
+ GPG_MD2HashAlgorithm = 5,
+ GPG_TIGER192HashAlgorithm = 6,
+ GPG_HAVALHashAlgorithm = 7,
+ GPG_SHA256HashAlgorithm = 8,
+ GPG_SHA384HashAlgorithm = 9,
+ GPG_SHA512HashAlgorithm = 10,
+ GPG_MD4HashAlgorithm = 301,
+ GPG_CRC32HashAlgorithm = 302,
+ GPG_CRC32RFC1510HashAlgorithm = 303,
+ GPG_CRC24RFC2440HashAlgorithm = 304,
}GPGHashAlgorithm;
@@ -154,10 +198,15 @@
@interface GPGKey : GPGObject <NSCopying> /*"NSObject"*/
{
+ NSArray *_subkeys; /*"Array containing GPGSubkey instances"*/
+ NSArray *_userIDs; /*"Array containing GPGUserID instances"*/
+ NSData *_photoData;
+ BOOL _checkedPhotoData;
}
- (unsigned) hash;
- (BOOL) isEqual:(id)anObject;
++ (NSString *) formattedFingerprint:(NSString *)fingerprint;
/*"
* Public and secret keys
@@ -168,11 +217,7 @@
/*"
* Description
"*/
-- (NSString *) descriptionAsXMLString;
- (NSDictionary *) dictionaryRepresentation;
-+ (NSString *) algorithmDescription: (GPGPublicKeyAlgorithm)value;
-+ (NSString *) validityDescription: (GPGValidity)value;
-+ (NSString *) ownerTrustDescription: (GPGValidity)value;
/*"
* Global key capabilities
@@ -180,6 +225,7 @@
- (BOOL) canEncrypt;
- (BOOL) canSign;
- (BOOL) canCertify;
+- (BOOL) canAuthenticate;
/*"
* Main key
@@ -197,10 +243,7 @@
- (BOOL) isKeyInvalid;
- (BOOL) hasKeyExpired;
- (BOOL) isKeyDisabled;
-- (BOOL) hasSecretPart;
-- (BOOL) mainKeyCanEncrypt;
-- (BOOL) mainKeyCanSign;
-- (BOOL) mainKeyCanCertify;
+- (BOOL) isSecret;
- (GPGValidity) ownerTrust;
- (NSString *) ownerTrustDescription;
- (NSString *) issuerSerial;
@@ -208,27 +251,12 @@
- (NSString *) chainID;
/*"
- * Sub keys
+ * All subkeys
"*/
-- (NSArray *) subkeysShortKeyIDs;
-- (NSArray *) subkeysKeyIDs;
-- (NSArray *) subkeysFingerprints;
-- (NSArray *) subkeysFormattedFingerprints;
-- (NSArray *) subkeysAlgorithms;
-- (NSArray *) subkeysAlgorithmDescriptions;
-- (NSArray *) subkeysLengths;
-- (NSArray *) subkeysCreationDates;
-- (NSArray *) subkeysExpirationDates;
-- (NSArray *) subkeysRevocationStatuses;
-- (NSArray *) subkeysValidityStatuses;
-- (NSArray *) subkeysExpirationStatuses;
-- (NSArray *) subkeysActivityStatuses;
-- (NSArray *) subkeysEncryptionCapabilities;
-- (NSArray *) subkeysSigningCapabilities;
-- (NSArray *) subkeysCertificationCapabilities;
+- (NSArray *) subkeys;
/*"
- * Primary user ID
+ * Primary user ID information
"*/
- (NSString *) userID;
- (NSString *) name;
@@ -236,26 +264,23 @@
- (NSString *) comment;
- (GPGValidity) validity;
- (NSString *) validityDescription;
-- (BOOL) isPrimaryUserIDRevoked;
-- (BOOL) isPrimaryUserIDInvalid;
/*"
* All user IDs
"*/
- (NSArray *) userIDs;
-- (NSArray *) names;
-- (NSArray *) emails;
-- (NSArray *) comments;
-- (NSArray *) validities;
-- (NSArray *) validityDescriptions;
-- (NSArray *) userIDsRevocationStatuses;
-- (NSArray *) userIDsValidityStatuses;
/*"
- * Key type
+ * Supported protocol
"*/
-- (GPGKeyType) type;
-- (NSString *) typeDescription;
+- (GPGProtocol) supportedProtocol;
+- (NSString *) supportedProtocolDescription;
+
+/*"
+ * Other key attributes
+"*/
+- (NSData *) photoData;
+- (GPGKeyListMode) keyListMode;
@end
Index: GPGKey.m
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGKey.m,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- GPGKey.m 27 Sep 2003 14:27:24 -0000 1.25
+++ GPGKey.m 23 Jan 2005 13:20:02 -0000 1.26
@@ -2,25 +2,27 @@
// GPGKey.m
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code is free software; you can redistribute it and/or modify it under
[...1526 lines suppressed...]
+ algoForNameDict = [[NSDictionary alloc] initWithObjectsAndKeys:
+ [NSNumber numberWithInt:GPG_RSAAlgorithm], @"RSA", // OK
+ [NSNumber numberWithInt:GPG_RSAEncryptOnlyAlgorithm], @"RSA-S",
+ [NSNumber numberWithInt:GPG_RSASignOnlyAlgorithm], @"RSA-E",
+ [NSNumber numberWithInt:GPG_ElgamalEncryptOnlyAlgorithm], @"ELG-E", // OK
+ [NSNumber numberWithInt:GPG_DSAAlgorithm], @"DSA", // OK
+ [NSNumber numberWithInt:GPG_DSAAlgorithm], @"DSS/DH", // OK; there are 2 names, but it's very complicated; google ("DSS/DH" DSA) to learn more
+ [NSNumber numberWithInt:GPG_EllipticCurveAlgorithm], @"Elliptic",
+ [NSNumber numberWithInt:GPG_ECDSAAlgorithm], @"ECDSA",
+ [NSNumber numberWithInt:GPG_ElgamalAlgorithm], @"ELG",
+ [NSNumber numberWithInt:GPG_DiffieHellmanAlgorithm], @"DH", nil];
+
+ aNumber = [algoForNameDict objectForKey:name];
+ if(aNumber == nil)
+ return -1;
+ else
+ return [aNumber intValue];
+}
+
@end
Index: GPGME.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGME.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- GPGME.h 27 Sep 2003 14:27:24 -0000 1.5
+++ GPGME.h 23 Jan 2005 13:20:02 -0000 1.6
@@ -2,29 +2,31 @@
// GPGME.h
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
-#ifndef GPGME_H
-#define GPGME_H
+#ifndef GPGME_FRAMEWORK_H
+#define GPGME_FRAMEWORK_H
#include <Foundation/Foundation.h>
@@ -34,10 +36,14 @@
#include <GPGME/GPGEngine.h>
#include <GPGME/GPGExceptions.h>
#include <GPGME/GPGKey.h>
+#include <GPGME/GPGKeyGroup.h>
+#include <GPGME/GPGKeySignature.h>
#include <GPGME/GPGObject.h>
-#include <GPGME/GPGRecipients.h>
+#include <GPGME/GPGOptions.h>
#include <GPGME/GPGSignature.h>
+#include <GPGME/GPGSubkey.h>
#include <GPGME/GPGTrustItem.h>
+#include <GPGME/GPGUserID.h>
#include <GPGME/GPGPrettyInfo.h>
-#endif /* GPGME_H */
+#endif /* GPGME_FRAMEWORK_H */
Index: GPGObject.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGObject.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- GPGObject.h 27 Sep 2003 14:27:24 -0000 1.4
+++ GPGObject.h 23 Jan 2005 13:20:02 -0000 1.5
@@ -2,25 +2,27 @@
// GPGObject.h
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGOBJECT_H
@@ -42,6 +44,7 @@
}
+ (void) initialize;
++ (BOOL) needsPointerUniquing;
- (id) initWithInternalRepresentation:(void *)aPtr;
Index: GPGObject.m
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGObject.m,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- GPGObject.m 27 Sep 2003 14:27:24 -0000 1.5
+++ GPGObject.m 23 Jan 2005 13:20:02 -0000 1.6
@@ -2,25 +2,27 @@
// GPGObject.m
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#include <GPGME/GPGObject.h>
@@ -57,12 +59,21 @@
// one NSThread has been created, that's why we create a dummy
// thread before doing anything with gpgme.
[NSThread detachNewThreadSelector:@selector(release) toTarget:aThreadStarter withObject:nil];
-
+
+ setlocale (LC_ALL, "");
// Let's initialize libgpgme sub-systems now.
NSAssert(gpgme_check_version(NULL) != NULL, @"### Unable to initialize gpgme sub-systems.");
+ // Let's initialize default locale; we don't use that possibility in GPGME.framework yet
+ gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
+ gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL));
}
}
++ (BOOL) needsPointerUniquing
+{
+ return NO;
+}
+
- (id) initWithInternalRepresentation:(void *)aPtr
/*"
* Default initializer.
@@ -72,10 +83,18 @@
* In this case the original object is released.
"*/
{
- NSParameterAssert(aPtr != NULL);
+ BOOL needsPointerUniquing = [[self class] needsPointerUniquing];
+
+ NSAssert(!needsPointerUniquing || aPtr != NULL, @"### Cannot map wrapper to a NULL pointer");
if(self = [super init]){
- id anExistingObject = NSMapGet(mapTable, aPtr);
+ id anExistingObject = nil;
+
+ if(needsPointerUniquing){
+ [mapTableLock lock];
+ anExistingObject = NSMapGet(mapTable, aPtr);
+ [mapTableLock unlock];
+ }
if(anExistingObject != nil){
[self release];
@@ -83,9 +102,11 @@
}
else{
_internalRepresentation = aPtr;
- [mapTableLock lock];
- NSMapInsertKnownAbsent(mapTable, _internalRepresentation, self);
- [mapTableLock unlock];
+ if(needsPointerUniquing){
+ [mapTableLock lock];
+ NSMapInsertKnownAbsent(mapTable, _internalRepresentation, self);
+ [mapTableLock unlock];
+ }
}
}
@@ -98,13 +119,25 @@
* #{-[GPGObject dealloc]} method is called!!!
"*/
{
- if(_internalRepresentation != NULL){
- [mapTableLock lock];
- NSMapRemove(mapTable, _internalRepresentation);
- [mapTableLock unlock];
+ if([[self class] needsPointerUniquing]){
+ if(_internalRepresentation != NULL){
+ [mapTableLock lock];
+ NSMapRemove(mapTable, _internalRepresentation);
+ [mapTableLock unlock];
+ }
+ }
+ else{
+ if(_internalRepresentation != NULL){
+ // Free pointer?
+ }
}
[super dealloc];
}
++ (BOOL) accessInstanceVariablesDirectly
+{
+ return NO;
+}
+
@end
Index: GPGPrettyInfo.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGPrettyInfo.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- GPGPrettyInfo.h 27 Sep 2003 14:27:24 -0000 1.5
+++ GPGPrettyInfo.h 23 Jan 2005 13:20:02 -0000 1.6
@@ -5,22 +5,24 @@
// Created by Gordon Worley on Tue Jun 18 2002.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
-//
+// Copyright (C) 2001-2005 Mac GPG Project.
+//
// This code 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; either version 2 of the License, or any later version.
-//
+// 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 General Public License for more
+// 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.
//
-// For a copy of the GNU General Public License, 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGPRETTYINFO_H
@@ -28,9 +30,8 @@
#include <Foundation/Foundation.h>
-#include <GPGME/GPGKey.h>
-#include <GPGME/GPGRecipients.h>
#include <GPGME/GPGDefines.h>
+#include <GPGME/GPGKey.h>
#ifdef __cplusplus
extern "C" {
@@ -39,11 +40,63 @@
#endif
#endif
+
+/*"
+ * Returns a localized human readable string that describing the public
+ * key algorithm value. Returns nil if value is not a valid public key
+ * algorithm.
+"*/
GPG_EXPORT NSString * GPGPublicKeyAlgorithmDescription(GPGPublicKeyAlgorithm value);
+
+
+/*"
+ * Returns a non-localized human readable string that describing the public
+ * key algorithm value. Returns nil if value is not a valid public key
+ * algorithm.
+"*/
+GPG_EXPORT NSString * GPGLocalizedPublicKeyAlgorithmDescription(GPGPublicKeyAlgorithm value);
+
+
+/*"
+ * Returns a localized human readable string that corresponds to the gcrypt input value
+"*/
GPG_EXPORT NSString * GPGSymmetricKeyAlgorithmDescription(GPGSymmetricKeyAlgorithm value);
+
+
+/*"
+ * Returns a localized human readable string describing the hash algorithm
+ * algo. Returns nil if value is not a valid hash algorithm.
+"*/
+GPG_EXPORT NSString * GPGLocalizedHashAlgorithmDescription(GPGHashAlgorithm value);
+
+
+/*"
+ * Returns a non-localized human readable string describing the hash algorithm
+ * algo. This string can be used to output the name of the hash algorithm to
+ * the user. Returns nil if value is not a valid hash algorithm.
+"*/
GPG_EXPORT NSString * GPGHashAlgorithmDescription(GPGHashAlgorithm value);
+
+
+/*"
+ * Returns a localized human readable string that corresponds to the gcrypt input value
+"*/
GPG_EXPORT NSString * GPGValidityDescription(GPGValidity value);
+
+/*"
+ * Returns a non-localized human readable string that corresponds to the protocol input value.
+ * Returns nil if protocol is not valid.
+"*/
+GPG_EXPORT NSString * GPGProtocolDescription(GPGProtocol protocol);
+
+
+/*"
+ * Returns a localized human readable string that corresponds to the protocol input value.
+ * Returns nil if protocol is not valid.
+"*/
+GPG_EXPORT NSString * GPGLocalizedProtocolDescription(GPGProtocol protocol);
+
#ifdef __cplusplus
}
#endif
Index: GPGPrettyInfo.m
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGPrettyInfo.m,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- GPGPrettyInfo.m 27 Sep 2003 14:27:24 -0000 1.5
+++ GPGPrettyInfo.m 23 Jan 2005 13:20:02 -0000 1.6
@@ -5,193 +5,155 @@
// Created by Gordon Worley on Tue Jun 18 2002.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
-//
+// Copyright (C) 2001-2005 Mac GPG Project.
+//
// This code 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; either version 2 of the License, or any later version.
-//
+// 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 General Public License for more
+// 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.
//
-// For a copy of the GNU General Public License, 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#include <GPGME/GPGPrettyInfo.h>
#include <GPGME/LocalizableStrings.h>
+#include <GPGME/GPGInternals.h>
+
+
+#define GPGLocalizedString(string) (string != nil ? NSLocalizedStringFromTableInBundle(string, nil, [NSBundle bundleForClass: [GPGObject class]], ""):nil)
+
+NSString * GPGLocalizedPublicKeyAlgorithmDescription(GPGPublicKeyAlgorithm value)
+{
+ NSString *aString = GPGPublicKeyAlgorithmDescription(value);
+
+ return GPGLocalizedString(aString);
+}
NSString * GPGPublicKeyAlgorithmDescription(GPGPublicKeyAlgorithm value)
-/*"
- * Returns a localized human readable string that corresponds to the gcrypt input value
-"*/
{
- NSString *return_value;
-
- switch (value) {
- case GPG_RSAAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGRSAAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_RSAEncryptOnlyAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGRSAEncryptOnlyAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_RSASignOnlyAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGRSASignOnlyAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_ElgamalEncryptOnlyAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGElgamalEncryptOnlyAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_DSAAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGDSAAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_EllipticCurveAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGEllipticCurveAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_ECDSAAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGECDSAAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_ElgamalAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGElgamalAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_DiffieHellmanAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGDiffieHellmanAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- default:
- return_value = NSLocalizedStringFromTableInBundle(GPGUnknownString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- }
+ const char *aCString = gpgme_pubkey_algo_name(value); // statically allocated string or NULL
- return return_value;
+ return GPGStringFromChars(aCString);
}
NSString * GPGSymmetricKeyAlgorithmDescription(GPGSymmetricKeyAlgorithm value)
-/*"
- * Returns a localized human readable string that corresponds to the gcrypt input value
-"*/
{
NSString *return_value;
switch (value) {
case GPG_NoAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGNoAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGNoAlgorithmString);
break;
case GPG_IDEAAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGIDEAAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGIDEAAlgorithmString);
break;
case GPG_TripleDESAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGTripleDESAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGTripleDESAlgorithmString);
break;
case GPG_CAST5Algorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGCAST5AlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGCAST5AlgorithmString);
break;
case GPG_BlowfishAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGBlowfishAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGBlowfishAlgorithmString);
break;
case GPG_SAFER_SK128Algorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGSAFERSK128AlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGSAFERSK128AlgorithmString);
break;
case GPG_DES_SKAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGDESSKAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGDESSKAlgorithmString);
break;
case GPG_AES128Algorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGAES128AlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGAES128AlgorithmString);
break;
case GPG_AES192Algorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGAES192AlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGAES192AlgorithmString);
break;
case GPG_AES256Algorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGAES256AlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGAES256AlgorithmString);
break;
case GPG_TwoFishAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGTwoFishAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGTwoFishAlgorithmString);
break;
case GPG_SkipjackAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGSkipjackAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGSkipjackAlgorithmString);
break;
case GPG_TwoFish_OldAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGTwoFishOldAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGTwoFishOldAlgorithmString);
break;
case GPG_DummyAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGDummyAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGDummyAlgorithmString);
break;
default:
- return_value = NSLocalizedStringFromTableInBundle(GPGUnknownString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGUnknownString);
break;
}
return return_value;
}
-NSString * GPGHashAlgorithmDescription(GPGHashAlgorithm value)
-/*"
- * Returns a localized human readable string that corresponds to the gcrypt input value
-"*/
+NSString * GPGLocalizedHashAlgorithmDescription(GPGHashAlgorithm value)
{
- NSString *return_value;
+ NSString *aString = GPGHashAlgorithmDescription(value);
- switch (value) {
- case GPG_MD5HashAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGMD5HashAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_SHA_1HashAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGSHA1HashAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_RIPE_MD160HashAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGRIPEMD160HashAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_DoubleWidthSHAHashAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGDoubleWidthSHAHashAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_MD2HashAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGMD2HashAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_TIGER192HashAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGTIGER192HashAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- case GPG_HAVALHashAlgorithm:
- return_value = NSLocalizedStringFromTableInBundle(GPGHAVALHashAlgorithmString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- default:
- return_value = NSLocalizedStringFromTableInBundle(GPGUnknownString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
- break;
- }
+ return GPGLocalizedString(aString);
+}
- return return_value;
+NSString * GPGHashAlgorithmDescription(GPGHashAlgorithm value)
+{
+ const char *aCString = gpgme_hash_algo_name(value); // statically allocated string or NULL
+
+ return GPGStringFromChars(aCString);
}
NSString * GPGValidityDescription(GPGValidity value)
-/*"
- * Returns a localized human readable string that corresponds to the gcrypt input value
-"*/
{
NSString *return_value;
switch (value) {
case GPGValidityUndefined:
- return_value = NSLocalizedStringFromTableInBundle(GPGValidityUndefinedString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGValidityUndefinedString);
break;
case GPGValidityNever:
- return_value = NSLocalizedStringFromTableInBundle(GPGValidityNeverString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGValidityNeverString);
break;
case GPGValidityMarginal:
- return_value = NSLocalizedStringFromTableInBundle(GPGValidityMarginalString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGValidityMarginalString);
break;
case GPGValidityFull:
- return_value = NSLocalizedStringFromTableInBundle(GPGValidityFullString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGValidityFullString);
break;
case GPGValidityUltimate:
- return_value = NSLocalizedStringFromTableInBundle(GPGValidityUltimateString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGValidityUltimateString);
break;
default: //GPGValidityUnknown = 0; if it's something else I guess it's also unknown
- return_value = NSLocalizedStringFromTableInBundle(GPGUnknownString, nil, [NSBundle bundleForClass: [GPGObject class]], "");
+ return_value = GPGLocalizedString(GPGUnknownString);
break;
}
return return_value;
}
+
+NSString *GPGLocalizedProtocolDescription(GPGProtocol protocol)
+{
+ NSString *aString = GPGProtocolDescription(protocol);
+
+ return GPGLocalizedString(aString);
+}
+
+NSString *GPGProtocolDescription(GPGProtocol protocol)
+{
+ const char *aCString = gpgme_get_protocol_name(protocol); // statically allocated string or NULL
+
+ return GPGStringFromChars(aCString);
+}
Index: GPGSignature.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGSignature.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- GPGSignature.h 27 Sep 2003 14:27:24 -0000 1.4
+++ GPGSignature.h 23 Jan 2005 13:20:02 -0000 1.5
@@ -2,31 +2,33 @@
// GPGSignature.h
// GPGME
//
-// Created by davelopper@... on Sun Jul 14 2002.
+// Created by davelopper at users.sourceforge.net on Sun Jul 14 2002.
//
//
-// Copyright (C) 2002 Mac GPG Project.
-//
+// Copyright (C) 2001-2005 Mac GPG Project.
+//
// This code 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; either version 2 of the License, or any later version.
-//
+// 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 General Public License for more
+// 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.
//
-// For a copy of the GNU General Public License, 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGSIGNATURE_H
#define GPGSIGNATURE_H
-#include <Foundation/Foundation.h>
+#include <GPGME/GPGObject.h>
#include <GPGME/GPGKey.h>
#ifdef __cplusplus
@@ -38,57 +40,35 @@
/*"
- * The #GPGSignatureStatus type holds the result of a signature check,
- * or the combined result of all signatures. The following results are possible:
- * _{GPGSignatureStatusNone No status.
- * This status should not occur in normal operation.}
- * _{GPGSignatureStatusGood The signature is valid.
- * For the combined result this status means that
- * all signatures are valid.}
- * _{GPGSignatureStatusBad The signature is not valid.
- * For the combined result this status means that
- * all signatures are invalid.}
- * _{GPGSignatureStatusNoKey The signature could not be checked due to a missing key.
- * For the combined result this status means that
- * all signatures could not be checked due to missing keys.}
- * _{GPGSignatureStatusNoSignature This is not a signature.}
- * _{GPGSignatureStatusError Due to some other error the check could not be done.}
- * _{GPGSignatureStatusDifferent There is more than 1 signature and
- * they have not the same status.}
- * _{GPGSignatureStatusGoodButExpired The signature is valid but expired.
- * For the combined result this status means that
- * all signatures are valid and expired.}
- * _{GPGSignatureStatusGoodButKeyExpired The signature is valid but the key used to
- * verify the signature has expired. For the
- * combined result this status means that all
- * signatures are valid and all keys are expired.}
-"*/
-typedef enum {
- GPGSignatureStatusNone = 0,
- GPGSignatureStatusGood = 1,
- GPGSignatureStatusBad = 2,
- GPGSignatureStatusNoKey = 3,
- GPGSignatureStatusNoSignature = 4,
- GPGSignatureStatusError = 5,
- GPGSignatureStatusDifferent = 6,
- GPGSignatureStatusGoodButExpired = 7,
- GPGSignatureStatusGoodButKeyExpired = 8
-} GPGSignatureStatus;
-
-
-/*"
* Mask values used in #{-summary}.
- * _{GPGSignatureSummaryValidMask The signature is fully valid}
- * _{GPGSignatureSummaryGreenMask The signature is good}
- * _{GPGSignatureSummaryRedMask The signature is bad}
- * _{GPGSignatureSummaryKeyRevokedMask One key has been revoked}
- * _{GPGSignatureSummaryKeyExpiredMask One key has expired}
+ * _{GPGSignatureSummaryValidMask The signature is fully valid.}
+ * _{GPGSignatureSummaryGreenMask The signature is good but one
+ * might want to display some extra
+ * information. Check the other
+ * bits.}
+ * _{GPGSignatureSummaryRedMask The signature is bad. It might
+ * be useful to check other bits
+ * and display more information,
+ * i.e. a revoked certificate might
+ * not render a signature invalid
+ * when the message was received
+ * prior to the cause for the
+ * revocation.}
+ * _{GPGSignatureSummaryKeyRevokedMask The key or at least one
+ * certificate has been revoked.}
+ * _{GPGSignatureSummaryKeyExpiredMask The key or one of the
+ * certificates has expired. It is
+ * probably a good idea to display
+ * the date of the expiration.}
* _{GPGSignatureSummarySignatureExpiredMask The signature has expired}
- * _{GPGSignatureSummaryKeyMissingMask Can't verify: key missing}
- * _{GPGSignatureSummaryCRLMissingMask CRL not available}
- * _{GPGSignatureSummaryCRLTooOldMask Available CRL is too old}
- * _{GPGSignatureSummaryBadPolicyMask A policy was not met}
- * _{GPGSignatureSummarySystemErrorMask A system error occured}
+ * _{GPGSignatureSummaryKeyMissingMask Can't verify due to a missing
+ * key or certificate.}
+ * _{GPGSignatureSummaryCRLMissingMask The CRL (or an equivalent
+ * mechanism) is not available.}
+ * _{GPGSignatureSummaryCRLTooOldMask Available CRL is too old.}
+ * _{GPGSignatureSummaryBadPolicyMask A policy requirement was not
+ * met.}
+ * _{GPGSignatureSummarySystemErrorMask A system error occured.}
"*/
typedef enum {
GPGSignatureSummaryValidMask = 0x0001,
@@ -105,22 +85,56 @@
}GPGSignatureSummaryMask;
-@... GPGSignature : NSObject
+@interface GPGSignature : NSObject <NSCopying>
{
- void *_internalRepresentation;
- unsigned _index;
+ NSString *_fingerprint;
+ NSCalendarDate *_creationDate;
+ NSCalendarDate *_expirationDate;
+ GPGValidity _validity;
+ GPGError _status;
+ GPGSignatureSummaryMask _summary;
+ NSDictionary *_notations;
+ NSArray *_policyURLs;
+ GPGError _validityError;
+ BOOL _wrongKeyUsage;
+ GPGPublicKeyAlgorithm _algorithm;
+ GPGHashAlgorithm _hashAlgorithm;
+ unsigned int _signatureClass;
}
+/*"
+ * Attributes
+"*/
- (NSString *) fingerprint;
-- (GPGKey *) key;
-- (NSString *) errorToken;
-- (NSString *) suberrorToken;
- (NSCalendarDate *) creationDate;
- (NSCalendarDate *) expirationDate;
- (GPGValidity) validity;
-- (NSString *) validityDescription;
-- (GPGSignatureStatus) status;
+- (GPGError) status;
- (GPGSignatureSummaryMask) summary;
+- (GPGPublicKeyAlgorithm) algorithm;
+- (GPGHashAlgorithm) hashAlgorithm;
+- (unsigned int) signatureClass;
+
+/*"
+ * Notations
+"*/
+- (NSDictionary *) notations;
+- (NSArray *) policyURLs;
+
+/*"
+ * Misc
+"*/
+- (GPGError) validityError;
+
+- (BOOL) wrongKeyUsage;
+
+/*"
+ * Convenience methods
+"*/
+- (NSString *) validityDescription;
+- (NSString *) algorithmDescription;
+- (NSString *) hashAlgorithmDescription;
+- (NSString *) formattedFingerprint;
@end
Index: GPGSignature.m
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGSignature.m,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- GPGSignature.m 27 Sep 2003 14:27:24 -0000 1.4
+++ GPGSignature.m 23 Jan 2005 13:20:02 -0000 1.5
@@ -2,162 +2,348 @@
// GPGSignature.m
// GPGME
//
-// Created by davelopper@... on Sun Jul 14 2002.
-//
+// Created by davelopper at users.sourceforge.net on Sun Jul 14 2002.
//
-// Copyright (C) 2002 Mac GPG Project.
//
+// Copyright (C) 2001-2005 Mac GPG Project.
+//
// This code 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; either version 2 of the License, or any later version.
-//
+// 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 General Public License for more
+// 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.
//
-// For a copy of the GNU General Public License, 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#include <GPGME/GPGSignature.h>
-#include <GPGME/GPGInternals.h>
#include <GPGME/GPGPrettyInfo.h>
+#include <GPGME/GPGInternals.h>
#include <Foundation/Foundation.h>
#include <gpgme.h>
-#define _context ((GPGContext *)_internalRepresentation)
-
-
@implementation GPGSignature
/*"
- * #GPGSignature instances are returned by #{-[GPGContext signatures]};
- * you should never need to instantiate yourself objects of that class.
+ * #GPGSignature instances are returned by #{-[GPGContext signatures]}; you
+ * should never need to instantiate yourself objects of that class. Signatures
+ * are also returned after a signing operation, but in this case, currently,
+ * not all attributes have significant values: you can count only on
+ * -algorithm, -hashAlgorithm, -signatureClass, -creationDate and -fingerprint
"*/
-- (id) initWithContext:(GPGContext *)ctx index:(unsigned)index
++ (BOOL) accessInstanceVariablesDirectly
{
- if(self = [self init]){
- _context = ctx; // Not retained
- _index = index;
- }
-
- return self;
+ return NO;
}
-- (BOOL) isEqual:(id)anObject
+- (void) dealloc
{
- if(anObject != nil && [anObject isKindOfClass:[GPGSignature class]])
- return (_context == ((GPGSignature *)anObject)->_internalRepresentation) && (_index == ((GPGSignature *)anObject)->_index);
- else
- return NO;
+ [_fingerprint release];
+ [_creationDate release];
+ [_expirationDate release];
+ [_notations release];
+ [_policyURLs release];
+
+ [super dealloc];
}
-- (NSString *) mainStringAttributeWithIdentifier:(GpgmeAttr)identifier
+- (id) copyWithZone:(NSZone *)zone
+/*"
+ * Returns the same instance, retained. #GPGSignature instances are
+ * (currently) immutable.
+ *
+ * #WARNING: zone is not taken in account.
+"*/
{
- const char *aCString = gpgme_get_sig_string_attr([_context gpgmeContext], _index, identifier, 0);
-
- if(aCString != NULL)
- return [NSString stringWithUTF8String:aCString];
- else
- return nil;
+ // Implementation is useful to allow use of GPGSignature instances as keys in NSMutableDictionary instances.
+ return [self retain];
}
- (NSString *) fingerprint
/*"
- * Returns signer key %fingerprint.
+ * Returns signer's key %fingerprint (or keyID!).
"*/
{
- return [self mainStringAttributeWithIdentifier:GPGME_ATTR_FPR];
+ return _fingerprint;
}
-- (GPGKey *) key
+- (NSString *) formattedFingerprint
/*"
- * Returns signer key.
- *
- * Can raise a #GPGException (except a #GPGErrorEOF).
+ * If -fingerprint returns a fingerprint, returns %{fingerprint} in hex digit
+ * form, formatted like this:
+ *
+ * XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
+ *
+ * or
+ *
+ * XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX
+ *
+ * If -fingerprint returns a keyID, return keyID prefixed by 0x.
"*/
{
- return [_context keyOfSignatureAtIndex:_index];
+ NSString *aString = [self fingerprint];
+
+ if(aString == nil)
+ return @"";
+ else if([aString length] >= 32)
+ return [GPGKey formattedFingerprint:aString];
+ else
+ return [@"0x" stringByAppendingString:aString];
}
-- (NSString *) errorToken
+- (GPGError) validityError
+/*"
+ * If a signature is not valid, this provides a reason why. Not used for new
+ * signatures.
+"*/
{
-#warning What is it for?
- return [self mainStringAttributeWithIdentifier:GPGME_ATTR_ERRTOK];
+ return _validityError;
}
-- (NSString *) suberrorToken
+- (BOOL) wrongKeyUsage
+/*"
+ * Returns YES if the key was not used according to its policy. Not used for
+ * new signatures.
+"*/
{
-#warning What is it for?
- const char *aCString = gpgme_get_sig_string_attr([_context gpgmeContext], _index, GPGME_ATTR_ERRTOK, 1);
-
- if(aCString != NULL)
- return [NSString stringWithUTF8String:aCString];
- else
- return nil;
+ return _wrongKeyUsage;
}
- (NSCalendarDate *) creationDate
/*"
- * Returns signature creation date. Returns nil when not available or invalid.
+ * Returns %signature creation date. Returns nil when not available or
+ * invalid.
"*/
{
- unsigned long aValue = gpgme_get_sig_ulong_attr([_context gpgmeContext], _index, GPGME_ATTR_CREATED, 0);
-
- if(aValue == 0L)
- return nil;
- else
- return [NSCalendarDate dateWithTimeIntervalSince1970:aValue];
+ return _creationDate;
}
- (NSCalendarDate *) expirationDate
/*"
- * Returns signature expiration date. Returns nil when not available or invalid.
+ * Returns %signature expiration date. Returns nil if signature does not
+ * expire. Not used for new signatures.
"*/
{
- unsigned long aValue = gpgme_get_sig_ulong_attr([_context gpgmeContext], _index, GPGME_ATTR_EXPIRE, 0);
-
- if(aValue == 0L)
- return nil;
- else
- return [NSCalendarDate dateWithTimeIntervalSince1970:aValue];
+ return _expirationDate;
}
- (GPGValidity) validity
/*"
- * Returns signature's validity.
+ * Returns %signature's validity. Not used for new signatures.
+ *
+ * Note that a signature's validity is never #GPGValidityUltimate, because
+ * #GPGValidityUltimate is reserved for key certification, not for signatures.
"*/
{
- return gpgme_get_sig_ulong_attr([_context gpgmeContext], _index, GPGME_ATTR_VALIDITY, 0);
+ return _validity;
}
- (NSString *) validityDescription
/*"
- * Returns signature's validity in localized human readable form.
+ * Returns %signature's validity in localized human readable form. Not used
+ * for new signatures.
"*/
{
return GPGValidityDescription([self validity]);
}
-- (GPGSignatureStatus) status
+- (GPGError) status
/*"
- * Returns signature status.
+ * Returns %signature status. In particular, the following status codes are of
+ * interest:
+ * _{GPGErrorNoError This status indicates that the signature is
+ * valid. For the combined result this status
+ * means that all signatures are valid.}
+ * _{GPGErrorSignatureExpired This status indicates that the signature is
+ * valid but expired. For the combined result this
+ * status means that all signatures are valid and
+ * expired.}
+ * _{GPGErrorKeyExpired This status indicates that the signature is
+ * valid but the key used to verify the signature
+ * has expired. For the combined result this
+ * status means that all signatures are valid and
+ * all keys are expired.}
+ * _{GPGErrorCertificateRevoked This status indicates that the signature is
+ * valid but the key used to verify the signature
+ * has been revoked. For the combined result this
+ * status means that all signatures are valid and
+ * all keys are revoked.}
+ * _{GPGErrorBadSignature This status indicates that the signature is
+ * invalid. For the combined result this status
+ * means that all signatures are invalid.}
+ * _{GPGErrorNoPublicKey This status indicates that the signature could
+ * not be verified due to a missing key. For the
+ * combined result this status means that all
+ * signatures could not be checked due to missing
+ * keys.}
+ * _{GPGErrorGeneralError This status indicates that there was some other
+ * error which prevented the signature
+ * verification.}
+ * Not used for new signatures.
"*/
{
- return gpgme_get_sig_ulong_attr([_context gpgmeContext], _index, GPGME_ATTR_SIG_STATUS, 0);
+ return _status;
}
- (GPGSignatureSummaryMask) summary
/*"
- * Returns a mask reflecting the computed state of all signatures.
+ * Returns a mask giving a summary of the signature status. Not used for new
+ * signatures.
"*/
{
- return gpgme_get_sig_ulong_attr([_context gpgmeContext], _index, GPGME_ATTR_SIG_SUMMARY, 0);
+ return _summary;
+}
+
+- (NSDictionary *) notations
+/*"
+ * Returns a dictionary of %{notation data} key-value pairs. A notation is a
+ * key/value pair that is added to the content, it can be anything. Value
+ * is returned as an NSString instance. Not used for new signatures.
+"*/
+{
+ return _notations;
+}
+
+- (NSArray *) policyURLs
+/*"
+ * Returns an array of %{policy URLs} as NSString instances. A policy URL is
+ * an URL to a document that documents the persons policy in signing other
+ * peoples keys. Not used for new signatures.
+"*/
+{
+ return _policyURLs;
+}
+
+- (GPGPublicKeyAlgorithm) algorithm
+/*"
+ * Returns the algorithm used to create the signature. Not (yet?) available
+ * for signatures returned after a verification operation.
+"*/
+{
+ return _algorithm;
+}
+
+- (NSString *) algorithmDescription
+/*"
+ * Returns the localized description of the algorithm used to create the
+ * signature. Not (yet?) available for signatures returned after a
+ * verification operation.
+"*/
+{
+ return GPGLocalizedPublicKeyAlgorithmDescription([self algorithm]);
+}
+
+- (GPGHashAlgorithm) hashAlgorithm
+/*"
+ * Returns the hash algorithm used for the newly-created signature.
+"*/
+{
+ return _hashAlgorithm;
+}
+
+- (NSString *) hashAlgorithmDescription
+/*"
+ * Returns the localized description of the algorithm used for the
+ * newly-created signature.
+"*/
+{
+ return GPGLocalizedHashAlgorithmDescription([self hashAlgorithm]);
+}
+
+- (unsigned int) signatureClass
+/*"
+ * Returns the signature class of a %{key signature} or a new signature. The
+ * meaning is specific to the crypto engine.
+ *
+ * This attribute is not (yet?) available for signatures returned after a
+ * verification operation.
+"*/
+{
+ return _signatureClass;
+}
+
+@end
+
+@implementation GPGSignature(GPGInternals)
+
+- (id) initWithSignature:(gpgme_signature_t)signature
+{
+ if(self = [self init]){
+ unsigned long aValue;
+ gpgme_sig_notation_t aNotation;
+
+ _fingerprint = [GPGStringFromChars(signature->fpr) retain];
+ _validityError = signature->validity_reason;
+ _wrongKeyUsage = !!signature->wrong_key_usage;
+ aValue = signature->timestamp;
+ if(aValue != 0L)
+ _creationDate = [[NSCalendarDate dateWithTimeIntervalSince1970:aValue] retain];
+ aValue = signature->exp_timestamp;
+ if(aValue != 0L)
+ _expirationDate = [[NSCalendarDate dateWithTimeIntervalSince1970:aValue] retain];
+ _validity = signature->validity;
+ _status = signature->status;
+ _summary = signature->summary;
+ aNotation = signature->notations;
+ _notations = [[NSMutableDictionary alloc] init];
+ _policyURLs = [[NSMutableArray alloc] init];
+ while(aNotation != NULL){
+ char *name = aNotation->name;
+
+ if(name != NULL){
+ // WARNING: theoretically there could be more than one notation
+ // data for the same name.
+ NSString *aName = GPGStringFromChars(name);
+ NSString *aValue = GPGStringFromChars(aNotation->value);
+
+ if([_notations objectForKey:aName] != nil)
+ NSLog(@"### We don't support more than one notation per name!! Ignoring notation '%@' with value '%@'", aName, aValue);
+ else
+ [(NSMutableDictionary *)_notations setObject:aValue forKey:aName];
+ }
+ else
+ [(NSMutableArray *)_policyURLs addObject:GPGStringFromChars(aNotation->value)];
+ aNotation = aNotation->next;
+ }
+ _algorithm = 0; // Unsignificant value
+ _hashAlgorithm = 0; // Unsignificant value (GPG_NoHashAlgorithm)
+ _signatureClass = 0; // Unsignificant value
+ }
+
+ return self;
+}
+
+- (id) initWithNewSignature:(gpgme_new_signature_t)signature
+{
+ if(self = [self init]){
+ long aValue;
+
+ _fingerprint = [GPGStringFromChars(signature->fpr) retain];
+ _validityError = GPGErrorNoError;
+ _wrongKeyUsage = NO;
+ aValue = signature->timestamp;
+ if(aValue != 0L)
+ _creationDate = [[NSCalendarDate dateWithTimeIntervalSince1970:aValue] retain];
+ _validity = GPGValidityUltimate;
+ _status = GPGErrorNoError;
+ _summary = 0;
+ _algorithm = signature->pubkey_algo;
+ _hashAlgorithm = signature->hash_algo;
+ _signatureClass = signature->sig_class;
+ // We ignore gpgme_new_signature_t->type (GPGSignatureMode)
+ }
+
+ return self;
}
@end
Index: GPGTrustItem.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGTrustItem.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- GPGTrustItem.h 27 Sep 2003 14:27:24 -0000 1.6
+++ GPGTrustItem.h 23 Jan 2005 13:20:02 -0000 1.7
@@ -2,32 +2,34 @@
// GPGTrustItem.h
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGTRUSTITEM_H
#define GPGTRUSTITEM_H
#include <GPGME/GPGObject.h>
-#include <GPGME/GPGRecipients.h>
+#include <GPGME/GPGKey.h>
#ifdef __cplusplus
extern "C" {
@@ -45,16 +47,11 @@
}
- (NSString *) keyID;
-- (GPGValidity) ownerTrust;
- (NSString *) ownerTrustDescription;
-- (NSString *) userID;
-- (GPGValidity) validity;
- (NSString *) validityDescription;
- (int) level;
- (int) type;
-
-+ (NSString *) ownerTrustDescription: (GPGValidity)value;
-+ (NSString *) validityDescription: (GPGValidity)value;
+- (NSString *) name;
@end
Index: GPGTrustItem.m
===================================================================
RCS file: /cvsroot/macgpg/GPGME/GPGTrustItem.m,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- GPGTrustItem.m 27 Sep 2003 14:27:24 -0000 1.8
+++ GPGTrustItem.m 23 Jan 2005 13:20:02 -0000 1.9
@@ -2,25 +2,27 @@
// GPGTrustItem.m
// GPGME
//
-// Created by davelopper@... on Tue Aug 14 2001.
+// Created by davelopper at users.sourceforge.net on Tue Aug 14 2001.
//
//
-// Copyright (C) 2001-2003 Mac GPG Project.
+// Copyright (C) 2001-2005 Mac GPG Project.
//
// This code 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; either version 2 of the License, or any later version.
+// 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 General Public License for more
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
-// For a copy of the GNU General Public License, visit <http://www.gnu.org/> or
-// write to the Free Software Foundation, Inc., 59 Temple Place--Suite 330,
-// Boston, MA 02111-1307, USA.
+// 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#include <GPGME/GPGTrustItem.h>
@@ -30,24 +32,30 @@
#include <gpgme.h>
-#define _trustItem ((GpgmeTrustItem)_internalRepresentation)
+#define _trustItem ((gpgme_trust_item_t)_internalRepresentation)
@implementation GPGTrustItem
/*"
- * #GPGTrustItem instances are returned by #{-[GPGContext trustListEnumeratorForSearchPattern:maximumLevel:]};
- * you should never need to instantiate objects of that class.
+ * #GPGTrustItem instances are returned by
+ * #{-[GPGContext trustListEnumeratorForSearchPattern:maximumLevel:]}; you
+ * should never need to instantiate objects of that class.
*
* #CAUTION: the trust items interface is experimental.
"*/
++ (BOOL) needsPointerUniquing
+{
+ return YES;
+}
+
- (void) dealloc
{
- GpgmeTrustItem cachedTrustItem = _trustItem;
+ gpgme_trust_item_t cachedTrustItem = _trustItem;
[super dealloc];
- gpgme_trust_item_release(cachedTrustItem);
+ gpgme_trust_item_unref(cachedTrustItem);
}
- (NSString *) keyID
@@ -55,92 +63,31 @@
* Returns the %{key ID} of the %key refered by the trust item.
"*/
{
- const char *aCString = gpgme_trust_item_get_string_attr(_trustItem, GPGME_ATTR_KEYID, NULL, 0);
- NSString *aString = nil;
-
- NSAssert(aCString != NULL, @"### Invalid key.");
- if(aCString != NULL)
- aString = [NSString stringWithUTF8String:aCString];
-
- return aString;
-}
-
-- (GPGValidity) validityFromCharacter:(char)character
-{
- switch(character){
- case 'q':
- return GPGValidityUnknown;
- case 'n':
- return GPGValidityNever;
- case 'm':
- return GPGValidityMarginal;
- case 'f':
- return GPGValidityFull;
- case 'u':
- return GPGValidityUltimate;
- default:
- [NSException raise:NSInternalInconsistencyException format:@"Unknown trust value '%c'", character];
- return -1; // Never reached; just here to make compiler happy ;-)
- }
+ return GPGStringFromChars(_trustItem->keyid);
}
-- (GPGValidity) ownerTrust
+- (NSString *) ownerTrustDescription
/*"
- * #CAUTION: not yet working.
+ * #CAUTION: not yet working. Only if type = 1.
"*/
{
- const char *aCString = gpgme_trust_item_get_string_attr(_trustItem, GPGME_ATTR_OTRUST, NULL, 0);
-
- NSAssert(aCString != NULL, @"### Invalid key.");
- if(aCString != NULL){
- NSAssert1(strlen(aCString) == 1, @"### We cannot decode this ownerTrust value: %s", aCString);
-
- return [self validityFromCharacter:aCString[0]];
- }
-
- return GPGValidityUnknown;
-}
-
-- (NSString *) ownerTrustDescription
-{
- return GPGValidityDescription([self ownerTrust]);
+ return GPGStringFromChars(_trustItem->owner_trust);
}
-- (NSString *) userID
+- (NSString *) name
/*"
- * Returns the %{user ID} associated with the trust item.
+ * Returns the %{name} associated with the trust item. Only if type = 2.
"*/
{
- const char *aCString = gpgme_trust_item_get_string_attr(_trustItem, GPGME_ATTR_USERID, NULL, 0);
- NSString *aString = nil;
-
- NSAssert(aCString != NULL, @"### Invalid key.");
- if(aCString != NULL)
- aString = GPGStringFromChars(aCString);
-
- return aString;
+ return GPGStringFromChars(_trustItem->name);
}
-- (GPGValidity) validity
+- (NSString *) validityDescription
/*"
* Returns the computed validity associated with the trust item.
"*/
{
- const char *aCString = gpgme_trust_item_get_string_attr(_trustItem, GPGME_ATTR_VALIDITY, NULL, 0);
-
- NSAssert(aCString != NULL, @"### Invalid key.");
- if(aCString != NULL){
- NSAssert1(strlen(aCString) == 1, @"### We cannot decode this validity value: %s", aCString);
-
- return [self validityFromCharacter:aCString[0]];
- }
-
- return GPGValidityUnknown;
-}
-
-- (NSString *) validityDescription
-{
- return GPGValidityDescription([self validity]);
+ return GPGStringFromChars(_trustItem->validity);
}
- (int) level
@@ -148,27 +95,18 @@
* Returns the trust level of the trust item.
"*/
{
- int level = gpgme_trust_item_get_int_attr(_trustItem, GPGME_ATTR_LEVEL, NULL, 0);
-
- // It seems that level=0 is a valid value (ultimately trusted?)
-// NSAssert(level != 0, @"### Invalid key.");
-
- return level;
+ return _trustItem->level;
}
- (int) type
/*"
- * Returns the type of the trust item.
+ * Returns the type of the trust item. A value of 1 refers to a key, a value
+ * of 2 refers to a user ID.
*
- * #CAUTION: not yet working.
+ * #CHECK: not yet working.
"*/
{
- // What is the <type> attribute??? Asked to Werner: "do not use GpgmeTrustItem yet"
- int type = gpgme_trust_item_get_int_attr(_trustItem, GPGME_ATTR_TYPE, NULL, 0);
-
- NSAssert(type != 0, @"### Invalid key.");
-
- return type;
+ return _trustItem->type;
}
#warning TODO
@@ -178,14 +116,4 @@
(we need to create a local context to get the named key; key should be cached)
*/
-+ (NSString *) ownerTrustDescription: (GPGValidity)value
-{
- return GPGValidityDescription(value);
-}
-
-+ (NSString *) validityDescription: (GPGValidity)value
-{
- return GPGValidityDescription(value);
-}
-
@end
Index: IntroGPGME.html
===================================================================
RCS file: /cvsroot/macgpg/GPGME/IntroGPGME.html,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- IntroGPGME.html 27 Sep 2003 14:22:28 -0000 1.3
+++ IntroGPGME.html 23 Jan 2005 13:20:02 -0000 1.4
@@ -6,7 +6,7 @@
<P>`GnuPG Made Easy' (<ACRONYM>GPGME</ACRONYM>) is an Objective-C framework wrapping <A HREF="http://www.gnupg.org/gpgme.html">libgpgme</A>, a C language library, that allows to add support for cryptography to a program. It is designed to make access to crypto engines like GnuPG or GpgSM easier for applications. <ACRONYM>GPGME</ACRONYM> provides a high-level crypto API for encryption, decryption, signing, signature verification and key management.</P>
-<P><ACRONYM>GPGME</ACRONYM> uses GnuPG and GpgSM as its backends to support OpenPGP and the Cryptograhic Message Syntax (CMS).</P>
+<P><ACRONYM>GPGME</ACRONYM> uses GnuPG and GpgSM as its backends to support OpenPGP and the Cryptographic Message Syntax (CMS).</P>
<H2>Getting Started</H2>
@@ -19,9 +19,9 @@
<P><ACRONYM>GPGME</ACRONYM> has a couple of advantages over other libraries/frameworks doing a similar job, and over implementing support for GnuPG or other crypto engines into your application directly.</P>
<DL COMPACT>
<DT>It's free software
-<DD>Anybody can use, modify, and redistribute it under the terms of the <A HREF="">GNU General Public License</A>.
+<DD>Anybody can use, modify, and redistribute it under the terms of the <A HREF="http://www.gnu.org/">GNU Lesser General Public License</A>.
<DT>It's flexible
-<DD><ACRONYM>GPGME</ACRONYM> provides transparent support for several cryptographic protocols by different engines. Currently, <ACRONYM>GPGME</ACRONYM> supports the OpenPGP protocol using GnuPG as the backend, and the Cryptographic Message Syntax using GpgSM as the backend. <B>NOTE: GpgSM is not yet working on MacOS X.</B>
+<DD><ACRONYM>GPGME</ACRONYM> provides transparent support for several cryptographic protocols by different engines. Currently, <ACRONYM>GPGME</ACRONYM> supports the OpenPGP protocol using GnuPG as the backend, and the Cryptographic Message Syntax using GpgSM as the backend. <B>NOTE: GpgSM has not yet been ported to MacOS X.</B>
<DT>It's easy
<DD><ACRONYM>GPGME</ACRONYM> hides the differences between the protocols and engines from the programmer behind an easy-to-use interface. This way the programmer can focus on the other parts of the program, and still integrate strong cryptography in his application. Once support for <ACRONYM>GPGME</ACRONYM> has been added to a program, it is easy to add support for other crypto protocols once <ACRONYM>GPGME</ACRONYM> backends provide them.
</DL>
@@ -33,7 +33,7 @@
<P>Furthermore, <ACRONYM>GPGME</ACRONYM> has rich key management facilities including listing keys, querying their attributes, generating, importing, exporting and deleting keys, and acquiring information about the trust path.</P>
-<P><STRONG>Caution:</STRONG> The <ACRONYM>GPGME</ACRONYM> framework is not thread-safe. It will be to some extent in the future, but currently great care has to be taken if <ACRONYM>GPGME</ACRONYM> is used in a multi-threaded environment.</P>
+<P><STRONG>Caution:</STRONG> The <ACRONYM>GPGME</ACRONYM> framework is not thread-safe. It will be to some extent in the future, but currently great care has to be taken if <ACRONYM>GPGME</ACRONYM> is used in a multi-threaded environment. You should at least take care that no instance of GPGContext nor GPGData is accessed concurrently, and that only one thread at any time calls +[GPGContext waitOnAnyRequest:] or -[GPGContext wait:].</P>
<H2>Error handling</H2>
@@ -60,11 +60,16 @@
<LH>Classes
<LI><A HREF="Classes/GPGContext.html">GPGContext</A>
<LI><A HREF="Classes/GPGData.html">GPGData</A>
+<LI><A HREF="Classes/GPGEngine.html">GPGEngine</A>
<LI><A HREF="Classes/GPGKey.html">GPGKey</A>
+<LI><A HREF="Classes/GPGKeyGroup.html">GPGKeyGroup</A>
+<LI><A HREF="Classes/GPGKeySignature.html">GPGKeySignature</A>
<LI><A HREF="Classes/GPGObject.html">GPGObject</A>
-<LI><A HREF="Classes/GPGRecipients.html">GPGRecipients</A>
+<LI><A HREF="Classes/GPGOptions.html">GPGOptions</A>
<LI><A HREF="Classes/GPGSignature.html">GPGSignature</A>
+<LI><A HREF="Classes/GPGSubkey.html">GPGSubkey</A>
<LI><A HREF="Classes/GPGTrustItem.html">GPGTrustItem</A>
+<LI><A HREF="Classes/GPGUserID.html">GPGUserID</A>
<LI><A HREF="Classes/NSException+GPGExceptions.html">NSException(GPGExceptions)</A>
</UL>
<UL>
@@ -74,9 +79,8 @@
</UL>
<UL>
<LH>Functions
-<LI><A HREF="Functions/GPGEngine.html">GPGEngine</A>
<LI><A HREF="Functions/GPGPrettyInfo.html">GPGPrettyInfo</A>
</UL>
-<P>© 2001-2002 <A HREF="http://macgpg.sourceforge.net/">Mac GPG Project</A></P>
+<P>© 2001-2005 <A HREF="http://macgpg.sourceforge.net/">Mac GPG Project</A></P>
</BODY>
</HTML>
\ No newline at end of file
Index: LocalizableStrings.h
===================================================================
RCS file: /cvsroot/macgpg/GPGME/LocalizableStrings.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- LocalizableStrings.h 27 Sep 2003 14:27:24 -0000 1.4
+++ LocalizableStrings.h 23 Jan 2005 13:20:02 -0000 1.5
@@ -3,28 +3,33 @@
// GPGME
//
// Created by Gordon Worley
-// Copyright (C) 2001 Mac GPG Project.
//
-// This code 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; either version 2 of the License, or any later version.
//
+// Copyright (C) 2001-2005 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 General Public License for more
+// 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.
//
-// For a copy of the GNU General Public License, 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/> or <macgpg@...>
+// More info at <http://macgpg.sourceforge.net/>
//
#ifndef LOCALIZABLESTRINGS_H
#define LOCALIZABLESTRINGS_H
#include <Foundation/Foundation.h>
+#include <GPGME/GPGDefines.h>
#ifdef __cplusplus
extern "C" {
@@ -33,42 +38,27 @@
#endif
#endif
-extern NSString * const GPGUnknownString;
-extern NSString * const GPGValidityUndefinedString;
-extern NSString * const GPGValidityNeverString;
-extern NSString * const GPGValidityMarginalString;
-extern NSString * const GPGValidityFullString;
-extern NSString * const GPGValidityUltimateString;
-extern NSString * const GPGMD5HashAlgorithmString;
-extern NSString * const GPGSHA1HashAlgorithmString;
-extern NSString * const GPGRIPEMD160HashAlgorithmString;
-extern NSString * const GPGDoubleWidthSHAHashAlgorithmString;
-extern NSString * const GPGMD2HashAlgorithmString;
-extern NSString * const GPGTIGER192HashAlgorithmString;
-extern NSString * const GPGHAVALHashAlgorithmString;
-extern NSString * const GPGRSAAlgorithmString;
-extern NSString * const GPGRSAEncryptOnlyAlgorithmString;
-extern NSString * const GPGRSASignOnlyAlgorithmString;
-extern NSString * const GPGElgamalEncryptOnlyAlgorithmString;
-extern NSString * const GPGDSAAlgorithmString;
-extern NSString * const GPGEllipticCurveAlgorithmString;
-extern NSString * const GPGECDSAAlgorithmString;
-extern NSString * const GPGElgamalAlgorithmString;
-extern NSString * const GPGDiffieHellmanAlgorithmString;
-extern NSString * const GPGNoAlgorithmString;
-extern NSString * const GPGIDEAAlgorithmString;
-extern NSString * const GPGTripleDESAlgorithmString;
-extern NSString * const GPGCAST5AlgorithmString;
-extern NSString * const GPGBlowfishAlgorithmString;
-extern NSString * const GPGSAFERSK128AlgorithmString;
-extern NSString * const GPGDESSKAlgorithmString;
-extern NSString * const GPGAES128AlgorithmString;
-extern NSString * const GPGAES192AlgorithmString;
-extern NSString * const GPGAES256AlgorithmString;
-extern NSString * const GPGTwoFishAlgorithmString;
-extern NSString * const GPGSkipjackAlgorithmString;
-extern NSString * const GPGTwoFishOldAlgorithmString;
-extern NSString * const GPGDummyAlgorithmString;
+
+GPG_EXPORT NSString * const GPGUnknownString;
+GPG_EXPORT NSString * const GPGValidityUndefinedString;
+GPG_EXPORT NSString * const GPGValidityNeverString;
+GPG_EXPORT NSString * const GPGValidityMarginalString;
+GPG_EXPORT NSString * const GPGValidityFullString;
+GPG_EXPORT NSString * const GPGValidityUltimateString;
+GPG_EXPORT NSString * const GPGNoAlgorithmString;
+GPG_EXPORT NSString * const GPGIDEAAlgorithmString;
+GPG_EXPORT NSString * const GPGTripleDESAlgorithmString;
+GPG_EXPORT NSString * const GPGCAST5AlgorithmString;
+GPG_EXPORT NSString * const GPGBlowfishAlgorithmString;
+GPG_EXPORT NSString * const GPGSAFERSK128AlgorithmString;
+GPG_EXPORT NSString * const GPGDESSKAlgorithmString;
+GPG_EXPORT NSString * const GPGAES128AlgorithmString;
+GPG_EXPORT NSString * const GPGAES192AlgorithmString;
+GPG_EXPORT NSString * const GPGAES256AlgorithmString;
+GPG_EXPORT NSString * const GPGTwoFishAlgorithmString;
+GPG_EXPORT NSString * const GPGSkipjackAlgorithmString;
+GPG_EXPORT NSString * const GPGTwoFishOldAlgorithmString;
+GPG_EXPORT NSString * const GPGDummyAlgorithmString;
#ifdef __cplusplus
}
Index: README
===================================================================
RCS file: /cvsroot/macgpg/GPGME/README,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- README 27 Sep 2003 14:21:53 -0000 1.18
+++ README 23 Jan 2005 13:20:02 -0000 1.19
@@ -1,54 +1,51 @@
gpgme library
=============
-In order to build this framework, you need gpgme 0.3.15 or greater installed (and whatever version of GnuPG that requires; currently >= 1.2.0). To download and install it, proceed like this:
-On MacOS X 10.2:
-curl -O ftp://ftp.gnupg.org/gcrypt/gpgme/gpgme-0.3.15.tar.gz
-curl -O ftp://ftp.gnupg.org/gcrypt/gpgme/gpgme-0.3.15.tar.gz.sig
-gpg --verify gpgme-0.3.15.tar.gz.sig
+*** WARNING These instructions are for MacOS X 10.3.x, and will NOT work as-is for 10.2 ***
-(It seems there is a bug in the package; rights will not be restored correctly if not unpackaged as root, that's why we use the 'sudo tcsh' command to perform all following commands as root)
+In order to build this framework, you need gpgme 1.0.2 or greater installed (and whatever version of GnuPG that requires; currently >= 1.2.2), and libgpg-error 1.0. These instructions show you how to build these libraries as static libraries, and not dynamic ones; this way you have no problem when installing your framework (not other dependency than framework's).
-sudo tcsh
-gnutar xzf gpgme-0.3.15.tar.gz
-cd gpgme-0.3.15
-./configure
-mv libtool libtool.original
-sed < libtool.original "s%-flat_namespace -undefined suppress%-prebind -F/System/Library/Frameworks/System.framework -seg1addr 0x10000000%" > libtool
-make
-make install
-mv /usr/local/lib/libgpgme.dylib /usr/local/lib/libgpgme.dylib.off
-exit
+To download and install it, proceed like this:
+
+curl -O ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.0.tar.gz
+curl -O ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.0.tar.gz.sig
+gpg --verify libgpg-error-1.0.tar.gz.sig
+gnutar xzf libgpg-error-1.0.tar.gz
+cd libgpg-error-1.0
+./configure --enable-static --disable-shared --disable-dependency-tracking
+sudo make install
cd ..
+curl -O ftp://ftp.gnupg.org/gcrypt/gpgme/gpgme-1.0.2.tar.gz
+curl -O ftp://ftp.gnupg.org/gcrypt/gpgme/gpgme-1.0.2.tar.gz.sig
+gpg --verify gpgme-1.0.2.tar.gz.sig
+gnutar xzf gpgme-1.0.2.tar.gz
+cd gpgme-1.0.2
+./configure --enable-static --disable-shared --disable-dependency-tracking
+sudo make install
+cd ..
-Note that now the dynamic library libgpgme.dylib is renamed to avoid it's use! If you link GPGME against the dylib (if there are both a static and dynamic version of the same library, the linker uses the dynamic one), then you must install the dylib on user's computer. To avoid this, it's preferrable to rename it to avoid its use, and link against the static version.
+
+WARNING: since gpgme 0.4.3, we need to use libgpgme-pthread (instead of libgpgme) if we want support for multithreading. We do that in GPGME.
Installing GPGME framework (OR: Using It In Your Code)
=======================================================
In order to do anything useful with this framework you must install it. There are now 4 build styles, 2 of them are for stand-alone framework, the 2 others are for embedding the framework in your application (these are the ones you should use).
-So, compile the framework using the EmbDevelopment or EmbDeployment Build Styles, then add a Copy Phase in your application's project to copy the GPGME.framework (located in your build products directory) in the Frameworks subdirectory of your application. See GPGTester settings to get an example or read Project Builder's help about frameworks.
+So, compile the framework using the EmbDevelopment or EmbDeployment Build Styles, then add a Copy Phase in your application's project to copy the GPGME.framework (located in your build products directory) in the Frameworks subdirectory of your application. See GPGTester settings to get an example or read Xcode's help about frameworks.
If you prefer to have a standalone installed version of GPGME.framework (why would you do?), then use the Development or Deployment Build Styles.
/Library/Frameworks is the default install location.
(Why? It's really hard to create a portable access path to ~/Library/Frameworks. Very easy to create one to /Library/Frameworks)
-However, ProjectBuilder (as of ProjectBuilder 2.0.1) does not provide yet the -install- feature, you must use Terminal
-
-On Mac OS X 10.2:
- (from within the GPGME directory)
- pbxbuild install -target GPGME DSTROOT= //there is no typo here. It really is "DSTROOT="
- cd ..
-
Documentation generation
========================
HTML documentation can be generated automatically from code. For this you need to have installed autodoc in /usr/local/bin/, and its templates in one of the searched locations (see AutoDoc documentation).
To install AutoDoc, type the following commands in a terminal:
-On MacOS X 10.2:
+On MacOS X 10.3:
curl -O ftp://ftp.misckit.com/pub/next/misckit/AutoDoc-2.0b8-P-b.tar.gz
gnutar xzf AutoDoc-2.0b8-P-b.tar.gz
sudo mkdir -p /usr/local/bin
@@ -60,5 +57,5 @@
To generate and install the documentation, choose target GPGME Documentation, and build; documentation will be installed in /Library/Documentation/GPGME
Note that if you use the Deployment Build Style for GPGME.framework, documentation will also be copied in GPGME.framework on install.
-Tip: To view documentation within ProjectBuilder, open the files using File/Open..., and bookmark them with Navigation/Add to Bookmarks.
+Tip: To view documentation within Xcode, open the installed files using File/Open..., and bookmark them with Navigation/Add to Bookmarks.
|