diff options
author | Simon Josefsson <simon@josefsson.org> | 2006-02-11 10:44:37 +0000 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2006-02-11 10:44:37 +0000 |
commit | 6bcbac0f4169c1499e87332233e5eb595fec592c (patch) | |
tree | 9809155462ca7d5b02a4ac86dc6f3544e21b2fc3 /lib/decoding.c | |
parent | a7bc6c2a212a5032b3c09e38ce3a116988c4d1c9 (diff) | |
download | libtasn1-6bcbac0f4169c1499e87332233e5eb595fec592c.tar.gz libtasn1-6bcbac0f4169c1499e87332233e5eb595fec592c.tar.bz2 libtasn1-6bcbac0f4169c1499e87332233e5eb595fec592c.zip |
Export DER utility functions.
Diffstat (limited to 'lib/decoding.c')
-rw-r--r-- | lib/decoding.c | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/lib/decoding.c b/lib/decoding.c index bfb6ccc..3ce6104 100644 --- a/lib/decoding.c +++ b/lib/decoding.c @@ -48,7 +48,7 @@ _asn1_error_description_tag_error(node_asn *node,char *ErrorDescription) signed long -_asn1_get_length_der(const unsigned char *der, int der_len, int *len) +asn1_get_length_der(const unsigned char *der, int der_len, int *len) { unsigned long ans; int k,punt; @@ -88,7 +88,7 @@ _asn1_get_length_der(const unsigned char *der, int der_len, int *len) int -_asn1_get_tag_der(const unsigned char *der, int der_len, +asn1_get_tag_der(const unsigned char *der, int der_len, unsigned char *class,int *len, unsigned long *tag) { int punt,ris; @@ -132,14 +132,14 @@ _asn1_get_tag_der(const unsigned char *der, int der_len, int -_asn1_get_octet_der(const unsigned char *der, int der_len, int *ret_len,unsigned char *str,int str_size, int *str_len) +asn1_get_octet_der(const unsigned char *der, int der_len, int *ret_len,unsigned char *str,int str_size, int *str_len) { int len_len; if (der_len <= 0) return ASN1_GENERIC_ERROR; /* if(str==NULL) return ASN1_SUCCESS; */ - *str_len=_asn1_get_length_der(der, der_len, &len_len); + *str_len=asn1_get_length_der(der, der_len, &len_len); if (*str_len < 0) return ASN1_DER_ERROR; @@ -164,7 +164,7 @@ _asn1_get_time_der(const unsigned char *der, int der_len, int *ret_len,unsigned int len_len,str_len; if(der_len <=0 || str==NULL) return ASN1_DER_ERROR; - str_len=_asn1_get_length_der(der, der_len, &len_len); + str_len=asn1_get_length_der(der, der_len, &len_len); if (str_len < 0 || str_size < str_len) return ASN1_DER_ERROR; memcpy(str,der+len_len,str_len); @@ -187,7 +187,7 @@ _asn1_get_objectid_der(const unsigned char *der,int der_len, int *ret_len,unsign if (str && str_size > 0) str[0] = 0; /* no oid */ if(str==NULL || der_len <= 0) return; - len=_asn1_get_length_der(der,der_len, &len_len); + len=asn1_get_length_der(der,der_len, &len_len); if (len < 0 || len > der_len || len_len > der_len) return; @@ -215,13 +215,13 @@ _asn1_get_objectid_der(const unsigned char *der,int der_len, int *ret_len,unsign int -_asn1_get_bit_der(const unsigned char *der, int der_len, +asn1_get_bit_der(const unsigned char *der, int der_len, int *ret_len,unsigned char *str, int str_size, int *bit_len) { int len_len,len_byte; if (der_len <=0) return ASN1_GENERIC_ERROR; - len_byte=_asn1_get_length_der(der,der_len,&len_len)-1; + len_byte=asn1_get_length_der(der,der_len,&len_len)-1; if (len_byte < 0) return ASN1_DER_ERROR; @@ -262,12 +262,12 @@ _asn1_extract_tag_der(node_asn *node,const unsigned char *der, int der_len,int * else class2=CONTEXT_SPECIFIC; if(p->type&CONST_EXPLICIT){ - if (_asn1_get_tag_der(der+counter, der_len-counter,&class,&len2, &tag)!=ASN1_SUCCESS) + if (asn1_get_tag_der(der+counter, der_len-counter,&class,&len2, &tag)!=ASN1_SUCCESS) return ASN1_DER_ERROR; if (counter+len2 > der_len) return ASN1_DER_ERROR; counter+=len2; - len3=_asn1_get_length_der(der+counter,der_len-counter, &len2); + len3=asn1_get_length_der(der+counter,der_len-counter, &len2); if (len3 < 0) return ASN1_DER_ERROR; counter+=len2; @@ -299,7 +299,7 @@ _asn1_extract_tag_der(node_asn *node,const unsigned char *der, int der_len,int * } if(is_tag_implicit){ - if (_asn1_get_tag_der(der+counter, der_len-counter,&class,&len2, &tag)!=ASN1_SUCCESS) + if (asn1_get_tag_der(der+counter, der_len-counter,&class,&len2, &tag)!=ASN1_SUCCESS) return ASN1_DER_ERROR; if (counter+len2 > der_len) return ASN1_DER_ERROR; @@ -321,7 +321,7 @@ _asn1_extract_tag_der(node_asn *node,const unsigned char *der, int der_len,int * return ASN1_SUCCESS; } - if (_asn1_get_tag_der(der+counter, der_len-counter,&class,&len2,&tag)!=ASN1_SUCCESS) + if (asn1_get_tag_der(der+counter, der_len-counter,&class,&len2,&tag)!=ASN1_SUCCESS) return ASN1_DER_ERROR; if (counter+len2 > der_len) return ASN1_DER_ERROR; @@ -440,7 +440,7 @@ _asn1_get_octet_string(const unsigned char* der, node_asn *node,int* len) if(*(der-1) & STRUCTURED){ tot_len=0; - indefinite=_asn1_get_length_der(der, *len, &len3); + indefinite=asn1_get_length_der(der, *len, &len3); if (indefinite < -1) return ASN1_DER_ERROR; @@ -462,7 +462,7 @@ _asn1_get_octet_string(const unsigned char* der, node_asn *node,int* len) counter++; - len2=_asn1_get_length_der(der+counter,*len-counter, &len3); + len2=asn1_get_length_der(der+counter,*len-counter, &len3); if(len2 <= 0) return ASN1_DER_ERROR; counter+=len3+len2; @@ -471,16 +471,16 @@ _asn1_get_octet_string(const unsigned char* der, node_asn *node,int* len) /* copy */ if(node){ - _asn1_length_der(tot_len,NULL,&len2); + asn1_length_der(tot_len,NULL,&len2); temp=(unsigned char *)_asn1_alloca(len2+tot_len); if (temp==NULL){ return ASN1_MEM_ALLOC_ERROR; } - _asn1_length_der(tot_len,temp,&len2); + asn1_length_der(tot_len,temp,&len2); tot_len+=len2; temp2=temp+len2; - len2=_asn1_get_length_der(der,*len,&len3); + len2=asn1_get_length_der(der,*len,&len3); if(len2 < -1) return ASN1_DER_ERROR; counter2=len3+1; @@ -488,7 +488,7 @@ _asn1_get_octet_string(const unsigned char* der, node_asn *node,int* len) else counter_end=counter; while(counter2<counter_end){ - len2=_asn1_get_length_der(der+counter2, *len-counter, &len3); + len2=asn1_get_length_der(der+counter2, *len-counter, &len3); if(len2 < -1) return ASN1_DER_ERROR; /* FIXME: to be checked. Is this ok? Has the @@ -504,7 +504,7 @@ _asn1_get_octet_string(const unsigned char* der, node_asn *node,int* len) } } else{ /* NOT STRUCTURED */ - len2=_asn1_get_length_der(der, *len, &len3); + len2=asn1_get_length_der(der, *len, &len3); if(len2 < 0) return ASN1_DER_ERROR; if (len3+len2 > *len) return ASN1_DER_ERROR; if(node) @@ -537,12 +537,12 @@ _asn1_get_indefinite_length_string(const unsigned char* der, int* len) else continue; } - if(_asn1_get_tag_der(der+counter, *len-counter,&class,&len2,&tag)!=ASN1_SUCCESS) + if(asn1_get_tag_der(der+counter, *len-counter,&class,&len2,&tag)!=ASN1_SUCCESS) return ASN1_DER_ERROR; if (counter+len2 > *len) return ASN1_DER_ERROR; counter+=len2; - len2=_asn1_get_length_der(der+counter, *len-counter,&len3); + len2=asn1_get_length_der(der+counter, *len-counter,&len3); if(len2 < -1) return ASN1_DER_ERROR; if(len2 == -1){ indefinite++; @@ -754,7 +754,7 @@ asn1_der_decoding(ASN1_TYPE *element,const void *ider,int len, move=RIGHT; break; case TYPE_INTEGER: case TYPE_ENUMERATED: - len2=_asn1_get_length_der(der+counter,len-counter, &len3); + len2=asn1_get_length_der(der+counter,len-counter, &len3); if(len2 < 0) return ASN1_DER_ERROR; if (len2+len3 > len-counter) return ASN1_DER_ERROR; _asn1_set_value(p,der+counter,len3+len2); @@ -789,7 +789,7 @@ asn1_der_decoding(ASN1_TYPE *element,const void *ider,int len, move=RIGHT; break; case TYPE_GENERALSTRING: - len2=_asn1_get_length_der(der+counter,len-counter,&len3); + len2=asn1_get_length_der(der+counter,len-counter,&len3); if(len2 < 0) return ASN1_DER_ERROR; if (len3+len2 > len-counter) return ASN1_DER_ERROR; _asn1_set_value(p,der+counter,len3+len2); @@ -797,7 +797,7 @@ asn1_der_decoding(ASN1_TYPE *element,const void *ider,int len, move=RIGHT; break; case TYPE_BIT_STRING: - len2=_asn1_get_length_der(der+counter,len-counter,&len3); + len2=asn1_get_length_der(der+counter,len-counter,&len3); if(len2 < 0) return ASN1_DER_ERROR; if (len3+len2 > len-counter) return ASN1_DER_ERROR; _asn1_set_value(p,der+counter,len3+len2); @@ -826,7 +826,7 @@ asn1_der_decoding(ASN1_TYPE *element,const void *ider,int len, move=RIGHT; } else{ /* move==DOWN || move==RIGHT */ - len3=_asn1_get_length_der(der+counter,len-counter,&len2); + len3=asn1_get_length_der(der+counter,len-counter,&len2); if(len3 < -1) return ASN1_DER_ERROR; counter+=len2; if(len3>0){ @@ -886,7 +886,7 @@ asn1_der_decoding(ASN1_TYPE *element,const void *ider,int len, } } else{ /* move==DOWN || move==RIGHT */ - len3=_asn1_get_length_der(der+counter,len-counter,&len2); + len3=asn1_get_length_der(der+counter,len-counter,&len2); if(len3 < -1) return ASN1_DER_ERROR; counter+=len2; if(len3){ @@ -909,23 +909,23 @@ asn1_der_decoding(ASN1_TYPE *element,const void *ider,int len, move=RIGHT; break; case TYPE_ANY: - if(_asn1_get_tag_der(der+counter,len-counter,&class,&len2,&tag)!=ASN1_SUCCESS) + if(asn1_get_tag_der(der+counter,len-counter,&class,&len2,&tag)!=ASN1_SUCCESS) return ASN1_DER_ERROR; if (counter+len2 > len) return ASN1_DER_ERROR; - len4=_asn1_get_length_der(der+counter+len2,len-counter-len2,&len3); + len4=asn1_get_length_der(der+counter+len2,len-counter-len2,&len3); if(len4 < -1) return ASN1_DER_ERROR; if(len4 > len-counter+len2+len3) return ASN1_DER_ERROR; if(len4 != -1){ len2+=len4; - _asn1_length_der(len2+len3,NULL,&len4); + asn1_length_der(len2+len3,NULL,&len4); temp2=(unsigned char *)_asn1_alloca(len2+len3+len4); if (temp2==NULL){ asn1_delete_structure(element); return ASN1_MEM_ALLOC_ERROR; } - _asn1_octet_der(der+counter,len2+len3,temp2,&len4); + asn1_octet_der(der+counter,len2+len3,temp2,&len4); _asn1_set_value(p,temp2,len4); _asn1_afree(temp2); counter+=len2+len3; @@ -943,14 +943,14 @@ asn1_der_decoding(ASN1_TYPE *element,const void *ider,int len, asn1_delete_structure(element); return ris; } - _asn1_length_der(len2,NULL,&len4); + asn1_length_der(len2,NULL,&len4); temp2=(unsigned char *)_asn1_alloca(len2+len4); if (temp2==NULL){ asn1_delete_structure(element); return ASN1_MEM_ALLOC_ERROR; } - _asn1_octet_der(der+counter,len2,temp2,&len4); + asn1_octet_der(der+counter,len2,temp2,&len4); _asn1_set_value(p,temp2,len4); _asn1_afree(temp2); counter+=len2; @@ -1241,7 +1241,7 @@ asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName, move=RIGHT; break; case TYPE_INTEGER: case TYPE_ENUMERATED: - len2=_asn1_get_length_der(der+counter,len-counter,&len3); + len2=asn1_get_length_der(der+counter,len-counter,&len3); if(len2 < 0) return ASN1_DER_ERROR; if(state==FOUND){ if (len3+len2 > len-counter) return ASN1_DER_ERROR; @@ -1263,7 +1263,7 @@ asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName, if(p==nodeFound) state=EXIT; } else{ - len2=_asn1_get_length_der(der+counter,len-counter,&len3); + len2=asn1_get_length_der(der+counter,len-counter,&len3); if(len2 < 0) return ASN1_DER_ERROR; len2+=len3; } @@ -1286,7 +1286,7 @@ asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName, if(p==nodeFound) state=EXIT; } else{ - len2=_asn1_get_length_der(der+counter,len-counter,&len3); + len2=asn1_get_length_der(der+counter,len-counter,&len3); if(len2 < 0) return ASN1_DER_ERROR; len2+=len3; } @@ -1308,7 +1308,7 @@ asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName, move=RIGHT; break; case TYPE_GENERALSTRING: - len2=_asn1_get_length_der(der+counter,len-counter,&len3); + len2=asn1_get_length_der(der+counter,len-counter,&len3); if(len2 < 0) return ASN1_DER_ERROR; if(state==FOUND){ if (len3+len2 > len-counter) return ASN1_DER_ERROR; @@ -1320,7 +1320,7 @@ asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName, move=RIGHT; break; case TYPE_BIT_STRING: - len2=_asn1_get_length_der(der+counter,len-counter,&len3); + len2=asn1_get_length_der(der+counter,len-counter,&len3); if(len2 < 0) return ASN1_DER_ERROR; if(state==FOUND){ if (len3+len2 > len-counter) return ASN1_DER_ERROR; @@ -1353,13 +1353,13 @@ asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName, } else{ /* move==DOWN || move==RIGHT */ if(state==OTHER_BRANCH){ - len3=_asn1_get_length_der(der+counter,len-counter,&len2); + len3=asn1_get_length_der(der+counter,len-counter,&len2); if(len3 < 0) return ASN1_DER_ERROR; counter+=len2+len3; move=RIGHT; } else { /* state==SAME_BRANCH or state==FOUND */ - len3=_asn1_get_length_der(der+counter,len-counter,&len2); + len3=asn1_get_length_der(der+counter,len-counter,&len2); if(len3 < 0) return ASN1_DER_ERROR; counter+=len2; if(len3>0){ @@ -1410,13 +1410,13 @@ asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName, } else{ /* move==DOWN || move==RIGHT */ if(state==OTHER_BRANCH){ - len3=_asn1_get_length_der(der+counter,len-counter,&len2); + len3=asn1_get_length_der(der+counter,len-counter,&len2); if(len3 < 0) return ASN1_DER_ERROR; counter+=len2+len3; move=RIGHT; } else{ /* state==FOUND or state==SAME_BRANCH */ - len3=_asn1_get_length_der(der+counter,len-counter,&len2); + len3=asn1_get_length_der(der+counter,len-counter,&len2); if(len3 < 0) return ASN1_DER_ERROR; counter+=len2; if(len3){ @@ -1436,25 +1436,25 @@ asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName, break; case TYPE_ANY: - if(_asn1_get_tag_der(der+counter, len-counter,&class,&len2,&tag)!=ASN1_SUCCESS) + if(asn1_get_tag_der(der+counter, len-counter,&class,&len2,&tag)!=ASN1_SUCCESS) return ASN1_DER_ERROR; if (counter+len2 > len) return ASN1_DER_ERROR; - len4=_asn1_get_length_der(der+counter+len2,len-counter-len2,&len3); + len4=asn1_get_length_der(der+counter+len2,len-counter-len2,&len3); if(len4 < -1) return ASN1_DER_ERROR; if(len4 != -1){ len2+=len4; if(state==FOUND){ - _asn1_length_der(len2+len3,NULL,&len4); + asn1_length_der(len2+len3,NULL,&len4); temp2=(unsigned char *)_asn1_alloca(len2+len3+len4); if (temp2==NULL){ asn1_delete_structure(structure); return ASN1_MEM_ALLOC_ERROR; } - _asn1_octet_der(der+counter,len2+len3,temp2,&len4); + asn1_octet_der(der+counter,len2+len3,temp2,&len4); _asn1_set_value(p,temp2,len4); _asn1_afree(temp2); @@ -1477,14 +1477,14 @@ asn1_der_decoding_element(ASN1_TYPE *structure,const char *elementName, } if(state==FOUND){ - _asn1_length_der(len2,NULL,&len4); + asn1_length_der(len2,NULL,&len4); temp2=(unsigned char *)_asn1_alloca(len2+len4); if (temp2==NULL){ asn1_delete_structure(structure); return ASN1_MEM_ALLOC_ERROR; } - _asn1_octet_der(der+counter,len2,temp2,&len4); + asn1_octet_der(der+counter,len2,temp2,&len4); _asn1_set_value(p,temp2,len4); _asn1_afree(temp2); @@ -1752,19 +1752,19 @@ asn1_der_decoding_startEnd(ASN1_TYPE element,const void *ider,int len, move=RIGHT; break; case TYPE_INTEGER: case TYPE_ENUMERATED: - len2=_asn1_get_length_der(der+counter,len-counter,&len3); + len2=asn1_get_length_der(der+counter,len-counter,&len3); if(len2 < 0) return ASN1_DER_ERROR; counter+=len3+len2; move=RIGHT; break; case TYPE_OBJECT_ID: - len2=_asn1_get_length_der(der+counter,len-counter,&len3); + len2=asn1_get_length_der(der+counter,len-counter,&len3); if(len2 < 0) return ASN1_DER_ERROR; counter+=len2+len3; move=RIGHT; break; case TYPE_TIME: - len2=_asn1_get_length_der(der+counter,len-counter,&len3); + len2=asn1_get_length_der(der+counter,len-counter,&len3); if(len2 < 0) return ASN1_DER_ERROR; counter+=len2+len3; move=RIGHT; @@ -1777,20 +1777,20 @@ asn1_der_decoding_startEnd(ASN1_TYPE element,const void *ider,int len, move=RIGHT; break; case TYPE_GENERALSTRING: - len2=_asn1_get_length_der(der+counter,len-counter,&len3); + len2=asn1_get_length_der(der+counter,len-counter,&len3); if(len2 < 0) return ASN1_DER_ERROR; counter+=len3+len2; move=RIGHT; break; case TYPE_BIT_STRING: - len2=_asn1_get_length_der(der+counter,len-counter,&len3); + len2=asn1_get_length_der(der+counter,len-counter,&len3); if(len2 < 0) return ASN1_DER_ERROR; counter+=len3+len2; move=RIGHT; break; case TYPE_SEQUENCE: case TYPE_SET: if(move!=UP){ - len3=_asn1_get_length_der(der+counter,len-counter,&len2); + len3=asn1_get_length_der(der+counter,len-counter,&len2); if(len3 < -1) return ASN1_DER_ERROR; counter+=len2; if(len3==0) move=RIGHT; @@ -1804,7 +1804,7 @@ asn1_der_decoding_startEnd(ASN1_TYPE element,const void *ider,int len, break; case TYPE_SEQUENCE_OF: case TYPE_SET_OF: if(move!=UP){ - len3=_asn1_get_length_der(der+counter,len-counter,&len2); + len3=asn1_get_length_der(der+counter,len-counter,&len2); if(len3 < -1) return ASN1_DER_ERROR; counter+=len2; if((len3==-1) && !der[counter] && !der[counter+1]) @@ -1823,12 +1823,12 @@ asn1_der_decoding_startEnd(ASN1_TYPE element,const void *ider,int len, move=RIGHT; break; case TYPE_ANY: - if (_asn1_get_tag_der(der+counter, len-counter,&class,&len2,&tag)!=ASN1_SUCCESS) + if (asn1_get_tag_der(der+counter, len-counter,&class,&len2,&tag)!=ASN1_SUCCESS) return ASN1_DER_ERROR; if (counter+len2 > len) return ASN1_DER_ERROR; - len4=_asn1_get_length_der(der+counter+len2,len-counter-len2,&len3); + len4=asn1_get_length_der(der+counter+len2,len-counter-len2,&len3); if(len4 < -1) return ASN1_DER_ERROR; if(len4 != -1){ @@ -2001,7 +2001,7 @@ asn1_expand_any_defined_by(ASN1_TYPE definitions,ASN1_TYPE *element) result=asn1_create_element(definitions,name,&aux); if(result == ASN1_SUCCESS){ _asn1_set_name(aux,p->name); - len2=_asn1_get_length_der(p->value,p->value_len,&len3); + len2=asn1_get_length_der(p->value,p->value_len,&len3); if(len2 < 0) return ASN1_DER_ERROR; result=asn1_der_decoding(&aux,p->value+len3,len2, @@ -2166,7 +2166,7 @@ asn1_expand_octet_string(ASN1_TYPE definitions,ASN1_TYPE *element, result=asn1_create_element(definitions,name,&aux); if(result == ASN1_SUCCESS){ _asn1_set_name(aux,octetNode->name); - len2=_asn1_get_length_der(octetNode->value,octetNode->value_len,&len3); + len2=asn1_get_length_der(octetNode->value,octetNode->value_len,&len3); if(len2 < 0) return ASN1_DER_ERROR; result=asn1_der_decoding(&aux,octetNode->value+len3,len2, |