Advertisement
AnthonyCagliano

Untitled

Oct 23rd, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. size_t asn1_decode(uint8_t *asn1_data, size_t asn1_len, asn1_obj_t *objs, size_t iter_count){
  2. uint8_t *asn1_current = asn1_data; // set current to start of data to decode
  3. uint8_t *asn1_end = asn1_current + asn1_len;
  4. size_t i;
  5. for(i = 0; i < iter_count; i++){ // loop until iter count hit. Break manually if done.
  6. asn1_obj_t *node_o = &objs[i];
  7. node_o->tag = *asn1_current++; // get numeric tag id
  8. if((*asn1_current)>>7 & 1){ // if bit 7 of byte is set, this is a size word length
  9. uint8_t size_len = (*asn1_current++) & 0x7f;
  10. if(size_len > 3) continue; // due to device limits, seq len limited to u24.
  11. for(int j = 0; j < size_len; j++){
  12. node_o->len <<= 8;
  13. node_o->len += *(asn1_current+j);
  14. }
  15. asn1_current += size_len;
  16. }
  17. else // else, this is a size byte
  18. node_o->len = *asn1_current++;
  19. node_o->data = asn1_current;
  20. asn1_current += node_o->len;
  21. if(asn1_current >= asn1_end) break;
  22. }
  23. return i;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement