/** * gnutls_privkey_export_openpgp: * @pkey: The private key * @key: Location for the key to be exported. * * Converts the given abstract private key to a #gnutls_openpgp_privkey_t * type. The key must be of type %GNUTLS_PRIVKEY_OPENPGP. The key * returned in @key must be deinitialized with * gnutls_openpgp_privkey_deinit(). * * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a * negative error value. * * Since: 3.4.0 */ int gnutls_privkey_export_openpgp(gnutls_privkey_t pkey, gnutls_openpgp_privkey_t *key) { int ret; if (pkey->type != GNUTLS_PRIVKEY_OPENPGP) { gnutls_assert(); return GNUTLS_E_INVALID_REQUEST; } ret = gnutls_openpgp_privkey_init(key); if (ret < 0) return gnutls_assert_val(ret); ret = _gnutls_openpgp_privkey_cpy(*key, pkey->key.openpgp); if (ret < 0) { gnutls_openpgp_privkey_deinit(*key); *key = NULL; return gnutls_assert_val(ret); } return 0; }
/** * gnutls_privkey_import_openpgp: * @pkey: The private key * @key: The private key to be imported * @flags: Flags for the import * * This function will import the given private key to the abstract * #gnutls_privkey_t structure. * * The #gnutls_openpgp_privkey_t object must not be deallocated * during the lifetime of this structure. The subkey set as * preferred will be used, or the master key otherwise. * * @flags might be zero or one of %GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE * and %GNUTLS_PRIVKEY_IMPORT_COPY. * * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a * negative error value. * * Since: 2.12.0 **/ int gnutls_privkey_import_openpgp(gnutls_privkey_t pkey, gnutls_openpgp_privkey_t key, unsigned int flags) { int ret, idx; uint8_t keyid[GNUTLS_OPENPGP_KEYID_SIZE]; ret = check_if_clean(pkey); if (ret < 0) { gnutls_assert(); return ret; } if (flags & GNUTLS_PRIVKEY_IMPORT_COPY) { ret = gnutls_openpgp_privkey_init(&pkey->key.openpgp); if (ret < 0) return gnutls_assert_val(ret); ret = _gnutls_openpgp_privkey_cpy(pkey->key.openpgp, key); if (ret < 0) { gnutls_openpgp_privkey_deinit(pkey->key.openpgp); return gnutls_assert_val(ret); } } else pkey->key.openpgp = key; pkey->type = GNUTLS_PRIVKEY_OPENPGP; ret = gnutls_openpgp_privkey_get_preferred_key_id(key, keyid); if (ret == GNUTLS_E_OPENPGP_PREFERRED_KEY_ERROR) { pkey->pk_algorithm = gnutls_openpgp_privkey_get_pk_algorithm(key, NULL); } else { if (ret < 0) return gnutls_assert_val(ret); idx = gnutls_openpgp_privkey_get_subkey_idx(key, keyid); pkey->pk_algorithm = gnutls_openpgp_privkey_get_subkey_pk_algorithm(key, idx, NULL); } pkey->flags = flags; return 0; }