svn rev #25687: trunk/src/lib/krb5/asn.1/
ghudson@MIT.EDU
ghudson at MIT.EDU
Sat Feb 11 18:25:04 EST 2012
http://src.mit.edu/fisheye/changelog/krb5/?cs=25687
Commit By: ghudson
Log Message:
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.
Changed Files:
U trunk/src/lib/krb5/asn.1/asn1_encode.c
U trunk/src/lib/krb5/asn.1/asn1_encode.h
U trunk/src/lib/krb5/asn.1/asn1_k_encode.c
Modified: trunk/src/lib/krb5/asn.1/asn1_encode.c
===================================================================
--- trunk/src/lib/krb5/asn.1/asn1_encode.c 2012-02-11 23:25:00 UTC (rev 25686)
+++ trunk/src/lib/krb5/asn.1/asn1_encode.c 2012-02-11 23:25:04 UTC (rev 25687)
@@ -325,16 +325,6 @@
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);
Modified: trunk/src/lib/krb5/asn.1/asn1_encode.h
===================================================================
--- trunk/src/lib/krb5/asn.1/asn1_encode.h 2012-02-11 23:25:00 UTC (rev 25686)
+++ trunk/src/lib/krb5/asn.1/asn1_encode.h 2012-02-11 23:25:04 UTC (rev 25687)
@@ -139,13 +139,9 @@
* invalid.
*/
atype_min = 1,
- /* Encoder function (contents-only) to be called with address of <thing>
- * and wrapped with a universal primitive tag. tinfo is a struct
- * primitive_info *. */
- atype_primitive,
/*
* Encoder function to be called with address of <thing>. 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 @@
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 @@
* 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 = { \
Modified: trunk/src/lib/krb5/asn.1/asn1_k_encode.c
===================================================================
--- trunk/src/lib/krb5/asn.1/asn1_k_encode.c 2012-02-11 23:25:00 UTC (rev 25686)
+++ trunk/src/lib/krb5/asn.1/asn1_k_encode.c 2012-02-11 23:25:04 UTC (rev 25687)
@@ -70,15 +70,16 @@
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 @@
* 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);
More information about the cvs-krb5
mailing list