]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dcrypt: dcrypt_key_type_public/private() can no longer fail.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 19 Jun 2016 18:21:56 +0000 (21:21 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 21 Jun 2016 18:43:07 +0000 (21:43 +0300)
Removed unnecessary failure handling.

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/ostream-encrypt.c

index d67d916cc80fd794a879327e6041b04defd4961a..81dcd645163f861345b28f2d0dd50f49890188f9 100644 (file)
@@ -1855,25 +1855,23 @@ bool dcrypt_openssl_name2oid(const char *name, buffer_t *oid, const char **error
 }
 
 static
-bool dcrypt_openssl_private_key_type(struct dcrypt_private_key *key, enum dcrypt_key_type *key_type)
+enum dcrypt_key_type dcrypt_openssl_private_key_type(struct dcrypt_private_key *key)
 {
        EVP_PKEY *priv = (EVP_PKEY*)key;
-       if (priv == NULL) return FALSE;
-       if (EVP_PKEY_base_id(priv) == EVP_PKEY_RSA) *key_type = DCRYPT_KEY_RSA;
-       else if (EVP_PKEY_base_id(priv) == EVP_PKEY_EC) *key_type = DCRYPT_KEY_EC;
+       i_assert(priv != NULL);
+       if (EVP_PKEY_base_id(priv) == EVP_PKEY_RSA) return DCRYPT_KEY_RSA;
+       else if (EVP_PKEY_base_id(priv) == EVP_PKEY_EC) return DCRYPT_KEY_EC;
        else i_unreached();
-       return FALSE;
 }
 
 static
-bool dcrypt_openssl_public_key_type(struct dcrypt_public_key *key, enum dcrypt_key_type *key_type)
+enum dcrypt_key_type dcrypt_openssl_public_key_type(struct dcrypt_public_key *key)
 {
        EVP_PKEY *pub = (EVP_PKEY*)key;
-       if (pub == NULL) return FALSE;
-       if (EVP_PKEY_base_id(pub) == EVP_PKEY_RSA) *key_type = DCRYPT_KEY_RSA;
-       else if (EVP_PKEY_base_id(pub) == EVP_PKEY_EC) *key_type = DCRYPT_KEY_EC;
+       i_assert(pub != NULL);
+       if (EVP_PKEY_base_id(pub) == EVP_PKEY_RSA) return DCRYPT_KEY_RSA;
+       else if (EVP_PKEY_base_id(pub) == EVP_PKEY_EC) return DCRYPT_KEY_EC;
        else i_unreached();
-       return FALSE;
 }
 
 /** this is the v1 old legacy way of doing key id's **/
index 06aa47809c133724d318099e523e5483ee21ea1d..5e4a60d14c286ab042502eba2dc4e7ed9c39e305 100644 (file)
@@ -90,8 +90,8 @@ struct dcrypt_vfs {
        const char *(*oid2name)(const unsigned char *oid, size_t oid_len, const char **error_r);
        bool (*name2oid)(const char *name, buffer_t *oid, const char **error_r);
 
-       bool (*private_key_type)(struct dcrypt_private_key *key, enum dcrypt_key_type *key_type);
-       bool (*public_key_type)(struct dcrypt_public_key *key, enum dcrypt_key_type *key_type);
+       enum dcrypt_key_type (*private_key_type)(struct dcrypt_private_key *key);
+       enum dcrypt_key_type (*public_key_type)(struct dcrypt_public_key *key);
        bool (*public_key_id)(struct dcrypt_public_key *key, const char *algorithm, buffer_t *result, const char **error_r);
        bool (*public_key_id_old)(struct dcrypt_public_key *key, buffer_t *result, const char **error_r);
        bool (*private_key_id)(struct dcrypt_private_key *key, const char *algorithm, buffer_t *result, const char **error_r);
index 1801ae84797bfd492f5b12e11d158b8a749a0598..a6845ad4e4567d8aa41a2199716e225d953b29e7 100644 (file)
@@ -230,13 +230,13 @@ bool dcrypt_key_string_get_info(const char *key_data, enum dcrypt_key_format *fo
                encryption_key_hash_r, key_hash_r, error_r);
 }
 
-bool dcrypt_key_type_private(struct dcrypt_private_key *key, enum dcrypt_key_type *type)
+enum dcrypt_key_type dcrypt_key_type_private(struct dcrypt_private_key *key)
 {
-       return dcrypt_vfs->private_key_type(key, type);
+       return dcrypt_vfs->private_key_type(key);
 }
-bool dcrypt_key_type_public(struct dcrypt_public_key *key, enum dcrypt_key_type *type)
+enum dcrypt_key_type dcrypt_key_type_public(struct dcrypt_public_key *key)
 {
-       return dcrypt_vfs->public_key_type(key, type);
+       return dcrypt_vfs->public_key_type(key);
 }
 bool dcrypt_key_id_public(struct dcrypt_public_key *key, const char *algorithm, buffer_t *result, const char **error_r)
 {
index 89e6027dee4d59938a33f31246453f0b3317a73f..f6d3e44ed649ddc20554ffb7d801bd5b0afc7f16 100644 (file)
@@ -189,8 +189,8 @@ void dcrypt_keypair_free(struct dcrypt_keypair *keypair);
 void dcrypt_key_free_public(struct dcrypt_public_key **key);
 void dcrypt_key_free_private(struct dcrypt_private_key **key);
 
-bool dcrypt_key_type_private(struct dcrypt_private_key *key, enum dcrypt_key_type *type);
-bool dcrypt_key_type_public(struct dcrypt_public_key *key, enum dcrypt_key_type *type);
+enum dcrypt_key_type dcrypt_key_type_private(struct dcrypt_private_key *key);
+enum dcrypt_key_type dcrypt_key_type_public(struct dcrypt_public_key *key);
 bool dcrypt_key_id_public(struct dcrypt_public_key *key, const char *algorithm, buffer_t *result, const char **error_r); /* return digest of key */
 bool dcrypt_key_id_public_old(struct dcrypt_public_key *key, buffer_t *result, const char **error_r); /* return SHA1 sum of key */
 bool dcrypt_key_id_private(struct dcrypt_private_key *key, const char *algorithm, buffer_t *result, const char **error_r); /* return digest of key */
index 70e69d3fb7b448f45e1996a01f529e5ae9082492..0569253a0ca8a948f7bdf41e1c149ba664526787 100644 (file)
@@ -258,7 +258,7 @@ int o_stream_encrypt_key_for_pubkey_v2(struct encrypt_ostream *stream, const cha
        encrypted_key = buffer_create_dynamic(pool_datastack_create(), 256);
        temp_key = buffer_create_dynamic(pool_datastack_create(), 48);
 
-       dcrypt_key_type_public(pubkey, &ktype);
+       ktype = dcrypt_key_type_public(pubkey);
 
        if (ktype == DCRYPT_KEY_RSA) {
                /* encrypt key as R (as we don't need DH with RSA)*/