/* Read an integer value for ASN.1 data Note: This function allocates memory which must be freed by the user.  */
int ICACHE_FLASH_ATTR asn1_get_int(const uint8_t *buf, int *offset, uint8_t **object)
/* Read an integer value for ASN.1 data Note: This function allocates memory which must be freed by the user.  */
int ICACHE_FLASH_ATTR asn1_get_int(const uint8_t *buf, int *offset, uint8_t **object)
{
    int len;
    if ((len = asn1_next_obj(buf, offset, ASN1_INTEGER)) < 0)
        goto end_int_array;
    if (len > 1 && buf[*offset] == 0x00)
    {
        len--;
        (*offset)++;
    }
    *object = (uint8_t *)malloc(len);
    memcpy(*object, &buf[*offset], len);
    *offset += len;
end_int_array:
    return len;
}