Botan 1.10.17
asn1_int.h
Go to the documentation of this file.
1/*
2* ASN.1 Internals
3* (C) 1999-2007 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
6*/
7
8#ifndef BOTAN_ASN1_H__
9#define BOTAN_ASN1_H__
10
11#include <botan/secmem.h>
12#include <botan/exceptn.h>
13
14namespace Botan {
15
16/**
17* ASN.1 Type and Class Tags
18*/
20 UNIVERSAL = 0x00,
23 PRIVATE = 0xC0,
24
26
27 EOC = 0x00,
28 BOOLEAN = 0x01,
29 INTEGER = 0x02,
30 BIT_STRING = 0x03,
32 NULL_TAG = 0x05,
33 OBJECT_ID = 0x06,
34 ENUMERATED = 0x0A,
35 SEQUENCE = 0x10,
36 SET = 0x11,
37
41 T61_STRING = 0x14,
42 IA5_STRING = 0x16,
44 BMP_STRING = 0x1E,
45
46 UTC_TIME = 0x17,
48
49 NO_OBJECT = 0xFF00,
51};
52
53/**
54* Basic ASN.1 Object Interface
55*/
56class BOTAN_DLL ASN1_Object
57 {
58 public:
59 /**
60 * Encode whatever this object is into to
61 * @param to the DER_Encoder that will be written to
62 */
63 virtual void encode_into(class DER_Encoder& to) const = 0;
64
65 /**
66 * Decode whatever this object is from from
67 * @param from the BER_Decoder that will be read from
68 */
69 virtual void decode_from(class BER_Decoder& from) = 0;
70
71 virtual ~ASN1_Object() {}
72 };
73
74/**
75* BER Encoded Object
76*/
77class BOTAN_DLL BER_Object
78 {
79 public:
81
84 };
85
86/*
87* ASN.1 Utility Functions
88*/
89class DataSource;
90
91namespace ASN1 {
92
94std::string to_string(const BER_Object& obj);
95
96/**
97* Heuristics tests; is this object possibly BER?
98* @param src a data source that will be peeked at but not modified
99*/
100bool maybe_BER(DataSource& src);
101
102}
103
104/**
105* General BER Decoding Error Exception
106*/
107struct BOTAN_DLL BER_Decoding_Error : public Decoding_Error
108 {
109 BER_Decoding_Error(const std::string&);
110 };
111
112/**
113* Exception For Incorrect BER Taggings
114*/
115struct BOTAN_DLL BER_Bad_Tag : public BER_Decoding_Error
116 {
117 BER_Bad_Tag(const std::string& msg, ASN1_Tag tag);
118 BER_Bad_Tag(const std::string& msg, ASN1_Tag tag1, ASN1_Tag tag2);
119 };
120
121}
122
123#endif
virtual void encode_into(class DER_Encoder &to) const =0
virtual ~ASN1_Object()
Definition asn1_int.h:71
virtual void decode_from(class BER_Decoder &from)=0
SecureVector< byte > value
Definition asn1_int.h:83
ASN1_Tag class_tag
Definition asn1_int.h:82
void assert_is_a(ASN1_Tag, ASN1_Tag)
Definition ber_dec.cpp:144
ASN1_Tag type_tag
Definition asn1_int.h:82
bool maybe_BER(DataSource &source)
Definition asn1_int.cpp:55
SecureVector< byte > put_in_sequence(const MemoryRegion< byte > &contents)
Definition asn1_int.cpp:34
std::string to_string(u64bit n, size_t min_len)
Definition parsing.cpp:42
ASN1_Tag
Definition asn1_int.h:19
@ UTC_TIME
Definition asn1_int.h:46
@ DIRECTORY_STRING
Definition asn1_int.h:50
@ CONSTRUCTED
Definition asn1_int.h:25
@ GENERALIZED_TIME
Definition asn1_int.h:47
@ IA5_STRING
Definition asn1_int.h:42
@ BIT_STRING
Definition asn1_int.h:30
@ PRINTABLE_STRING
Definition asn1_int.h:40
@ T61_STRING
Definition asn1_int.h:41
@ UTF8_STRING
Definition asn1_int.h:38
@ SEQUENCE
Definition asn1_int.h:35
@ APPLICATION
Definition asn1_int.h:21
@ NUMERIC_STRING
Definition asn1_int.h:39
@ BOOLEAN
Definition asn1_int.h:28
@ CONTEXT_SPECIFIC
Definition asn1_int.h:22
@ BMP_STRING
Definition asn1_int.h:44
@ ENUMERATED
Definition asn1_int.h:34
@ NO_OBJECT
Definition asn1_int.h:49
@ OCTET_STRING
Definition asn1_int.h:31
@ NULL_TAG
Definition asn1_int.h:32
@ UNIVERSAL
Definition asn1_int.h:20
@ VISIBLE_STRING
Definition asn1_int.h:43
@ EOC
Definition asn1_int.h:27
@ OBJECT_ID
Definition asn1_int.h:33
@ SET
Definition asn1_int.h:36
@ INTEGER
Definition asn1_int.h:29
@ PRIVATE
Definition asn1_int.h:23
BER_Bad_Tag(const std::string &msg, ASN1_Tag tag)
Definition asn1_int.cpp:22
BER_Decoding_Error(const std::string &)
Definition asn1_int.cpp:19
Decoding_Error(const std::string &name)
Definition exceptn.h:140