Add krb5_enctype_to_name() API
authorGreg Hudson <ghudson@mit.edu>
Fri, 4 Jun 2010 18:33:26 +0000 (18:33 +0000)
committerGreg Hudson <ghudson@mit.edu>
Fri, 4 Jun 2010 18:33:26 +0000 (18:33 +0000)
Add an API to return the input name, or optionally the shortest alias,
of an enctype.  Similar to krb5_enctype_to_string() which returns a
description.

ticket: 6736

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24117 dc483132-0cff-0310-8789-dd5450dbe970

src/include/krb5/krb5.hin
src/lib/crypto/krb/enctype_util.c
src/lib/crypto/krb/etypes.h
src/lib/crypto/libk5crypto.exports

index 18097f236ae5078c18845c08fc0f8134102bb66c..22a2a24e8c91a690221e5c80563f265031ce8ca4 100644 (file)
@@ -2156,6 +2156,8 @@ krb5_error_code KRB5_CALLCONV krb5_string_to_timestamp(char *,
 krb5_error_code KRB5_CALLCONV krb5_string_to_deltat(char *, krb5_deltat *);
 krb5_error_code KRB5_CALLCONV krb5_enctype_to_string(krb5_enctype, char *,
                                                      size_t);
+krb5_error_code KRB5_CALLCONV krb5_enctype_to_name(krb5_enctype, krb5_boolean,
+                                                   char *, size_t);
 krb5_error_code KRB5_CALLCONV krb5_salttype_to_string(krb5_int32, char *,
                                                       size_t);
 krb5_error_code KRB5_CALLCONV krb5_cksumtype_to_string(krb5_cksumtype, char *,
index dd1a388abc3e3fe51b6c4ecdc28a00f42c024346..1a9caf667fb5424c8022e2c9711f9ba6827e2293 100644 (file)
@@ -81,8 +81,7 @@ krb5_string_to_enctype(char *string, krb5_enctype *enctypep)
             *enctypep = ktp->etype;
             return 0;
         }
-#define MAX_ALIASES (sizeof(ktp->aliases) / sizeof(ktp->aliases[0]))
-        for (j = 0; j < MAX_ALIASES; j++) {
+        for (j = 0; j < MAX_ETYPE_ALIASES; j++) {
             alias = ktp->aliases[j];
             if (alias == NULL)
                 break;
@@ -108,3 +107,28 @@ krb5_enctype_to_string(krb5_enctype enctype, char *buffer, size_t buflen)
         return ENOMEM;
     return 0;
 }
+
+krb5_error_code KRB5_CALLCONV
+krb5_enctype_to_name(krb5_enctype enctype, krb5_boolean shortest,
+                     char *buffer, size_t buflen)
+{
+    const struct krb5_keytypes *ktp;
+    const char *name;
+    int i;
+
+    ktp = find_enctype(enctype);
+    if (ktp == NULL)
+        return EINVAL;
+    name = ktp->name;
+    if (shortest) {
+        for (i = 0; i < MAX_ETYPE_ALIASES; i++) {
+            if (ktp->aliases[i] == NULL)
+                break;
+            if (strlen(ktp->aliases[i]) < strlen(name))
+                name = ktp->aliases[i];
+        }
+    }
+    if (strlcpy(buffer, name, buflen) >= buflen)
+        return ENOMEM;
+    return 0;
+}
index be737cb50a4ec2c7a026d84a383b3c67b3f0c4a7..a45a6c7712ebc169da606f8f47098d0f8ebe8f97 100644 (file)
@@ -30,6 +30,8 @@
 
 #include "k5-int.h"
 
+#define MAX_ETYPE_ALIASES 2
+
 struct krb5_keytypes;
 
 typedef unsigned int (*crypto_length_func)(const struct krb5_keytypes *ktp,
@@ -53,7 +55,7 @@ typedef krb5_error_code (*prf_func)(const struct krb5_keytypes *ktp,
 struct krb5_keytypes {
     krb5_enctype etype;
     char *name;
-    char *aliases[2];
+    char *aliases[MAX_ETYPE_ALIASES];
     char *out_string;
     const struct krb5_enc_provider *enc;
     const struct krb5_hash_provider *hash;
index b6d7353be8d198db9ba3ef1c62384bd4789fb2d0..ffc824818e20a7fb568086fde078e26fa9229461 100644 (file)
@@ -47,6 +47,7 @@ krb5_c_enctype_compare
 krb5_c_verify_checksum_iov
 valid_enctype
 krb5_enctype_to_string
+krb5_enctype_to_name
 krb5_c_make_checksum_iov
 krb5_calculate_checksum
 krb5_c_string_to_key