2 * src/lib/krb5/asn.1/asn1_get.c
4 * Copyright 1994 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. M.I.T. makes no representations about the suitability of
20 * this software for any purpose. It is provided "as is" without express
21 * or implied warranty.
26 asn1_error_code INTERFACE asn1_get_tag(buf, class, construction, tagnum, retlen)
29 asn1_construction * construction;
33 asn1_error_code retval;
35 if (buf == NULL || buf->base == NULL ||
36 buf->bound - buf->next + 1 <= 0) {
37 *tagnum = ASN1_TAGNUM_CEILING;
40 retval = asn1_get_id(buf,class,construction,tagnum);
41 if(retval) return retval;
42 retval = asn1_get_length(buf,retlen);
43 if(retval) return retval;
47 asn1_error_code INTERFACE asn1_get_sequence(buf, retlen)
51 asn1_error_code retval;
53 asn1_construction construction;
56 retval = asn1_get_tag(buf,&class,&construction,&tagnum,retlen);
57 if(retval) return retval;
58 if(retval) return (krb5_error_code)retval;
59 if(class != UNIVERSAL || construction != CONSTRUCTED ||
60 tagnum != ASN1_SEQUENCE) return ASN1_BAD_ID;
64 /****************************************************************/
65 /* Private Procedures */
67 asn1_error_code INTERFACE asn1_get_id(buf, class, construction, tagnum)
70 asn1_construction * construction;
73 asn1_error_code retval;
77 #define ASN1_CLASS_MASK 0xC0
78 #define ASN1_CONSTRUCTION_MASK 0x20
79 #define ASN1_TAG_NUMBER_MASK 0x1F
81 retval = asn1buf_remove_octet(buf,&o);
82 if(retval) return retval;
85 *class = (asn1_class)(o&ASN1_CLASS_MASK);
86 if(construction != NULL)
87 *construction = (asn1_construction)(o&ASN1_CONSTRUCTION_MASK);
88 if((o&ASN1_TAG_NUMBER_MASK) != ASN1_TAG_NUMBER_MASK){
89 /* low-tag-number form */
90 if(tagnum != NULL) *tagnum = (asn1_tagnum)(o&ASN1_TAG_NUMBER_MASK);
92 /* high-tag-number form */
94 retval = asn1buf_remove_octet(buf,&o);
95 if(retval) return retval;
96 tn = (tn<<7) + (asn1_tagnum)(o&0x7F);
98 if(tagnum != NULL) *tagnum = tn;
103 asn1_error_code INTERFACE asn1_get_length(buf, retlen)
107 asn1_error_code retval;
110 retval = asn1buf_remove_octet(buf,&o);
111 if(retval) return retval;
113 if(retlen != NULL) *retlen = (int)(o&0x7F);
118 for(num = (int)(o&0x7F); num>0; num--){
119 retval = asn1buf_remove_octet(buf,&o);
120 if(retval) return retval;
121 len = (len<<8) + (int)o;
123 if(retlen != NULL) *retlen = len;