changeset 20398:cf3bb56f9ce9

lib-dcrypt: dcrypt_key_convert_private_to_public() can no longer fail. Removed unnecessary failure handling.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sun, 19 Jun 2016 21:20:27 +0300
parents 4852054b2ba4
children 0798860710f7
files src/lib-dcrypt/dcrypt-openssl.c src/lib-dcrypt/dcrypt-private.h src/lib-dcrypt/dcrypt.c src/lib-dcrypt/dcrypt.h src/lib-dcrypt/test-crypto.c
diffstat 5 files changed, 15 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-dcrypt/dcrypt-openssl.c	Sun Jun 19 20:55:19 2016 +0300
+++ b/src/lib-dcrypt/dcrypt-openssl.c	Sun Jun 19 21:20:27 2016 +0300
@@ -107,8 +107,6 @@
 };
 
 static
-bool dcrypt_openssl_private_to_public_key(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key, const char **error_r);
-static
 bool dcrypt_openssl_public_key_id(struct dcrypt_public_key *key, const char *algorithm, buffer_t *result, const char **error_r);
 static
 bool dcrypt_openssl_public_key_id_old(struct dcrypt_public_key *key, buffer_t *result, const char **error_r);
@@ -117,7 +115,7 @@
 static
 bool dcrypt_openssl_private_key_id_old(struct dcrypt_private_key *key, buffer_t *result, const char **error_r);
 static
-bool dcrypt_openssl_private_to_public_key(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key_r, const char **error_r ATTR_UNUSED);
+void dcrypt_openssl_private_to_public_key(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key_r);
 static
 void dcrypt_openssl_free_private_key(struct dcrypt_private_key **key);
 static
@@ -714,7 +712,8 @@
 	if (kind == DCRYPT_KEY_RSA) {
 		if (dcrypt_openssl_generate_rsa_key(bits, &pkey, error_r)) {
 			pair_r->priv = (struct dcrypt_private_key*)pkey;
-			return dcrypt_openssl_private_to_public_key(pair_r->priv, &(pair_r->pub), error_r);
+			dcrypt_openssl_private_to_public_key(pair_r->priv, &(pair_r->pub));
+			return TRUE;
 		} else return dcrypt_openssl_error(error_r);
 	} else if (kind == DCRYPT_KEY_EC) {
 		int nid = OBJ_sn2nid(curve);
@@ -725,7 +724,8 @@
 		}
 		if (dcrypt_openssl_generate_ec_key(nid, &pkey, error_r)) {
 			pair_r->priv = (struct dcrypt_private_key*)pkey;
-			return dcrypt_openssl_private_to_public_key(pair_r->priv, &(pair_r->pub), error_r);
+			dcrypt_openssl_private_to_public_key(pair_r->priv, &(pair_r->pub));
+			return TRUE;
 		} else return dcrypt_openssl_error(error_r);
 	}
 	if (error_r != NULL)
@@ -1021,8 +1021,8 @@
 		buffer_t *data = buffer_create_dynamic(pool_datastack_create(), 128);
 
 		/* check that we have correct decryption key */
-		if (!dcrypt_openssl_private_to_public_key(dec_key, &pubkey, error_r) ||
-		    !dcrypt_openssl_public_key_id(pubkey, "sha256", data, error_r)) {
+		dcrypt_openssl_private_to_public_key(dec_key, &pubkey);
+		if (!dcrypt_openssl_public_key_id(pubkey, "sha256", data, error_r)) {
 			if (pubkey != NULL) dcrypt_openssl_free_public_key(&pubkey);
 			return FALSE;
 		}
@@ -1619,7 +1619,7 @@
 }
 
 static
-bool dcrypt_openssl_private_to_public_key(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key_r, const char **error_r)
+void dcrypt_openssl_private_to_public_key(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key_r)
 {
 	EVP_PKEY *pkey = (EVP_PKEY*)priv_key;
 	EVP_PKEY *pk;
@@ -1643,7 +1643,6 @@
 	}
 
 	*pub_key_r = (struct dcrypt_public_key*)pk;
-	return TRUE;
 }
 
 static
--- a/src/lib-dcrypt/dcrypt-private.h	Sun Jun 19 20:55:19 2016 +0300
+++ b/src/lib-dcrypt/dcrypt-private.h	Sun Jun 19 21:20:27 2016 +0300
@@ -72,7 +72,7 @@
 		const char *password, struct dcrypt_public_key *enc_key, const char **error_r);
 	bool (*store_public_key)(struct dcrypt_public_key *key, enum dcrypt_key_format format, buffer_t *destination, const char **error_r);
 
