ldns_key_free(k);
return LDNS_STATUS_ERR;
}
- ldns_key_set_rsa_key(k, rsa);
- RSA_free(rsa);
+ ldns_key_assign_rsa_key(k, rsa);
#endif /* HAVE_SSL */
break;
case LDNS_SIGN_DSA:
ldns_key_free(k);
return LDNS_STATUS_ERR;
}
- ldns_key_set_dsa_key(k, dsa);
- DSA_free(dsa);
+ ldns_key_assign_dsa_key(k, dsa);
#endif /* HAVE_SSL */
break;
case LDNS_SIGN_HMACMD5:
EVP_PKEY_set1_DSA(key, d);
k->_key.key = key;
}
+
+void
+ldns_key_assign_rsa_key(ldns_key *k, RSA *r)
+{
+ EVP_PKEY *key = EVP_PKEY_new();
+ EVP_PKEY_assign_RSA(key, r);
+ k->_key.key = key;
+}
+
+void
+ldns_key_assign_dsa_key(ldns_key *k, DSA *d)
+{
+ EVP_PKEY *key = EVP_PKEY_new();
+ EVP_PKEY_assign_DSA(key, d);
+ k->_key.key = key;
+}
#endif /* splint */
#endif /* HAVE_SSL */
void ldns_key_set_evp_key(ldns_key *k, EVP_PKEY *e);
/**
- * Set the key's rsa data
+ * Set the key's rsa data.
+ * The rsa data should be freed by the user themselve.
* \param[in] k the key
* \param[in] r the rsa data
*/
void ldns_key_set_rsa_key(ldns_key *k, RSA *r);
+
/**
* Set the key's dsa data
+ * The dsa data should be freed by the user themselve.
* \param[in] k the key
* \param[in] d the dsa data
*/
void ldns_key_set_dsa_key(ldns_key *k, DSA *d);
+/**
+ * Assign the key's rsa data
+ * The rsa data will be freed automatically when the key is freed.
+ * \param[in] k the key
+ * \param[in] r the rsa data
+ */
+void ldns_key_assign_rsa_key(ldns_key *k, RSA *r);
+
+/**
+ * Assign the key's dsa data
+ * The dsa data will be freed automatically when the key is freed.
+ * \param[in] k the key
+ * \param[in] d the dsa data
+ */
+void ldns_key_assign_dsa_key(ldns_key *k, DSA *d);
+
/**
* Get the PKEY id for GOST, loads GOST into openssl as a side effect.
* Only available if GOST is compiled into the library and openssl.