Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- size_t asn1_decode(uint8_t *asn1_data, size_t asn1_len, ans1_obj_t *objs, size_t iter_count){
- uint8_t *asn1_current = ans1_data; // set current to start of data to decode
- uint8_t *asn1_end = ans1_current + asn1_len;
- size_t i;
- for(i = 0; i < iter_count; i++){ // loop until iter count hit. Break manually if done.
- ans1_obt_t *node_o = &objs[i];
- node_o->tag = *asn1_current++; // get numeric tag id
- if((*asn1_current)>>7 & 1){ // if bit 7 of byte is set, this is a size word length
- uint8_t size_len = (*asn1_current++) & 0x7f;
- if(size_len > 3) continue; // due to device limits, seq len limited to u24.
- for(int j = 0; j < size_len; j++){
- node_o->len <<= 8;
- node_o->len += *(asn1_current+j);
- }
- asn1_current += size_len;
- }
- else // else, this is a size byte
- node_o->len = *asn1_current++;
- node_o->data = asn1_current;
- asn1_current += node_o->len;
- if(asn1_current >= asn1_end) break;
- }
- return i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement