Skip to content
This repository was archived by the owner on May 1, 2022. It is now read-only.

Commit f3a73da

Browse files
committed
x509: Translate attribute types into x509_rdn_type_t
1 parent e25c9ff commit f3a73da

28 files changed

+357
-4530
lines changed

include/asinine/asn1.h

+9-8
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ typedef enum asinine_err {
4242
ASININE_ERR_UNSUPPORTED_NAME = 35,
4343
ASININE_ERR_UNSUPPORTED_CONSTRAINT = 36,
4444
ASININE_ERR_INVALID = 40,
45-
ASININE_ERR_INVALID_UNTRUSTED = 41,
46-
ASININE_ERR_INVALID_EXPIRED = 42,
47-
ASININE_ERR_INVALID_ALGORITHM = 43,
48-
ASININE_ERR_INVALID_ISSUER = 44,
49-
ASININE_ERR_INVALID_VERSION = 45,
50-
ASININE_ERR_INVALID_NOT_CA = 46,
51-
ASININE_ERR_INVALID_PATH_LEN = 47,
52-
ASININE_ERR_INVALID_KEYUSE = 48,
45+
ASININE_ERR_INVALID_EXPIRED = 41,
46+
ASININE_ERR_INVALID_ALGORITHM = 42,
47+
ASININE_ERR_INVALID_ISSUER = 43,
48+
ASININE_ERR_INVALID_VERSION = 44,
49+
ASININE_ERR_INVALID_NOT_CA = 45,
50+
ASININE_ERR_INVALID_PATH_LEN = 46,
51+
ASININE_ERR_INVALID_KEYUSE = 47,
52+
ASININE_ERR_UNTRUSTED_ISSUER = 60,
53+
ASININE_ERR_UNTRUSTED_SIGNATURE = 61,
5354
ASININE_ERR_DEPRECATED = 70,
5455
} asinine_err_t;
5556

include/asinine/x509.h

+29-4
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,31 @@ typedef enum x509_ext_keyuse {
106106
X509_EXT_KEYUSE_ANY = 63
107107
} x509_ext_keyuse_t;
108108

109+
typedef enum x509_rdn_type {
110+
X509_RDN_INVALID,
111+
X509_RDN_JURISDICTION_COUNTRY,
112+
X509_RDN_JURISDICTION_STATE_OR_PROVINCE,
113+
X509_RDN_JURISDICTION_LOCALITY,
114+
X509_RDN_COUNTRY,
115+
X509_RDN_STATE_OR_PROVINCE,
116+
X509_RDN_LOCALITY,
117+
X509_RDN_POSTAL_CODE,
118+
X509_RDN_STREET_ADDRESS,
119+
X509_RDN_PO_BOX,
120+
X509_RDN_BUSINESS_CATEGORY,
121+
X509_RDN_ORGANIZATION,
122+
X509_RDN_ORGANIZATIONAL_UNIT,
123+
X509_RDN_ORGANIZATIONAL_ID,
124+
X509_RDN_DISTINGUISHED_NAME,
125+
X509_RDN_DISTINGUISHED_NAME_QUALIFIER,
126+
X509_RDN_COMMON_NAME,
127+
X509_RDN_SERIAL_NUMBER,
128+
X509_RDN_SURNAME,
129+
X509_RDN_EMAIL,
130+
} x509_rdn_type_t;
131+
109132
typedef struct x509_rdn {
110-
asn1_oid_t oid;
133+
x509_rdn_type_t type;
111134
asn1_token_t value;
112135
} x509_rdn_t;
113136

@@ -154,18 +177,20 @@ typedef struct x509_cert {
154177
int8_t path_len_constraint;
155178
} x509_cert_t;
156179

157-
ASININE_API asinine_err_t x509_parse(asn1_parser_t *parser, x509_cert_t *cert);
180+
ASININE_API asinine_err_t x509_parse_cert(
181+
asn1_parser_t *parser, x509_cert_t *cert);
158182
ASININE_API asinine_err_t x509_parse_name(
159183
asn1_parser_t *parser, x509_name_t *name);
160184
ASININE_API asinine_err_t x509_parse_optional_name(
161185
asn1_parser_t *parser, x509_name_t *name);
186+
ASININE_API asinine_err_t x509_parse_alt_names(
187+
asn1_parser_t *parser, x509_alt_names_t *alt_names);
162188
ASININE_API asinine_err_t x509_parse_pubkey(asn1_parser_t *parser,
163189
x509_pubkey_t *pubkey, x509_pubkey_params_t *params, bool *has_params);
164190
ASININE_API void x509_sort_name(x509_name_t *name);
191+
ASININE_API const char *x509_rdn_type_string(x509_rdn_type_t type);
165192
ASININE_API bool x509_name_eq(
166193
const x509_name_t *a, const x509_name_t *b, const char **err);
167-
ASININE_API asinine_err_t x509_parse_alt_names(
168-
asn1_parser_t *parser, x509_alt_names_t *alt_names);
169194

170195
typedef asinine_err_t (*x509_validation_cb_t)(const x509_pubkey_t *pubkey,
171196
x509_pubkey_params_t params, const x509_signature_t *sig,

premake5.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ workspace "Asinine"
5151
language "C"
5252
links { "asinine" }
5353

54-
files { "include/tests/*.h", "src/tests/*.c" }
54+
files { "include/tests/*.h", "src/tests/*.c", "src/utils/load.c" }

src/asn1-oid.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
#include <stdarg.h>
6+
#include <stdbool.h>
67
#include <stdio.h>
78
#include <string.h>
89

@@ -15,14 +16,14 @@
1516
#define OID_VALUE_MASK ((1 << 7) - 1)
1617
#define OID_VALUE_BITS_PER_BYTE 7
1718

18-
static int
19+
static bool
1920
append_arc(asn1_oid_t *oid, asn1_oid_arc_t arc) {
2021
if (oid->num >= ASN1_OID_MAXIMUM_DEPTH) {
21-
return 0;
22+
return false;
2223
}
2324

2425
oid->arcs[oid->num++] = arc;
25-
return 1;
26+
return true;
2627
}
2728

2829
// 8.19

src/asn1-types.c

+3-8
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,16 @@ asinine_strerror(asinine_err_t err) {
445445
case_for_tag(ASININE_ERR_UNSUPPORTED_NAME);
446446
case_for_tag(ASININE_ERR_UNSUPPORTED_CONSTRAINT);
447447
case_for_tag(ASININE_ERR_INVALID);
448-
case_for_tag(ASININE_ERR_INVALID_UNTRUSTED);
449448
case_for_tag(ASININE_ERR_INVALID_EXPIRED);
450449
case_for_tag(ASININE_ERR_INVALID_ALGORITHM);
451450
case_for_tag(ASININE_ERR_INVALID_ISSUER);
452451
case_for_tag(ASININE_ERR_INVALID_VERSION);
453452
case_for_tag(ASININE_ERR_INVALID_NOT_CA);
454453
case_for_tag(ASININE_ERR_INVALID_PATH_LEN);
455454
case_for_tag(ASININE_ERR_INVALID_KEYUSE);
455+
case_for_tag(ASININE_ERR_UNTRUSTED_ISSUER);
456+
case_for_tag(ASININE_ERR_UNTRUSTED_SIGNATURE);
456457
case_for_tag(ASININE_ERR_DEPRECATED);
457-
default:
458-
return "UNKNOWN";
459458
}
460459
#undef case_for_tag
461460
}
@@ -471,8 +470,6 @@ class_to_string(asn1_class_t class) {
471470
case_for(ASN1_CLASS_APPLICATION);
472471
case_for(ASN1_CLASS_CONTEXT);
473472
case_for(ASN1_CLASS_PRIVATE);
474-
default:
475-
return "UNKNOWN";
476473
}
477474
#undef case_for
478475
}
@@ -483,7 +480,7 @@ tag_to_string(asn1_tag_t tag) {
483480
#define case_for(x) \
484481
case x: \
485482
return #x
486-
switch ((asn1_tag_t)tag) {
483+
switch (tag) {
487484
case_for(ASN1_TAG_BOOL);
488485
case_for(ASN1_TAG_INT);
489486
case_for(ASN1_TAG_BITSTRING);
@@ -499,8 +496,6 @@ tag_to_string(asn1_tag_t tag) {
499496
case_for(ASN1_TAG_UTCTIME);
500497
case_for(ASN1_TAG_GENERALIZEDTIME);
501498
case_for(ASN1_TAG_VISIBLESTRING);
502-
default:
503-
return "UNKNOWN";
504499
}
505500
#undef case_for
506501
}

0 commit comments

Comments
 (0)