Use centralized hasher names in pki utility
authorMartin Willi <martin@revosec.ch>
Tue, 17 Jul 2012 15:31:02 +0000 (17:31 +0200)
committerMartin Willi <martin@revosec.ch>
Tue, 17 Jul 2012 15:32:05 +0000 (17:32 +0200)
src/pki/commands/issue.c
src/pki/commands/req.c
src/pki/commands/self.c
src/pki/commands/signcrl.c
src/pki/pki.c
src/pki/pki.h

index 4dbe2e0..47e668b 100644 (file)
@@ -105,8 +105,8 @@ static int issue()
                                }
                                continue;
                        case 'g':
-                               digest = get_digest(arg);
-                               if (digest == HASH_UNKNOWN)
+                               digest = enum_from_name(hash_algorithm_short_names, arg);
+                               if (digest == -1)
                                {
                                        error = "invalid --digest type";
                                        goto usage;
index 087a97b..d050c70 100644 (file)
@@ -63,8 +63,8 @@ static int req()
                                }
                                continue;
                        case 'g':
-                               digest = get_digest(arg);
-                               if (digest == HASH_UNKNOWN)
+                               digest = enum_from_name(hash_algorithm_short_names, arg);
+                               if (digest == -1)
                                {
                                        error = "invalid --digest type";
                                        goto usage;
index e98f90f..4a50aa4 100644 (file)
@@ -94,8 +94,8 @@ static int self()
                                }
                                continue;
                        case 'g':
-                               digest = get_digest(arg);
-                               if (digest == HASH_UNKNOWN)
+                               digest = enum_from_name(hash_algorithm_short_names, arg);
+                               if (digest == -1)
                                {
                                        error = "invalid --digest type";
                                        goto usage;
index 153734f..4ada120 100644 (file)
@@ -141,8 +141,8 @@ static int sign_crl()
                        case 'h':
                                goto usage;
                        case 'g':
-                               digest = get_digest(arg);
-                               if (digest == HASH_UNKNOWN)
+                               digest = enum_from_name(hash_algorithm_short_names, arg);
+                               if (digest == -1)
                                {
                                        error = "invalid --digest type";
                                        goto usage;
index 3005d2f..e28bf15 100644 (file)
@@ -80,38 +80,6 @@ bool get_form(char *form, cred_encoding_type_t *enc, credential_type_t type)
 }
 
 /**
- * Convert a digest string to a hash algorithm
- */
-hash_algorithm_t get_digest(char *name)
-{
-       if (streq(name, "md5"))
-       {
-               return HASH_MD5;
-       }
-       if (streq(name, "sha1"))
-       {
-               return HASH_SHA1;
-       }
-       if (streq(name, "sha224"))
-       {
-               return HASH_SHA224;
-       }
-       if (streq(name, "sha256"))
-       {
-               return HASH_SHA256;
-       }
-       if (streq(name, "sha384"))
-       {
-               return HASH_SHA384;
-       }
-       if (streq(name, "sha512"))
-       {
-               return HASH_SHA512;
-       }
-       return HASH_UNKNOWN;
-}
-
-/**
  * Callback credential set pki uses
  */
 static callback_cred_t *cb_set;
index 9c145cd..f72b180 100644 (file)
@@ -31,9 +31,4 @@
  */
 bool get_form(char *form, cred_encoding_type_t *enc, credential_type_t type);
 
-/**
- * Convert a digest string to a hash algorithm
- */
-hash_algorithm_t get_digest(char *name);
-
 #endif /** PKI_H_ @}*/