File: tag.h

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (77 lines) | stat: -rw-r--r-- 2,694 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_DER_TAG_H_
#define NET_DER_TAG_H_

#include <stdint.h>

#include "net/base/net_export.h"
#include "third_party/boringssl/src/include/openssl/bytestring.h"

namespace net::der {

// This Tag type represents the identifier for an ASN.1 tag as encoded with
// DER. It matches the BoringSSL CBS and CBB in-memory representation for a
// tag.
//
// Callers must not assume it matches the DER representation for small tag
// numbers. Instead, constants are provided for universal class types, and
// functions are provided for building context specific tags. Tags can also be
// built from the provided constants and bitmasks.
using Tag = unsigned;

// Universal class primitive types
const Tag kBool = CBS_ASN1_BOOLEAN;
const Tag kInteger = CBS_ASN1_INTEGER;
const Tag kBitString = CBS_ASN1_BITSTRING;
const Tag kOctetString = CBS_ASN1_OCTETSTRING;
const Tag kNull = CBS_ASN1_NULL;
const Tag kOid = CBS_ASN1_OBJECT;
const Tag kEnumerated = CBS_ASN1_ENUMERATED;
const Tag kUtf8String = CBS_ASN1_UTF8STRING;
const Tag kPrintableString = CBS_ASN1_PRINTABLESTRING;
const Tag kTeletexString = CBS_ASN1_T61STRING;
const Tag kIA5String = CBS_ASN1_IA5STRING;
const Tag kUtcTime = CBS_ASN1_UTCTIME;
const Tag kGeneralizedTime = CBS_ASN1_GENERALIZEDTIME;
const Tag kVisibleString = CBS_ASN1_VISIBLESTRING;
const Tag kUniversalString = CBS_ASN1_UNIVERSALSTRING;
const Tag kBmpString = CBS_ASN1_BMPSTRING;

// Universal class constructed types
const Tag kSequence = CBS_ASN1_SEQUENCE;
const Tag kSet = CBS_ASN1_SET;

// Primitive/constructed bits
const unsigned kTagPrimitive = 0x00;
const unsigned kTagConstructed = CBS_ASN1_CONSTRUCTED;

// Tag classes
const unsigned kTagUniversal = 0x00;
const unsigned kTagApplication = CBS_ASN1_APPLICATION;
const unsigned kTagContextSpecific = CBS_ASN1_CONTEXT_SPECIFIC;
const unsigned kTagPrivate = CBS_ASN1_PRIVATE;

// Masks for the 3 components of a tag (class, primitive/constructed, number)
const unsigned kTagNumberMask = CBS_ASN1_TAG_NUMBER_MASK;
const unsigned kTagConstructionMask = CBS_ASN1_CONSTRUCTED;
const unsigned kTagClassMask = CBS_ASN1_CLASS_MASK;

// Creates the value for the outer tag of an explicitly tagged type.
//
// The ASN.1 keyword for this is:
//     [tag_number] EXPLICIT
//
// (Note, the EXPLICIT may be omitted if the entire schema is in
// EXPLICIT mode, the default)
NET_EXPORT Tag ContextSpecificConstructed(uint8_t tag_number);

NET_EXPORT Tag ContextSpecificPrimitive(uint8_t base);

NET_EXPORT bool IsConstructed(Tag tag);

}  // namespace net::der

#endif  // NET_DER_TAG_H_