src/lib/crypto.c
X509_KEYPAIR *crypto_keypair_dup(X509_KEYPAIR *keypair)
{
   X509_KEYPAIR *newpair;
   int ret;

   newpair = crypto_keypair_new();

   if (!newpair) {
      /* Allocation failed */
      return NULL;
   }

   /* Increment the public key ref count */
   if (keypair->pubkey) {
      ret = EVP_PKEY_up_ref(keypair->pubkey);
      if (ret == 0)
              goto out_free_new;
      newpair->pubkey = keypair->pubkey;
   }

   /* Increment the private key ref count */
   if (keypair->privkey) {
      ret = EVP_PKEY_up_ref(keypair->privkey);
      if (ret == 0)
              goto out_free_new;
      newpair->privkey = keypair->privkey;
   }

   /* Duplicate the keyid */
   if (keypair->keyid) {
      newpair->keyid = ASN1_OCTET_STRING_dup(keypair->keyid);
      if (!newpair->keyid)
              goto out_free_new;
   }

   return newpair;

out_free_new:
   crypto_keypair_free(newpair);
   return NULL;
}
/*
 * Create a copy of a keypair object. The underlying
 * EVP objects are not duplicated, as no EVP_PKEY_dup()
 * API is available. Instead, the reference count is
 * incremented.
 */
Create a copy of a keypair object. The underlying
EVP objects are not duplicated, as no EVP_PKEY_dup()
API is available. Instead, the reference count is
incremented.
Create a copy of a keypair object . The underlying EVP objects are not duplicated as no EVP_PKEY_dup () API is available . Instead the reference count is incremented .
X509_KEYPAIR *crypto_keypair_dup(X509_KEYPAIR *keypair)
{
   X509_KEYPAIR *newpair;
   int ret;
   newpair = crypto_keypair_new();
   if (!newpair) {
      return NULL;
   }
   if (keypair->pubkey) {
      ret = EVP_PKEY_up_ref(keypair->pubkey);
      if (ret == 0)
              goto out_free_new;
      newpair->pubkey = keypair->pubkey;
   }
   if (keypair->privkey) {
      ret = EVP_PKEY_up_ref(keypair->privkey);
      if (ret == 0)
              goto out_free_new;
      newpair->privkey = keypair->privkey;
   }
   if (keypair->keyid) {
      newpair->keyid = ASN1_OCTET_STRING_dup(keypair->keyid);
      if (!newpair->keyid)
              goto out_free_new;
   }
   return newpair;
out_free_new:
   crypto_keypair_free(newpair);
   return NULL;
}
X509_KEYPAIR * crypto_keypair_dup ( X509_KEYPAIR * keypair ) { X509_KEYPAIR * newpair ; int ret ; newpair = crypto_keypair_new ( ) ; if ( ! newpair ) { return NULL ; } if ( keypair -> pubkey ) { ret = EVP_PKEY_up_ref ( keypair -> pubkey ) ; if ( ret == 0 ) goto out_free_new ; newpair -> pubkey = keypair -> pubkey ; } if ( keypair -> privkey ) { ret = EVP_PKEY_up_ref ( keypair -> privkey ) ; if ( ret == 0 ) goto out_free_new ; newpair -> privkey = keypair -> privkey ; } if ( keypair -> keyid ) { newpair -> keyid = ASN1_OCTET_STRING_dup ( keypair -> keyid ) ; if ( ! newpair -> keyid ) goto out_free_new ; } return newpair ; out_free_new : crypto_keypair_free ( newpair ) ; return NULL ; }
Create a copy of a keypair object.
Create a copy of a keypair object .
/* Allocation failed */ /* Increment the public key ref count */ /* Increment the private key ref count */ /* Duplicate the keyid */