]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Bugfix 457: add two functions to use EVP_PKEY_assign_DSA and EVP_PKEY_assign_RSA...
authorWillem Toorop <willem@NLnetLabs.nl>
Fri, 13 Jul 2012 08:35:57 +0000 (08:35 +0000)
committerWillem Toorop <willem@NLnetLabs.nl>
Fri, 13 Jul 2012 08:35:57 +0000 (08:35 +0000)
* ldns_key_assign_dsa_key
* ldns_key_assign_rsa_key
and use those in ldns_key_new_frm_algorithm.

keys.c
ldns/keys.h
ldns_symbols.def

diff --git a/keys.c b/keys.c
index ed7f5e901c801e81ffcf2504a49672c192d3686a..9b82efdfeb0142d0655f94448074aa43dfa3388c 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -431,8 +431,7 @@ ldns_key_new_frm_fp_l(ldns_key **key, FILE *fp, int *line_nr)
                                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:
@@ -444,8 +443,7 @@ ldns_key_new_frm_fp_l(ldns_key **key, FILE *fp, int *line_nr)
                                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:
@@ -1007,6 +1005,22 @@ ldns_key_set_dsa_key(ldns_key *k, DSA *d)
        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 */
 
index c4bf536911f1b367a605f062727b98e06de29a37..089b55cffad1e074e4093730c5f480ababcf7350 100644 (file)
@@ -299,18 +299,37 @@ void ldns_key_set_algorithm(ldns_key *k, ldns_signing_algorithm l);
 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.
index 1ed0f9e213744e9f937db04601687f4e02443c45..9a1fe72bee0b95cf11c630ae45094a7f07266179 100644 (file)
@@ -201,6 +201,8 @@ ldns_key2rr
 ldns_key2str
 ldns_key_algorithm
 ldns_key_algo_supported
+ldns_key_assign_dsa_key
+ldns_key_assign_rsa_key
 ldns_key_buf2dsa
 ldns_key_buf2dsa_raw
 ldns_key_buf2rsa