Rizin
unix-like reverse engineering framework and cli tools
rz_asn1.h
Go to the documentation of this file.
1 #ifndef RZ_ASN1_H
2 #define RZ_ASN1_H
3 
4 #include <rz_types.h>
5 #include <stdint.h>
6 #include <rz_util/rz_strbuf.h>
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #define ASN1_JSON_NULL "null"
13 #define ASN1_JSON_EMPTY "{}"
14 
15 #define ASN1_OID_LEN 64
16 
17 /* Masks */
18 #define ASN1_CLASS 0xC0 /* Bits 8 and 7 */
19 #define ASN1_FORM 0x20 /* Bit 6 */
20 #define ASN1_TAG 0x1F /* Bits 5 - 1 */
21 #define ASN1_LENLONG 0x80 /* long form */
22 #define ASN1_LENSHORT 0x7F /* Bits 7 - 1 */
23 
24 /* Classes */
25 #define CLASS_UNIVERSAL 0x00 /* 0 = Universal (defined by ITU X.680) */
26 #define CLASS_APPLICATION 0x40 /* 1 = Application */
27 #define CLASS_CONTEXT 0x80 /* 2 = Context-specific */
28 #define CLASS_PRIVATE 0xC0 /* 3 = Private */
29 
30 /* Forms */
31 #define FORM_PRIMITIVE 0x00 /* 0 = primitive */
32 #define FORM_CONSTRUCTED 0x20 /* 1 = constructed */
33 
34 /* Tags */
35 #define TAG_EOC 0x00 /* 0: End-of-contents octets */
36 #define TAG_BOOLEAN 0x01 /* 1: Boolean */
37 #define TAG_INTEGER 0x02 /* 2: Integer */
38 #define TAG_BITSTRING 0x03 /* 2: Bit string */
39 #define TAG_OCTETSTRING 0x04 /* 4: Byte string */
40 #define TAG_NULL 0x05 /* 5: NULL */
41 #define TAG_OID 0x06 /* 6: Object Identifier */
42 #define TAG_OBJDESCRIPTOR 0x07 /* 7: Object Descriptor */
43 #define TAG_EXTERNAL 0x08 /* 8: External */
44 #define TAG_REAL 0x09 /* 9: Real */
45 #define TAG_ENUMERATED 0x0A /* 10: Enumerated */
46 #define TAG_EMBEDDED_PDV 0x0B /* 11: Embedded Presentation Data Value */
47 #define TAG_UTF8STRING 0x0C /* 12: UTF8 string */
48 #define TAG_SEQUENCE 0x10 /* 16: Sequence/sequence of */
49 #define TAG_SET 0x11 /* 17: Set/set of */
50 #define TAG_NUMERICSTRING 0x12 /* 18: Numeric string */
51 #define TAG_PRINTABLESTRING 0x13 /* 19: Printable string (ASCII subset) */
52 #define TAG_T61STRING 0x14 /* 20: T61/Teletex string */
53 #define TAG_VIDEOTEXSTRING 0x15 /* 21: Videotex string */
54 #define TAG_IA5STRING 0x16 /* 22: IA5/ASCII string */
55 #define TAG_UTCTIME 0x17 /* 23: UTC time */
56 #define TAG_GENERALIZEDTIME 0x18 /* 24: Generalized time */
57 #define TAG_GRAPHICSTRING 0x19 /* 25: Graphic string */
58 #define TAG_VISIBLESTRING 0x1A /* 26: Visible string (ASCII subset) */
59 #define TAG_GENERALSTRING 0x1B /* 27: General string */
60 #define TAG_UNIVERSALSTRING 0x1C /* 28: Universal string */
61 #define TAG_BMPSTRING 0x1E /* 30: Basic Multilingual Plane/Unicode string */
62 
63 typedef struct rz_asn1_string_t {
65  const char *string;
66  bool allocated;
68 
69 typedef struct rz_asn1_list_t {
73 
74 typedef struct rz_asn1_bin_t {
78 
79 typedef struct rz_asn1_object_t {
80  ut8 klass; /* class type */
81  ut8 form; /* defines if contains data or objects */
82  ut8 tag; /* tag type */
83  const ut8 *sector; /* Sector containing data */
84  ut32 length; /* Sector Length */
85  ut64 offset; /* Object offset */
86  ASN1List list; /* List of objects contained in the sector */
88 
89 RZ_API RASN1Object *rz_asn1_create_object(const ut8 *buffer, ut32 length, const ut8 *start_pointer);
91 RZ_API RASN1String *rz_asn1_create_string(const char *string, bool allocated, ut32 length);
100 
102 // RZ_API void rz_asn1_print_object (RASN1Object *object, ut32 depth);
103 RZ_API char *rz_asn1_to_string(RASN1Object *object, ut32 depth, RzStrBuf *sb);
106 RZ_API void asn1_setformat(int fmt);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif /* RZ_ASN1_H */
static SblHeader sb
Definition: bin_mbn.c:26
#define RZ_API
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
uint32_t ut32
uint8_t ut8
Definition: lh5801.h:11
RZ_API char * rz_asn1_to_string(RASN1Object *object, ut32 depth, RzStrBuf *sb)
Definition: asn1.c:259
RZ_API void rz_asn1_free_object(RASN1Object *object)
Definition: asn1.c:445
RZ_API void rz_asn1_free_string(RASN1String *string)
Definition: astr.c:313
RZ_API void rz_asn1_free_binary(RASN1Binary *string)
Definition: asn1.c:463
RZ_API void asn1_setformat(int fmt)
Definition: asn1.c:12
RZ_API RASN1String * rz_asn1_stringify_time(const ut8 *buffer, ut32 length)
Definition: astr.c:108
RZ_API RASN1Binary * rz_asn1_create_binary(const ut8 *buffer, ut32 length)
Definition: asn1.c:152
struct rz_asn1_string_t RASN1String
struct rz_asn1_bin_t RASN1Binary
RZ_API RASN1String * rz_asn1_stringify_integer(const ut8 *buffer, ut32 length)
Definition: astr.c:185
RZ_API RASN1String * rz_asn1_stringify_bits(const ut8 *buffer, ut32 length)
Definition: astr.c:150
RZ_API RASN1Object * rz_asn1_create_object(const ut8 *buffer, ut32 length, const ut8 *start_pointer)
Definition: asn1.c:120
RZ_API RASN1String * rz_asn1_create_string(const char *string, bool allocated, ut32 length)
Definition: astr.c:10
RZ_API RASN1String * rz_asn1_stringify_utctime(const ut8 *buffer, ut32 length)
Definition: astr.c:67
RZ_API RASN1String * rz_asn1_stringify_bytes(const ut8 *buffer, ut32 length)
Definition: astr.c:213
RZ_API RASN1String * rz_asn1_stringify_oid(const ut8 *buffer, ut32 length)
Definition: astr.c:249
struct rz_asn1_object_t RASN1Object
RZ_API RASN1String * rz_asn1_stringify_boolean(const ut8 *buffer, ut32 length)
Definition: astr.c:178
struct rz_asn1_list_t ASN1List
RZ_API RASN1String * rz_asn1_stringify_string(const ut8 *buffer, ut32 length)
Definition: astr.c:55
Definition: buffer.h:15
ut32 length
Definition: rz_asn1.h:75
ut8 * binary
Definition: rz_asn1.h:76
ut32 length
Definition: rz_asn1.h:70
struct rz_asn1_object_t ** objects
Definition: rz_asn1.h:71
ASN1List list
Definition: rz_asn1.h:86
const ut8 * sector
Definition: rz_asn1.h:83
const char * string
Definition: rz_asn1.h:65
bool allocated
Definition: rz_asn1.h:66
ut64(WINAPI *w32_GetEnabledXStateFeatures)()