From: Greg Hudson Date: Thu, 29 Oct 2009 23:00:13 +0000 (+0000) Subject: Add a couple of krb5_data convenience constructor functions, to X-Git-Tag: krb5-1.8-alpha1~244 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cb01682747845d1852c82c0d567765b6babd70e8;p=krb5.git Add a couple of krb5_data convenience constructor functions, to facilitate properly initializing krb5_data objects. Adjust formatting of the existing krb5_data convenience functions and remove the #if 0 block. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23092 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/include/k5-int.h b/src/include/k5-int.h index e6f84562e..f6f091fcc 100644 --- a/src/include/k5-int.h +++ b/src/include/k5-int.h @@ -2952,37 +2952,44 @@ krb5int_build_principal_alloc_va(krb5_context context, va_list ap); /* Some data comparison and conversion functions. */ -#if 0 -static inline int data_cmp(krb5_data d1, krb5_data d2) -{ - if (d1.length < d2.length) return -1; - if (d1.length > d2.length) return 1; - return memcmp(d1.data, d2.data, d1.length); -} -static inline int data_eq (krb5_data d1, krb5_data d2) -{ - return data_cmp(d1, d2) == 0; -} -#else -static inline int data_eq (krb5_data d1, krb5_data d2) +static inline int +data_eq(krb5_data d1, krb5_data d2) { return (d1.length == d2.length && !memcmp(d1.data, d2.data, d1.length)); } -#endif -static inline krb5_data string2data (char *str) + +static inline krb5_data +make_data(void *data, unsigned int len) { krb5_data d; + d.magic = KV5M_DATA; - d.length = strlen(str); - d.data = str; + d.data = data; + d.length = len; return d; } -static inline int data_eq_string (krb5_data d, char *s) + +static inline krb5_data +empty_data() +{ + return make_data(NULL, 0); +} + +static inline krb5_data +string2data(char *str) +{ + return make_data(str, strlen(str)); +} + +static inline int +data_eq_string (krb5_data d, char *s) { return data_eq(d, string2data(s)); } -static inline int authdata_eq (krb5_authdata a1, krb5_authdata a2) + +static inline int +authdata_eq(krb5_authdata a1, krb5_authdata a2) { return (a1.ad_type == a2.ad_type && a1.length == a2.length