From: Greg Hudson Date: Fri, 4 Jun 2010 18:33:26 +0000 (+0000) Subject: Add krb5_enctype_to_name() API X-Git-Tag: krb5-1.9-beta1~204 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=91c7788e903744318a70982f50b69187db9a9914;p=krb5.git 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. ticket: 6736 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24117 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/include/krb5/krb5.hin b/src/include/krb5/krb5.hin index 18097f236..22a2a24e8 100644 --- a/src/include/krb5/krb5.hin +++ b/src/include/krb5/krb5.hin @@ -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 *, diff --git a/src/lib/crypto/krb/enctype_util.c b/src/lib/crypto/krb/enctype_util.c index dd1a388ab..1a9caf667 100644 --- a/src/lib/crypto/krb/enctype_util.c +++ b/src/lib/crypto/krb/enctype_util.c @@ -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; +} diff --git a/src/lib/crypto/krb/etypes.h b/src/lib/crypto/krb/etypes.h index be737cb50..a45a6c771 100644 --- a/src/lib/crypto/krb/etypes.h +++ b/src/lib/crypto/krb/etypes.h @@ -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; diff --git a/src/lib/crypto/libk5crypto.exports b/src/lib/crypto/libk5crypto.exports index b6d7353be..ffc824818 100644 --- a/src/lib/crypto/libk5crypto.exports +++ b/src/lib/crypto/libk5crypto.exports @@ -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