• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_DER_TAG_H_
6 #define NET_DER_TAG_H_
7 
8 #include <stdint.h>
9 
10 #include "net/base/net_export.h"
11 #include "third_party/boringssl/src/include/openssl/bytestring.h"
12 
13 namespace net::der {
14 
15 // This Tag type represents the identifier for an ASN.1 tag as encoded with
16 // DER. It matches the BoringSSL CBS and CBB in-memory representation for a
17 // tag.
18 //
19 // Callers must not assume it matches the DER representation for small tag
20 // numbers. Instead, constants are provided for universal class types, and
21 // functions are provided for building context specific tags. Tags can also be
22 // built from the provided constants and bitmasks.
23 using Tag = unsigned;
24 
25 // Universal class primitive types
26 const Tag kBool = CBS_ASN1_BOOLEAN;
27 const Tag kInteger = CBS_ASN1_INTEGER;
28 const Tag kBitString = CBS_ASN1_BITSTRING;
29 const Tag kOctetString = CBS_ASN1_OCTETSTRING;
30 const Tag kNull = CBS_ASN1_NULL;
31 const Tag kOid = CBS_ASN1_OBJECT;
32 const Tag kEnumerated = CBS_ASN1_ENUMERATED;
33 const Tag kUtf8String = CBS_ASN1_UTF8STRING;
34 const Tag kPrintableString = CBS_ASN1_PRINTABLESTRING;
35 const Tag kTeletexString = CBS_ASN1_T61STRING;
36 const Tag kIA5String = CBS_ASN1_IA5STRING;
37 const Tag kUtcTime = CBS_ASN1_UTCTIME;
38 const Tag kGeneralizedTime = CBS_ASN1_GENERALIZEDTIME;
39 const Tag kVisibleString = CBS_ASN1_VISIBLESTRING;
40 const Tag kUniversalString = CBS_ASN1_UNIVERSALSTRING;
41 const Tag kBmpString = CBS_ASN1_BMPSTRING;
42 
43 // Universal class constructed types
44 const Tag kSequence = CBS_ASN1_SEQUENCE;
45 const Tag kSet = CBS_ASN1_SET;
46 
47 // Primitive/constructed bits
48 const unsigned kTagPrimitive = 0x00;
49 const unsigned kTagConstructed = CBS_ASN1_CONSTRUCTED;
50 
51 // Tag classes
52 const unsigned kTagUniversal = 0x00;
53 const unsigned kTagApplication = CBS_ASN1_APPLICATION;
54 const unsigned kTagContextSpecific = CBS_ASN1_CONTEXT_SPECIFIC;
55 const unsigned kTagPrivate = CBS_ASN1_PRIVATE;
56 
57 // Masks for the 3 components of a tag (class, primitive/constructed, number)
58 const unsigned kTagNumberMask = CBS_ASN1_TAG_NUMBER_MASK;
59 const unsigned kTagConstructionMask = CBS_ASN1_CONSTRUCTED;
60 const unsigned kTagClassMask = CBS_ASN1_CLASS_MASK;
61 
62 // Creates the value for the outer tag of an explicitly tagged type.
63 //
64 // The ASN.1 keyword for this is:
65 //     [tag_number] EXPLICIT
66 //
67 // (Note, the EXPLICIT may be omitted if the entire schema is in
68 // EXPLICIT mode, the default)
69 NET_EXPORT Tag ContextSpecificConstructed(uint8_t tag_number);
70 
71 NET_EXPORT Tag ContextSpecificPrimitive(uint8_t base);
72 
73 NET_EXPORT bool IsConstructed(Tag tag);
74 
75 }  // namespace net::der
76 
77 #endif  // NET_DER_TAG_H_
78