From c28759e489ff78d60b33248f7658689125bd0492 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Fri, 18 Apr 2014 12:15:48 +0000 Subject: More KNF. --- src/lib/libcrypto/asn1/tasn_utl.c | 68 ++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 26 deletions(-) (limited to 'src/lib/libcrypto/asn1/tasn_utl.c') diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c index 9715dac931..e1051c2c3e 100644 --- a/src/lib/libcrypto/asn1/tasn_utl.c +++ b/src/lib/libcrypto/asn1/tasn_utl.c @@ -10,7 +10,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -56,7 +56,6 @@ * */ - #include #include #include @@ -73,7 +72,8 @@ * the selector value */ -int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) +int +asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) { int *sel = offset2ptr(*pval, it->utype); return *sel; @@ -83,8 +83,9 @@ int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) * the selector value, return old value. */ -int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) -{ +int +asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) +{ int *sel, ret; sel = offset2ptr(*pval, it->utype); ret = *sel; @@ -92,18 +93,20 @@ int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) return ret; } -/* Do reference counting. The value 'op' decides what to do. +/* Do reference counting. The value 'op' decides what to do. * if it is +1 then the count is incremented. If op is 0 count is * set to 1. If op is -1 count is decremented and the return value * is the current refrence count or 0 if no reference count exists. */ -int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) +int +asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) { const ASN1_AUX *aux; int *lck, ret; - if ((it->itype != ASN1_ITYPE_SEQUENCE) - && (it->itype != ASN1_ITYPE_NDEF_SEQUENCE)) + + if ((it->itype != ASN1_ITYPE_SEQUENCE) && + (it->itype != ASN1_ITYPE_NDEF_SEQUENCE)) return 0; aux = it->funcs; if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) @@ -117,9 +120,11 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) return ret; } -static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) +static ASN1_ENCODING * +asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) { const ASN1_AUX *aux; + if (!pval || !*pval) return NULL; aux = it->funcs; @@ -128,9 +133,11 @@ static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) return offset2ptr(*pval, aux->enc_offset); } -void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) +void +asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) { ASN1_ENCODING *enc; + enc = asn1_get_enc_ptr(pval, it); if (enc) { enc->enc = NULL; @@ -139,9 +146,11 @@ void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) } } -void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) +void +asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) { ASN1_ENCODING *enc; + enc = asn1_get_enc_ptr(pval, it); if (enc) { if (enc->enc) @@ -152,10 +161,12 @@ void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) } } -int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, - const ASN1_ITEM *it) +int +asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, + const ASN1_ITEM *it) { ASN1_ENCODING *enc; + enc = asn1_get_enc_ptr(pval, it); if (!enc) return 1; @@ -171,11 +182,13 @@ int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, return 1; } - -int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, - const ASN1_ITEM *it) + +int +asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, + const ASN1_ITEM *it) { ASN1_ENCODING *enc; + enc = asn1_get_enc_ptr(pval, it); if (!enc || enc->modified) return 0; @@ -189,9 +202,11 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, } /* Given an ASN1_TEMPLATE get a pointer to a field */ -ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) +ASN1_VALUE ** +asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) { ASN1_VALUE **pvaltmp; + if (tt->flags & ASN1_TFLG_COMBINE) return pval; pvaltmp = offset2ptr(*pval, tt->offset); @@ -206,14 +221,15 @@ ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) * the relevant ASN1_TEMPLATE in the table and return it. */ -const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, - int nullerr) +const ASN1_TEMPLATE * +asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr) { const ASN1_ADB *adb; const ASN1_ADB_TABLE *atbl; long selector; ASN1_VALUE **sfld; int i; + if (!(tt->flags & ASN1_TFLG_ADB_MASK)) return tt; @@ -234,9 +250,9 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, * NB: don't check for NID_undef here because it * might be a legitimate value in the table */ - if (tt->flags & ASN1_TFLG_ADB_OID) + if (tt->flags & ASN1_TFLG_ADB_OID) selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld); - else + else selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld); /* Try to find matching entry in table @@ -255,13 +271,13 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, /* No match, return default type */ if (!adb->default_tt) - goto err; + goto err; return adb->default_tt; - - err: + +err: /* FIXME: should log the value or OID of unsupported type */ if (nullerr) ASN1err(ASN1_F_ASN1_DO_ADB, - ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE); + ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE); return NULL; } -- cgit v1.2.3-55-g6feb