mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-08 22:16:10 +02:00
Switching to new style.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
29
src/asn1.c
29
src/asn1.c
@@ -17,29 +17,29 @@
|
||||
|
||||
#include "asn1.h"
|
||||
|
||||
size_t asn1_len_tag(uint16_t tag, size_t len)
|
||||
{
|
||||
size_t ret = 1+format_tlv_len(len, NULL)+len;
|
||||
size_t asn1_len_tag(uint16_t tag, size_t len) {
|
||||
size_t ret = 1 + format_tlv_len(len, NULL) + len;
|
||||
if (tag > 0x00ff) {
|
||||
return ret+1;
|
||||
return ret + 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int format_tlv_len(size_t len, uint8_t *out)
|
||||
{
|
||||
int format_tlv_len(size_t len, uint8_t *out) {
|
||||
if (len < 128) {
|
||||
if (out) {
|
||||
*out = len;
|
||||
}
|
||||
return 1;
|
||||
} else if (len < 256) {
|
||||
}
|
||||
else if (len < 256) {
|
||||
if (out) {
|
||||
*out++ = 0x81;
|
||||
*out++ = len;
|
||||
}
|
||||
return 2;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (out) {
|
||||
*out++ = 0x82;
|
||||
*out++ = (len >> 8) & 0xff;
|
||||
@@ -55,15 +55,14 @@ int walk_tlv(const uint8_t *cdata,
|
||||
uint8_t **p,
|
||||
uint16_t *tag,
|
||||
size_t *tag_len,
|
||||
uint8_t **data)
|
||||
{
|
||||
uint8_t **data) {
|
||||
if (!p) {
|
||||
return 0;
|
||||
}
|
||||
if (!*p) {
|
||||
*p = (uint8_t *) cdata;
|
||||
}
|
||||
if (*p-cdata >= cdata_len) {
|
||||
if (*p - cdata >= cdata_len) {
|
||||
return 0;
|
||||
}
|
||||
uint16_t tg = 0x0;
|
||||
@@ -77,7 +76,8 @@ int walk_tlv(const uint8_t *cdata,
|
||||
if (tgl == 0x82) {
|
||||
tgl = *(*p)++ << 8;
|
||||
tgl |= *(*p)++;
|
||||
} else if (tgl == 0x81) {
|
||||
}
|
||||
else if (tgl == 0x81) {
|
||||
tgl = *(*p)++;
|
||||
}
|
||||
if (tag) {
|
||||
@@ -89,7 +89,7 @@ int walk_tlv(const uint8_t *cdata,
|
||||
if (data) {
|
||||
*data = *p;
|
||||
}
|
||||
*p = *p+tgl;
|
||||
*p = *p + tgl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -97,8 +97,7 @@ bool asn1_find_tag(const uint8_t *data,
|
||||
size_t data_len,
|
||||
uint16_t itag,
|
||||
size_t *tag_len,
|
||||
uint8_t **tag_data)
|
||||
{
|
||||
uint8_t **tag_data) {
|
||||
uint16_t tag = 0x0;
|
||||
uint8_t *p = NULL;
|
||||
uint8_t *tdata = NULL;
|
||||
|
||||
Reference in New Issue
Block a user