Next: , Previous: Exporting Keys, Up: Key Management


7.4.7 Importing Keys

— Function: gpgme_error_t gpgme_op_import (gpgme_ctx_t ctx, gpgme_data_t keydata)

The function gpgme_op_import adds the keys in the data buffer keydata to the key ring of the crypto engine used by ctx. The format of keydata can be ASCII armored, for example, but the details are specific to the crypto engine.

After the operation completed successfully, the result can be retrieved with gpgme_op_import_result.

The function returns the error code GPG_ERR_NO_ERROR if the import was completed successfully, GPG_ERR_INV_VALUE if keydata if ctx or keydata is not a valid pointer, and GPG_ERR_NO_DATA if keydata is an empty data buffer.

— Function: gpgme_error_t gpgme_op_import_start (gpgme_ctx_t ctx, gpgme_data_t keydata)

The function gpgme_op_import_start initiates a gpgme_op_import operation. It can be completed by calling gpgme_wait on the context. See Waiting For Completion.

The function returns the error code GPG_ERR_NO_ERROR if the import could be started successfully, GPG_ERR_INV_VALUE if keydata if ctx or keydata is not a valid pointer, and GPG_ERR_NO_DATA if keydata is an empty data buffer.

— Data type: gpgme_import_status_t

This is a pointer to a structure used to store a part of the result of a gpgme_op_import operation. For each considered key one status is added that contains information about the result of the import. The structure contains the following members:

gpgme_import_status_t next
This is a pointer to the next status structure in the linked list, or NULL if this is the last element.
char *fpr
This is the fingerprint of the key that was considered.
gpgme_error_t result
If the import was not successful, this is the error value that caused the import to fail. Otherwise the error code is GPG_ERR_NO_ERROR.
unsigned int status
This is a bit-wise OR of the following flags that give more information about what part of the key was imported. If the key was already known, this might be 0.
GPGME_IMPORT_NEW
The key was new.
GPGME_IMPORT_UID
The key contained new user IDs.
GPGME_IMPORT_SIG
The key contained new signatures.
GPGME_IMPORT_SUBKEY
The key contained new sub keys.
GPGME_IMPORT_SECRET
The key contained a secret key.

— Data type: gpgme_import_result_t

This is a pointer to a structure used to store the result of a gpgme_op_import operation. After a successful import operation, you can retrieve the pointer to the result with gpgme_op_import_result. The structure contains the following members:

int considered
The total number of considered keys.
int no_user_id
The number of keys without user ID.
int imported
The total number of imported keys.
imported_rsa
The number of imported RSA keys.
unchanged
The number of unchanged keys.
new_user_ids
The number of new user IDs.
new_sub_keys
The number of new sub keys.
new_signatures
The number of new signatures.
new_revocations
The number of new revocations.
secret_read
The total number of secret keys read.
secret_imported
The number of imported secret keys.
secret_unchanged
The number of unchanged secret keys.
not_imported
The number of keys not imported.
gpgme_import_status_t imports
A list of gpgme_import_status_t objects which contain more information about the keys for which an import was attempted.

— Function: gpgme_import_result_t gpgme_op_import_result (gpgme_ctx_t ctx)

The function gpgme_op_import_result returns a gpgme_import_result_t pointer to a structure holding the result of a gpgme_op_import operation. The pointer is only valid if the last operation on the context was a gpgme_op_import or gpgme_op_import_start operation, and if this operation finished successfully. The returned pointer is only valid until the next operation is started on the context.

The following interface is deprecated and only provided for backward compatibility. Don't use it. It will be removed in a future version of GPGME.

— Function: gpgme_error_t gpgme_op_import_ext (gpgme_ctx_t ctx, gpgme_data_t keydata, int *nr)

The function gpgme_op_import_ext is equivalent to:

            gpgme_error_t err = gpgme_op_import (ctx, keydata);
            if (!err)
              {
                gpgme_import_result_t result = gpgme_op_import_result (ctx);
                *nr = result->considered;
              }