From c31a3767978104c6415f2d69b9aaf9300bf98606 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Sat, 11 Feb 2012 23:25:04 +0000 Subject: [PATCH] Fold atype_primitive into atype_fn atype_primitive is used for only two types (KerberosTime and KerberosFlags), which doesn't justify the machinery. Turn those types into atype_fn types and get rid of atype_primitive. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25687 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/asn.1/asn1_encode.c | 10 -------- src/lib/krb5/asn.1/asn1_encode.h | 38 ++---------------------------- src/lib/krb5/asn.1/asn1_k_encode.c | 26 ++++++++++---------- 3 files changed, 16 insertions(+), 58 deletions(-) diff --git a/src/lib/krb5/asn.1/asn1_encode.c b/src/lib/krb5/asn.1/asn1_encode.c index 7385cfa63..e53feea7e 100644 --- a/src/lib/krb5/asn.1/asn1_encode.c +++ b/src/lib/krb5/asn.1/asn1_encode.c @@ -325,16 +325,6 @@ krb5int_asn1_encode_type(asn1buf *buf, const void *val, return ASN1_MISSING_FIELD; switch (a->type) { - case atype_primitive: { - const struct primitive_info *prim = a->tinfo; - assert(prim->enc != NULL); - retval = prim->enc(buf, val, &rettag->length); - if (retval) return retval; - rettag->asn1class = UNIVERSAL; - rettag->construction = PRIMITIVE; - rettag->tagnum = prim->tagval; - break; - } case atype_fn: { const struct fn_info *fn = a->tinfo; assert(fn->enc != NULL); diff --git a/src/lib/krb5/asn.1/asn1_encode.h b/src/lib/krb5/asn.1/asn1_encode.h index c68b3832f..a5e2aef72 100644 --- a/src/lib/krb5/asn.1/asn1_encode.h +++ b/src/lib/krb5/asn.1/asn1_encode.h @@ -139,13 +139,9 @@ enum atype_type { * invalid. */ atype_min = 1, - /* Encoder function (contents-only) to be called with address of - * and wrapped with a universal primitive tag. tinfo is a struct - * primitive_info *. */ - atype_primitive, /* * Encoder function to be called with address of . tinfo is a - * struct fn_info *. Used only by kdc_req_body. + * struct fn_info *. */ atype_fn, /* Pointer to actual thing to be encoded. tinfo is a struct ptr_info *. */ @@ -188,11 +184,6 @@ struct atype_info { const void *tinfo; /* Points to type-specific structure */ }; -struct primitive_info { - asn1_error_code (*enc)(asn1buf *, const void *, unsigned int *); - unsigned int tagval; -}; - struct fn_info { asn1_error_code (*enc)(asn1buf *, const void *, taginfo *); }; @@ -284,32 +275,7 @@ struct choice_info { * Nothing else should directly define the atype_info structures. */ -/* - * Define a type using a primitive (content-only) encoder function. - * - * Because we need a single, consistent type for the descriptor structure - * field, we use the function pointer type that uses void*, and create a - * wrapper function in DEFFNXTYPE. The supplied function is static and not - * used otherwise, so the compiler can merge it with the wrapper function if - * the optimizer is good enough. - */ -#define DEFPRIMITIVETYPE(DESCNAME, CTYPENAME, ENCFN, TAG) \ - typedef CTYPENAME aux_typedefname_##DESCNAME; \ - static asn1_error_code \ - aux_encfn_##DESCNAME(asn1buf *buf, const void *val, \ - unsigned int *retlen) \ - { \ - return ENCFN(buf, \ - (const aux_typedefname_##DESCNAME *)val, \ - retlen); \ - } \ - static const struct primitive_info aux_info_##DESCNAME = { \ - aux_encfn_##DESCNAME, TAG \ - }; \ - const struct atype_info k5_atype_##DESCNAME = { \ - atype_primitive, sizeof(CTYPENAME), &aux_info_##DESCNAME \ - } -/* Define a type using an explicit (with tag) encoder function. */ +/* Define a type using an encoder function. */ #define DEFFNTYPE(DESCNAME, CTYPENAME, ENCFN) \ typedef CTYPENAME aux_typedefname_##DESCNAME; \ static const struct fn_info aux_info_##DESCNAME = { \ diff --git a/src/lib/krb5/asn.1/asn1_k_encode.c b/src/lib/krb5/asn.1/asn1_k_encode.c index 80c7fb13b..1db2f5748 100644 --- a/src/lib/krb5/asn.1/asn1_k_encode.c +++ b/src/lib/krb5/asn.1/asn1_k_encode.c @@ -70,15 +70,16 @@ DEFSEQTYPE(principal_data, krb5_principal_data, princname_fields, NULL); DEFPTRTYPE(principal, principal_data); static asn1_error_code -asn1_encode_kerberos_time_at(asn1buf *buf, const krb5_timestamp *val, - unsigned int *retlen) +encode_kerberos_time(asn1buf *buf, const void *val, taginfo *rettag) { /* Range checking for time_t vs krb5_timestamp? */ - time_t tval = *val; - return asn1_encode_generaltime(buf, tval, retlen); + time_t tval = *(krb5_timestamp *)val; + rettag->asn1class = UNIVERSAL; + rettag->construction = PRIMITIVE; + rettag->tagnum = ASN1_GENERALTIME; + return asn1_encode_generaltime(buf, tval, &rettag->length); } -DEFPRIMITIVETYPE(kerberos_time, krb5_timestamp, asn1_encode_kerberos_time_at, - ASN1_GENERALTIME); +DEFFNTYPE(kerberos_time, krb5_timestamp, encode_kerberos_time); DEFFIELD(address_0, krb5_address, addrtype, 0, int32); DEFCNFIELD(address_1, krb5_address, contents, length, 1, octetstring); @@ -115,15 +116,16 @@ DEFSEQTYPE(encrypted_data, krb5_enc_data, encrypted_data_fields, * as a 32-bit integer in host order. */ static asn1_error_code -asn1_encode_krb5_flags_at(asn1buf *buf, const krb5_flags *val, - unsigned int *retlen) +encode_krb5_flags(asn1buf *buf, const void *val, taginfo *rettag) { unsigned char cbuf[4], *cptr = cbuf; - store_32_be((krb5_ui_4) *val, cbuf); - return asn1_encode_bitstring(buf, &cptr, 4, retlen); + store_32_be((krb5_ui_4)*(const krb5_flags *)val, cbuf); + rettag->asn1class = UNIVERSAL; + rettag->construction = PRIMITIVE; + rettag->tagnum = ASN1_BITSTRING; + return asn1_encode_bitstring(buf, &cptr, 4, &rettag->length); } -DEFPRIMITIVETYPE(krb5_flags, krb5_flags, asn1_encode_krb5_flags_at, - ASN1_BITSTRING); +DEFFNTYPE(krb5_flags, krb5_flags, encode_krb5_flags); DEFFIELD(authdata_0, krb5_authdata, ad_type, 0, int32); DEFCNFIELD(authdata_1, krb5_authdata, contents, length, 1, octetstring); -- 2.26.2