]> git.saurik.com Git - apple/xnu.git/blame - EXTERNAL_HEADERS/corecrypto/ccasn1.h
xnu-4903.241.1.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / corecrypto / ccasn1.h
CommitLineData
fe8ab488
A
1/*
2 * ccasn1.h
3 * corecrypto
4 *
3e170ce0
A
5 * Created on 11/16/2010
6 *
7 * Copyright (c) 2010,2011,2012,2015 Apple Inc. All rights reserved.
fe8ab488
A
8 *
9 */
10
11#ifndef _CORECRYPTO_CCASN1_H_
12#define _CORECRYPTO_CCASN1_H_
13
14#include <corecrypto/cc.h>
15#include <stdbool.h>
16#include <string.h>
17
18/* ASN.1 types for on the fly ASN.1 BER/DER encoding/decoding. Don't use
19 these with the ccder interface, use the CCDER_ types instead. */
20enum {
21 CCASN1_EOL = 0x00,
22 CCASN1_BOOLEAN = 0x01,
23 CCASN1_INTEGER = 0x02,
24 CCASN1_BIT_STRING = 0x03,
25 CCASN1_OCTET_STRING = 0x04,
26 CCASN1_NULL = 0x05,
27 CCASN1_OBJECT_IDENTIFIER = 0x06,
28 CCASN1_OBJECT_DESCRIPTOR = 0x07,
29 /* External or instance-of 0x08 */
30 CCASN1_REAL = 0x09,
31 CCASN1_ENUMERATED = 0x0a,
32 CCASN1_EMBEDDED_PDV = 0x0b,
33 CCASN1_UTF8_STRING = 0x0c,
34 /* 0x0d */
35 /* 0x0e */
36 /* 0x0f */
37 CCASN1_SEQUENCE = 0x10,
38 CCASN1_SET = 0x11,
39 CCASN1_NUMERIC_STRING = 0x12,
40 CCASN1_PRINTABLE_STRING = 0x13,
41 CCASN1_T61_STRING = 0x14,
42 CCASN1_VIDEOTEX_STRING = 0x15,
43 CCASN1_IA5_STRING = 0x16,
44 CCASN1_UTC_TIME = 0x17,
45 CCASN1_GENERALIZED_TIME = 0x18,
46 CCASN1_GRAPHIC_STRING = 0x19,
47 CCASN1_VISIBLE_STRING = 0x1a,
48 CCASN1_GENERAL_STRING = 0x1b,
49 CCASN1_UNIVERSAL_STRING = 0x1c,
50 /* 0x1d */
51 CCASN1_BMP_STRING = 0x1e,
52 CCASN1_HIGH_TAG_NUMBER = 0x1f,
53 CCASN1_TELETEX_STRING = CCASN1_T61_STRING,
54
55 CCASN1_TAG_MASK = 0xff,
56 CCASN1_TAGNUM_MASK = 0x1f,
57
58 CCASN1_METHOD_MASK = 0x20,
59 CCASN1_PRIMITIVE = 0x00,
60 CCASN1_CONSTRUCTED = 0x20,
61
62 CCASN1_CLASS_MASK = 0xc0,
63 CCASN1_UNIVERSAL = 0x00,
64 CCASN1_APPLICATION = 0x40,
65 CCASN1_CONTEXT_SPECIFIC = 0x80,
66 CCASN1_PRIVATE = 0xc0,
67
68 CCASN1_CONSTRUCTED_SET = CCASN1_SET | CCASN1_CONSTRUCTED,
69 CCASN1_CONSTRUCTED_SEQUENCE = CCASN1_SEQUENCE | CCASN1_CONSTRUCTED,
fe8ab488
A
70};
71
d9a64523 72typedef const unsigned char * ccoid_t;
39037602 73#define CCOID(oid) (oid)
fe8ab488
A
74
75/* Returns the size of an oid including it's tag and length. */
d9a64523 76CC_INLINE CC_PURE CC_NONNULL((1))
fe8ab488 77size_t ccoid_size(ccoid_t oid) {
39037602 78 return 2 + CCOID(oid)[1];
fe8ab488
A
79}
80
d9a64523 81CC_INLINE CC_PURE CC_NONNULL((1, 2))
fe8ab488 82bool ccoid_equal(ccoid_t oid1, ccoid_t oid2) {
39037602
A
83 return (ccoid_size(oid1) == ccoid_size(oid2)
84 && memcmp(CCOID(oid1), CCOID(oid2), ccoid_size(oid1))== 0);
fe8ab488
A
85}
86
fe8ab488 87#endif /* _CORECRYPTO_CCASN1_H_ */