svn rev #24117: trunk/src/ include/krb5/ lib/crypto/ lib/crypto/krb/

ghudson@MIT.EDU ghudson at MIT.EDU
Fri Jun 4 14:33:27 EDT 2010


http://src.mit.edu/fisheye/changelog/krb5/?cs=24117
Commit By: ghudson
Log Message:
ticket: 6736
subject: Add krb5_enctype_to_name() API

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.



Changed Files:
U   trunk/src/include/krb5/krb5.hin
U   trunk/src/lib/crypto/krb/enctype_util.c
U   trunk/src/lib/crypto/krb/etypes.h
U   trunk/src/lib/crypto/libk5crypto.exports
Modified: trunk/src/include/krb5/krb5.hin
===================================================================
--- trunk/src/include/krb5/krb5.hin	2010-06-03 17:07:01 UTC (rev 24116)
+++ trunk/src/include/krb5/krb5.hin	2010-06-04 18:33:26 UTC (rev 24117)
@@ -2156,6 +2156,8 @@
 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 *,

Modified: trunk/src/lib/crypto/krb/enctype_util.c
===================================================================
--- trunk/src/lib/crypto/krb/enctype_util.c	2010-06-03 17:07:01 UTC (rev 24116)
+++ trunk/src/lib/crypto/krb/enctype_util.c	2010-06-04 18:33:26 UTC (rev 24117)
@@ -81,8 +81,7 @@
             *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 @@
         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;
+}

Modified: trunk/src/lib/crypto/krb/etypes.h
===================================================================
--- trunk/src/lib/crypto/krb/etypes.h	2010-06-03 17:07:01 UTC (rev 24116)
+++ trunk/src/lib/crypto/krb/etypes.h	2010-06-04 18:33:26 UTC (rev 24117)
@@ -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 @@
 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;

Modified: trunk/src/lib/crypto/libk5crypto.exports
===================================================================
--- trunk/src/lib/crypto/libk5crypto.exports	2010-06-03 17:07:01 UTC (rev 24116)
+++ trunk/src/lib/crypto/libk5crypto.exports	2010-06-04 18:33:26 UTC (rev 24117)
@@ -47,6 +47,7 @@
 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




More information about the cvs-krb5 mailing list