1/* Copyright (c) (2010-2012,2015-2019,2021,2022) Apple Inc. All rights reserved.
2 *
3 * corecrypto is licensed under Apple Inc.’s Internal Use License Agreement (which
4 * is contained in the License.txt file distributed with corecrypto) and only to
5 * people who accept that license. IMPORTANT: Any license rights granted to you by
6 * Apple Inc. (if any) are limited to internal use within your organization only on
7 * devices and computers you own or control, for the sole purpose of verifying the
8 * security characteristics and correct functioning of the Apple Software. You may
9 * not, directly or indirectly, redistribute the Apple Software or any portions thereof.
10 */
11
12#ifndef _CORECRYPTO_CCASN1_H_
13#define _CORECRYPTO_CCASN1_H_
14
15#include <corecrypto/cc.h>
16
17CC_PTRCHECK_CAPABLE_HEADER()
18
19/* ASN.1 types for on the fly ASN.1 BER/DER encoding/decoding. Don't use
20 these with the ccder interface, use the CCDER_ types instead. */
21enum {
22 CCASN1_EOL = 0x00,
23 CCASN1_BOOLEAN = 0x01,
24 CCASN1_INTEGER = 0x02,
25 CCASN1_BIT_STRING = 0x03,
26 CCASN1_OCTET_STRING = 0x04,
27 CCASN1_NULL = 0x05,
28 CCASN1_OBJECT_IDENTIFIER = 0x06,
29 CCASN1_OBJECT_DESCRIPTOR = 0x07,
30 /* External or instance-of 0x08 */
31 CCASN1_REAL = 0x09,
32 CCASN1_ENUMERATED = 0x0a,
33 CCASN1_EMBEDDED_PDV = 0x0b,
34 CCASN1_UTF8_STRING = 0x0c,
35 /* 0x0d */
36 /* 0x0e */
37 /* 0x0f */
38 CCASN1_SEQUENCE = 0x10,
39 CCASN1_SET = 0x11,
40 CCASN1_NUMERIC_STRING = 0x12,
41 CCASN1_PRINTABLE_STRING = 0x13,
42 CCASN1_T61_STRING = 0x14,
43 CCASN1_VIDEOTEX_STRING = 0x15,
44 CCASN1_IA5_STRING = 0x16,
45 CCASN1_UTC_TIME = 0x17,
46 CCASN1_GENERALIZED_TIME = 0x18,
47 CCASN1_GRAPHIC_STRING = 0x19,
48 CCASN1_VISIBLE_STRING = 0x1a,
49 CCASN1_GENERAL_STRING = 0x1b,
50 CCASN1_UNIVERSAL_STRING = 0x1c,
51 /* 0x1d */
52 CCASN1_BMP_STRING = 0x1e,
53 CCASN1_HIGH_TAG_NUMBER = 0x1f,
54 CCASN1_TELETEX_STRING = CCASN1_T61_STRING,
55
56 CCASN1_TAG_MASK = 0xff,
57 CCASN1_TAGNUM_MASK = 0x1f,
58
59 CCASN1_METHOD_MASK = 0x20,
60 CCASN1_PRIMITIVE = 0x00,
61 CCASN1_CONSTRUCTED = 0x20,
62
63 CCASN1_CLASS_MASK = 0xc0,
64 CCASN1_UNIVERSAL = 0x00,
65 CCASN1_APPLICATION = 0x40,
66 CCASN1_CONTEXT_SPECIFIC = 0x80,
67 CCASN1_PRIVATE = 0xc0,
68
69 CCASN1_CONSTRUCTED_SET = CCASN1_SET | CCASN1_CONSTRUCTED,
70 CCASN1_CONSTRUCTED_SEQUENCE = CCASN1_SEQUENCE | CCASN1_CONSTRUCTED,
71};
72
73typedef const unsigned char * cc_unsafe_indexable ccoid_t;
74#define CCOID(oid) (oid)
75
76/* Returns the size of an oid including its tag and length. */
77CC_PURE CC_NONNULL((1))
78size_t ccoid_size(ccoid_t oid);
79
80CC_PURE CC_NONNULL((1))
81const unsigned char *cc_indexable ccoid_payload(ccoid_t oid);
82
83CC_PURE
84bool ccoid_equal(ccoid_t oid1, ccoid_t oid2);
85
86#endif /* _CORECRYPTO_CCASN1_H_ */
87