-	bool (*private_to_public_key)(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key_r, const char **error_r);
+	void (*private_to_public_key)(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key_r);
 
 	bool (*key_string_get_info)(const char *key_data, enum dcrypt_key_format *format_r, enum dcrypt_key_version *version_r,
 		enum dcrypt_key_kind *kind_r, enum dcrypt_key_encryption_type *encryption_type_r, const char **encryption_key_hash_r,
--- a/src/lib-dcrypt/dcrypt.c	Sun Jun 19 20:55:19 2016 +0300
+++ b/src/lib-dcrypt/dcrypt.c	Sun Jun 19 21:20:27 2016 +0300
@@ -218,9 +218,9 @@
 	return dcrypt_vfs->store_public_key(key, format, destination, error_r);
 }
 
-bool dcrypt_key_convert_private_to_public(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key_r, const char **error_r)
+void dcrypt_key_convert_private_to_public(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key_r)
 {
-	return dcrypt_vfs->private_to_public_key(priv_key, pub_key_r, error_r);
+	dcrypt_vfs->private_to_public_key(priv_key, pub_key_r);
 }
 bool dcrypt_key_string_get_info(const char *key_data, enum dcrypt_key_format *format_r, enum dcrypt_key_version *version_r,
 	enum dcrypt_key_kind *kind_r, enum dcrypt_key_encryption_type *encryption_type_r, const char **encryption_key_hash_r,
--- a/src/lib-dcrypt/dcrypt.h	Sun Jun 19 20:55:19 2016 +0300
+++ b/src/lib-dcrypt/dcrypt.h	Sun Jun 19 21:20:27 2016 +0300
@@ -182,7 +182,7 @@
 
 bool dcrypt_key_store_public(struct dcrypt_public_key *key, enum dcrypt_key_format format, buffer_t *destination, const char **error_r);
 
-bool dcrypt_key_convert_private_to_public(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key_r, const char **error_r);
+void dcrypt_key_convert_private_to_public(struct dcrypt_private_key *priv_key, struct dcrypt_public_key **pub_key_r);
 
 void dcrypt_keypair_free(struct dcrypt_keypair *keypair);
 
--- a/src/lib-dcrypt/test-crypto.c	Sun Jun 19 20:55:19 2016 +0300
+++ b/src/lib-dcrypt/test-crypto.c	Sun Jun 19 21:20:27 2016 +0300
@@ -204,7 +204,7 @@
 		buffer_set_used_size(key_1, 0);
 		/* check that key_id matches */
 		struct dcrypt_public_key *pubkey = NULL;
-		dcrypt_key_convert_private_to_public(pkey, &pubkey, &error);
+		dcrypt_key_convert_private_to_public(pkey, &pubkey);
 		dcrypt_key_store_public(pubkey, DCRYPT_FORMAT_DOVECOT, key_1, NULL);
 		buffer_set_used_size(key_1, 0);
 		dcrypt_key_id_public(pubkey, "sha256", key_1, &error);
@@ -218,7 +218,7 @@
 			buffer_set_used_size(key_1, 0);
 			/* check that key_id matches */
 			struct dcrypt_public_key *pubkey = NULL;
-			dcrypt_key_convert_private_to_public(pkey2, &pubkey, &error);
+			dcrypt_key_convert_private_to_public(pkey2, &pubkey);
 			dcrypt_key_store_public(pubkey, DCRYPT_FORMAT_DOVECOT, key_1, NULL);
 			buffer_set_used_size(key_1, 0);
 			dcrypt_key_id_public_old(pubkey, key_1, &error);
@@ -270,7 +270,7 @@
 	dcrypt_key_free_private(&priv);
 
 	struct dcrypt_public_key *pub = NULL;
-	test_assert_idx(dcrypt_key_convert_private_to_public(priv2, &pub, &error), 3);
+	dcrypt_key_convert_private_to_public(priv2, &pub);
 	test_assert_idx(dcrypt_key_load_private(&priv, DCRYPT_FORMAT_DOVECOT, keys[3], NULL, priv2, &error), 3);
 	test_assert_idx(dcrypt_key_store_private(priv, DCRYPT_FORMAT_DOVECOT, "ecdh-aes-256-ctr", tmp, NULL, pub, &error), 3);
 	buffer_set_used_size(tmp, 0);