Exemplo n.º 1
0
void
cdk_pkt_free (cdk_packet_t pkt)
{
  if (!pkt)
    return;
  
  switch (pkt->pkttype) 
    {
    case CDK_PKT_ATTRIBUTE    :
    case CDK_PKT_USER_ID      : _cdk_free_userid (pkt->pkt.user_id); break;
    case CDK_PKT_PUBLIC_KEY   :
    case CDK_PKT_PUBLIC_SUBKEY: cdk_pk_release (pkt->pkt.public_key); break;
    case CDK_PKT_SECRET_KEY   :
    case CDK_PKT_SECRET_SUBKEY: cdk_sk_release (pkt->pkt.secret_key); break;
    case CDK_PKT_SIGNATURE    : _cdk_free_signature (pkt->pkt.signature);break;
    case CDK_PKT_PUBKEY_ENC   : free_pubkey_enc (pkt->pkt.pubkey_enc); break;
    case CDK_PKT_SYMKEY_ENC   : free_symkey_enc (pkt->pkt.symkey_enc); break;
    case CDK_PKT_MDC          : cdk_free (pkt->pkt.mdc); break;
    case CDK_PKT_ENCRYPTED    :
    case CDK_PKT_ENCRYPTED_MDC: free_encrypted (pkt->pkt.encrypted); break;
    case CDK_PKT_ONEPASS_SIG  : cdk_free (pkt->pkt.onepass_sig); break;
    case CDK_PKT_LITERAL      : free_literal (pkt->pkt.literal); break;
    case CDK_PKT_COMPRESSED   : cdk_free (pkt->pkt.compressed); break;
    default                   : break;
    }
  
  /* Reset the packet type to avoid, when cdk_pkt_release() will be
     used, that the second cdk_pkt_free() call will double free the data. */
  pkt->pkttype = 0;
}
Exemplo n.º 2
0
void cdk_sk_release(cdk_seckey_t sk)
{
	size_t nskey;

	if (!sk)
		return;

	nskey = cdk_pk_get_nskey(sk->pubkey_algo);
	_cdk_free_mpibuf(nskey, sk->mpi);
	cdk_free(sk->encdata);
	sk->encdata = NULL;
	cdk_pk_release(sk->pk);
	sk->pk = NULL;
	cdk_s2k_free(sk->protect.s2k);
	sk->protect.s2k = NULL;
	cdk_free(sk);
}
Exemplo n.º 3
0
/**
 * gnutls_openpgp_keyring_check_id:
 * @ring: holds the keyring to check against
 * @keyid: will hold the keyid to check for.
 * @flags: unused (should be 0)
 *
 * Check if a given key ID exists in the keyring.
 *
 * Returns: %GNUTLS_E_SUCCESS on success (if keyid exists) and a
 *   negative error code on failure.
 **/
int
gnutls_openpgp_keyring_check_id(gnutls_openpgp_keyring_t ring,
				const gnutls_openpgp_keyid_t keyid,
				unsigned int flags)
{
	cdk_pkt_pubkey_t pk;
	uint32_t id[2];

	id[0] = _gnutls_read_uint32(keyid);
	id[1] = _gnutls_read_uint32(&keyid[4]);

	if (!cdk_keydb_get_pk(ring->db, id, &pk)) {
		cdk_pk_release(pk);
		return 0;
	}

	_gnutls_debug_log("PGP: key not found %08lX\n",
			  (unsigned long) id[1]);
	return GNUTLS_E_NO_CERTIFICATE_FOUND;
}