Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- asn1_error_t asn1_decode(uint8_t *asn1_data, size_t asn1_len, uint8_t *elem_tag, size_t *elem_len, uint8_t **elem_data){
- uint8_t *asn1_current = asn1_data;
- // return tag value
- *elem_tag = *asn1_current++;
- // compute element size
- *elem_len = 0;
- uint8_t byte_2nd = *asn1_current++;
- if((byte_2nd>>7) & 1) {
- // if bit 7 of byte set, this is a length of size
- uint8_t size_len = byte_2nd & 0x7f;
- if(size_len > 3) return ASN1_ARCH_BAD_LEN; // if seq len > u24, we can't really handle this on calc
- rmemcpy(elem_len, asn1_current, size_len);
- asn1_current += size_len;
- }
- else *elem_len = byte_2nd; // else size byte
- if(*elem_len > asn1_len) return ASN1_EOF;
- // return ptr to data start
- *elem_data = asn1_current;
- return ASN1_OK;
- // pull out tag with associated flags
- // node_o->tag = tag & 0b11111;
- // node_o->f_constr = (tag>>5 & 1);
- // node_o->f_class = (tag>>6 & 0b11);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement