]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
certtool: hash_to_id moved to certtool-common.c
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Fri, 25 Aug 2017 08:33:27 +0000 (10:33 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 27 Aug 2017 13:58:28 +0000 (15:58 +0200)
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
src/certtool-common.c
src/certtool-common.h
src/certtool.c

index 413395926b6d9774982eb3cb3bd3c563055b321e..71de7cf61d6cee7c6e5787c2b81e8c17cb014139 100644 (file)
@@ -1556,3 +1556,34 @@ gnutls_pk_algorithm_t figure_key_type(const char *key_type)
                return GNUTLS_PK_UNKNOWN;
        }
 }
+
+gnutls_digest_algorithm_t hash_to_id(const char *hash)
+{
+       if (strcasecmp(hash, "md5") == 0) {
+               fprintf(stderr,
+                       "Warning: MD5 is broken, and should not be used any more for digital signatures.\n");
+               return GNUTLS_DIG_MD5;
+       } else if (strcasecmp(hash, "sha1") == 0)
+               return GNUTLS_DIG_SHA1;
+       else if (strcasecmp(hash, "sha256") == 0)
+               return GNUTLS_DIG_SHA256;
+       else if (strcasecmp(hash, "sha224") == 0)
+               return GNUTLS_DIG_SHA224;
+       else if (strcasecmp(hash, "sha384") == 0)
+               return GNUTLS_DIG_SHA384;
+       else if (strcasecmp(hash, "sha512") == 0)
+               return GNUTLS_DIG_SHA512;
+       else if (strcasecmp(hash, "sha3-256") == 0)
+               return GNUTLS_DIG_SHA3_256;
+       else if (strcasecmp(hash, "sha3-224") == 0)
+               return GNUTLS_DIG_SHA3_224;
+       else if (strcasecmp(hash, "sha3-384") == 0)
+               return GNUTLS_DIG_SHA3_384;
+       else if (strcasecmp(hash, "sha3-512") == 0)
+               return GNUTLS_DIG_SHA3_512;
+       else if (strcasecmp(hash, "rmd160") == 0)
+               return GNUTLS_DIG_RMD160;
+       else {
+               return gnutls_digest_get_id(hash);
+       }
+}
index f1e926328888b2321adae74044f1e2f41fa3d8b9..1b9255cf5563105c41ae373670d59ef9ba6a58cb 100644 (file)
@@ -174,4 +174,6 @@ void decode_seed(gnutls_datum_t *seed, const char *hex, unsigned hex_size);
 
 gnutls_pk_algorithm_t figure_key_type(const char *key_type);
 
+gnutls_digest_algorithm_t hash_to_id(const char *hash);
+
 #endif
index 97d42870783a6d359e3cc3459106ce716e134903..a8502ec5647dea4564c0b75321391f141bccdf44 100644 (file)
@@ -1250,36 +1250,10 @@ static void cmd_parser(int argc, char **argv)
 
        default_dig = GNUTLS_DIG_UNKNOWN;
        if (HAVE_OPT(HASH)) {
-               if (strcasecmp(OPT_ARG(HASH), "md5") == 0) {
-                       fprintf(stderr,
-                               "Warning: MD5 is broken, and should not be used any more for digital signatures.\n");
-                       default_dig = GNUTLS_DIG_MD5;
-               } else if (strcasecmp(OPT_ARG(HASH), "sha1") == 0)
-                       default_dig = GNUTLS_DIG_SHA1;
-               else if (strcasecmp(OPT_ARG(HASH), "sha256") == 0)
-                       default_dig = GNUTLS_DIG_SHA256;
-               else if (strcasecmp(OPT_ARG(HASH), "sha224") == 0)
-                       default_dig = GNUTLS_DIG_SHA224;
-               else if (strcasecmp(OPT_ARG(HASH), "sha384") == 0)
-                       default_dig = GNUTLS_DIG_SHA384;
-               else if (strcasecmp(OPT_ARG(HASH), "sha512") == 0)
-                       default_dig = GNUTLS_DIG_SHA512;
-               else if (strcasecmp(OPT_ARG(HASH), "sha3-256") == 0)
-                       default_dig = GNUTLS_DIG_SHA3_256;
-               else if (strcasecmp(OPT_ARG(HASH), "sha3-224") == 0)
-                       default_dig = GNUTLS_DIG_SHA3_224;
-               else if (strcasecmp(OPT_ARG(HASH), "sha3-384") == 0)
-                       default_dig = GNUTLS_DIG_SHA3_384;
-               else if (strcasecmp(OPT_ARG(HASH), "sha3-512") == 0)
-                       default_dig = GNUTLS_DIG_SHA3_512;
-               else if (strcasecmp(OPT_ARG(HASH), "rmd160") == 0)
-                       default_dig = GNUTLS_DIG_RMD160;
-               else {
-                       default_dig = gnutls_digest_get_id(OPT_ARG(HASH));
-                       if (default_dig == GNUTLS_DIG_UNKNOWN) {
-                               fprintf(stderr, "invalid hash: %s\n", OPT_ARG(HASH));
-                               app_exit(1);
-                       }
+               default_dig = hash_to_id(OPT_ARG(HASH));
+               if (default_dig == GNUTLS_DIG_UNKNOWN) {
+                       fprintf(stderr, "invalid hash: %s\n", OPT_ARG(HASH));
+                       app_exit(1);
                }
        }