Advertisement
AnthonyCagliano

Untitled

Apr 11th, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. 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){
  2.  
  3. uint8_t *asn1_current = asn1_data;
  4. // return tag value
  5. *elem_tag = *asn1_current++;
  6.  
  7. // compute element size
  8. *elem_len = 0;
  9. uint8_t byte_2nd = *asn1_current++;
  10. if((byte_2nd>>7) & 1) {
  11. // if bit 7 of byte set, this is a length of size
  12. uint8_t size_len = byte_2nd & 0x7f;
  13. if(size_len > 3) return ASN1_ARCH_BAD_LEN; // if seq len > u24, we can't really handle this on calc
  14. rmemcpy(elem_len, asn1_current, size_len);
  15. asn1_current += size_len;
  16. }
  17. else *elem_len = byte_2nd; // else size byte
  18.  
  19. if(*elem_len > asn1_len) return ASN1_EOF;
  20.  
  21. // return ptr to data start
  22. *elem_data = asn1_current;
  23. return ASN1_OK;
  24.  
  25. // pull out tag with associated flags
  26. // node_o->tag = tag & 0b11111;
  27. // node_o->f_constr = (tag>>5 & 1);
  28. // node_o->f_class = (tag>>6 & 0b11);
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement