aboutsummaryrefslogtreecommitdiff
path: root/src/lib/krb5/asn.1/asn1_get.c
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2003-03-12 04:33:30 +0000
committerKen Raeburn <raeburn@mit.edu>2003-03-12 04:33:30 +0000
commit6670198c5e4945eaabfec95e24b0c47c7d97fc44 (patch)
tree787e044efe4a2b753259125c1920e27c4be605b3 /src/lib/krb5/asn.1/asn1_get.c
parent9347b515ef987e4b1194fb7a03a7e1f8a6496670 (diff)
downloadkrb5-6670198c5e4945eaabfec95e24b0c47c7d97fc44.zip
krb5-6670198c5e4945eaabfec95e24b0c47c7d97fc44.tar.gz
krb5-6670198c5e4945eaabfec95e24b0c47c7d97fc44.tar.bz2
Rewrite asn1_get_tag interface to use a structure pointer rather than several
pointer variables for the returned data. Use the structure in the caller when straightforward; in cases where macros use different but overlapping sets of automatic scalar variables in one file, copy the values out of the structures for now, until they can be analyzed more carefully. * asn1_get.c (asn1_get_tag): Deleted. (asn1_get_tag_2): Renamed from asn1_get_tag_indef, now uses a pointer to taginfo rather than a bunch of pointer args. (asn1_get_id, asn1_get_length): Folded into asn1_get_tag_2. (asn1_get_sequence): Call asn1_get_tag_2. * asn1_get.h (taginfo): New structure. (asn1_get_tag_indef, asn1_get_tag, asn1_get_id, asn1_get_length): Declarations deleted. (asn1_get_tag_2): Declare. * asn1_decode.c (setup): Declare only a taginfo variable. (asn1class, construction, tagnum, length): New macros. (tag): Call asn1_get_tag_2. * asn1_k_decode.c (next_tag, get_eoc, apptag, end_sequence_of, end_sequence_of_no_tagvars, asn1_decode_krb5_flags): Call asn1_get_tag_2; if no error, copy out values into scalar variables. (asn1_decode_ticket): Call asn1_get_tag_2. * asn1buf.c (asn1buf_skiptail): Call asn1_get_tag_2. * krb5_decode.c (check_apptag, next_tag, get_eoc): Call asn1_get_tag_2; if no error, copy out values into scalar variables. (decode_krb5_enc_kdc_rep_part): Call asn1_get_tag_2. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15274 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/krb5/asn.1/asn1_get.c')
-rw-r--r--src/lib/krb5/asn.1/asn1_get.c183
1 files changed, 76 insertions, 107 deletions
diff --git a/src/lib/krb5/asn.1/asn1_get.c b/src/lib/krb5/asn.1/asn1_get.c
index e90ac6b..d5a7ca4 100644
--- a/src/lib/krb5/asn.1/asn1_get.c
+++ b/src/lib/krb5/asn.1/asn1_get.c
@@ -27,123 +27,92 @@
#include "asn1_get.h"
asn1_error_code
-asn1_get_tag_indef(asn1buf *buf, asn1_class *asn1class,
- asn1_construction *construction, asn1_tagnum *tagnum,
- unsigned int *retlen, int *indef)
+asn1_get_tag_2(asn1buf *buf, taginfo *t)
{
- asn1_error_code retval;
-
- if (buf == NULL || buf->base == NULL ||
- buf->bound - buf->next + 1 <= 0) {
- *tagnum = ASN1_TAGNUM_CEILING; /* emphatically not an EOC tag */
- if (asn1class != NULL)
- *asn1class = UNIVERSAL;
- if (construction != NULL)
- *construction = PRIMITIVE;
- if (retlen != NULL)
- *retlen = 0;
- if (indef != NULL)
- *indef = 0;
- return 0;
- }
- retval = asn1_get_id(buf,asn1class,construction,tagnum);
- if(retval) return retval;
- retval = asn1_get_length(buf,retlen,indef);
- if(retval) return retval;
- if (indef != NULL && *indef &&
- construction != NULL && *construction != CONSTRUCTED)
- return ASN1_MISMATCH_INDEF;
- return 0;
-}
-
-asn1_error_code
-asn1_get_tag(asn1buf *buf, asn1_class *asn1class,
- asn1_construction *construction, asn1_tagnum *tagnum,
- unsigned int *retlen)
-{
- int indef;
-
- return asn1_get_tag_indef(buf, asn1class, construction, tagnum, retlen,
- &indef);
-}
-
-asn1_error_code asn1_get_sequence(asn1buf *buf, unsigned int *retlen, int *indef)
-{
- asn1_error_code retval;
- asn1_class asn1class;
- asn1_construction construction;
- asn1_tagnum tagnum;
-
- retval = asn1_get_tag_indef(buf,&asn1class,&construction,&tagnum,retlen,indef);
- if(retval) return retval;
- if(retval) return (krb5_error_code)retval;
- if(asn1class != UNIVERSAL || construction != CONSTRUCTED ||
- tagnum != ASN1_SEQUENCE) return ASN1_BAD_ID;
- return 0;
-}
-
-/****************************************************************/
-/* Private Procedures */
+ asn1_error_code retval;
-asn1_error_code asn1_get_id(asn1buf *buf, asn1_class *asn1class,
- asn1_construction *construction,
- asn1_tagnum *tagnum)
-{
- asn1_error_code retval;
- asn1_tagnum tn=0;
- asn1_octet o;
+ if (buf == NULL || buf->base == NULL ||
+ buf->bound - buf->next + 1 <= 0) {
+ t->tagnum = ASN1_TAGNUM_CEILING; /* emphatically not an EOC tag */
+ t->asn1class = UNIVERSAL;
+ t->construction = PRIMITIVE;
+ t->length = 0;
+ t->indef = 0;
+ return 0;
+ }
+ {
+ /* asn1_get_id(buf, t) */
+ asn1_tagnum tn=0;
+ asn1_octet o;
#define ASN1_CLASS_MASK 0xC0
#define ASN1_CONSTRUCTION_MASK 0x20
#define ASN1_TAG_NUMBER_MASK 0x1F
- retval = asn1buf_remove_octet(buf,&o);
- if(retval) return retval;
+ retval = asn1buf_remove_octet(buf,&o);
+ if (retval)
+ return retval;
- if(asn1class != NULL)
- *asn1class = (asn1_class)(o&ASN1_CLASS_MASK);
- if(construction != NULL)
- *construction = (asn1_construction)(o&ASN1_CONSTRUCTION_MASK);
- if((o&ASN1_TAG_NUMBER_MASK) != ASN1_TAG_NUMBER_MASK){
- /* low-tag-number form */
- if(tagnum != NULL) *tagnum = (asn1_tagnum)(o&ASN1_TAG_NUMBER_MASK);
- }else{
- /* high-tag-number form */
- do{
- retval = asn1buf_remove_octet(buf,&o);
- if(retval) return retval;
- tn = (tn<<7) + (asn1_tagnum)(o&0x7F);
- }while(tn&0x80);
- if(tagnum != NULL) *tagnum = tn;
- }
- return 0;
-}
+ t->asn1class = (asn1_class)(o&ASN1_CLASS_MASK);
+ t->construction = (asn1_construction)(o&ASN1_CONSTRUCTION_MASK);
+ if ((o&ASN1_TAG_NUMBER_MASK) != ASN1_TAG_NUMBER_MASK){
+ /* low-tag-number form */
+ t->tagnum = (asn1_tagnum)(o&ASN1_TAG_NUMBER_MASK);
+ } else {
+ /* high-tag-number form */
+ do {
+ retval = asn1buf_remove_octet(buf,&o);
+ if (retval) return retval;
+ tn = (tn<<7) + (asn1_tagnum)(o&0x7F);
+ }while(tn&0x80);
+ t->tagnum = tn;
+ }
+ }
-asn1_error_code asn1_get_length(asn1buf *buf, unsigned int *retlen, int *indef)
-{
- asn1_error_code retval;
- asn1_octet o;
+ {
+ /* asn1_get_length(buf, t) */
+ asn1_octet o;
- if (indef != NULL)
- *indef = 0;
- retval = asn1buf_remove_octet(buf,&o);
- if(retval) return retval;
- if((o&0x80) == 0){
- if(retlen != NULL) *retlen = (int)(o&0x7F);
- }else{
- int num;
- int len=0;
+ t->indef = 0;
+ retval = asn1buf_remove_octet(buf,&o);
+ if (retval) return retval;
+ if ((o&0x80) == 0) {
+ t->length = (int)(o&0x7F);
+ } else {
+ int num;
+ int len=0;
- for(num = (int)(o&0x7F); num>0; num--){
- retval = asn1buf_remove_octet(buf,&o);
- if(retval) return retval;
- len = (len<<8) + (int)o;
+ for (num = (int)(o&0x7F); num>0; num--) {
+ retval = asn1buf_remove_octet(buf,&o);
+ if(retval) return retval;
+ len = (len<<8) + (int)o;
+ }
+ if (len < 0)
+ return ASN1_OVERRUN;
+ if (!len)
+ t->indef = 1;
+ t->length = len;
+ }
}
- if (len < 0)
- return ASN1_OVERRUN;
- if (indef != NULL && !len)
- *indef = 1;
- if(retlen != NULL) *retlen = len;
- }
- return 0;
+ if (t->indef && t->construction != CONSTRUCTED)
+ return ASN1_MISMATCH_INDEF;
+ return 0;
+}
+
+asn1_error_code asn1_get_sequence(asn1buf *buf, unsigned int *retlen, int *indef)
+{
+ taginfo t;
+ asn1_error_code retval;
+
+ retval = asn1_get_tag_2(buf, &t);
+ if (retval)
+ return retval;
+ if (t.asn1class != UNIVERSAL || t.construction != CONSTRUCTED ||
+ t.tagnum != ASN1_SEQUENCE)
+ return ASN1_BAD_ID;
+ if (retlen)
+ *retlen = t.length;
+ if (indef)
+ *indef = t.indef;
+ return 0;
}