Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

asn1_obj.cpp
Go to the documentation of this file.
1 /*
2 * ASN.1 Internals
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/asn1_obj.h>
9 #include <botan/der_enc.h>
10 #include <botan/ber_dec.h>
11 #include <botan/data_src.h>
12 #include <botan/parsing.h>
13 #include <botan/internal/stl_util.h>
14
15 namespace Botan {
16
17 /*
18 * BER Decoding Exceptions
19 */
20 BER_Decoding_Error::BER_Decoding_Error(const std::string& str) :
21 Decoding_Error("BER: " + str) {}
22
23 BER_Bad_Tag::BER_Bad_Tag(const std::string& str, ASN1_Tag tag) :
24 BER_Decoding_Error(str + ": " + std::to_string(tag)) {}
25
26 BER_Bad_Tag::BER_Bad_Tag(const std::string& str,
27 ASN1_Tag tag1, ASN1_Tag tag2) :
28 BER_Decoding_Error(str + ": " + std::to_string(tag1) + "/" + std::to_string(tag2)) {}
29
30 namespace ASN1 {
31
32 /*
33 * Put some arbitrary bytes into a SEQUENCE
34 */
35 std::vector<uint8_t> put_in_sequence(const std::vector<uint8_t>& contents)
36 {
37 return DER_Encoder()
38 .start_cons(SEQUENCE)
39 .raw_bytes(contents)
40 .end_cons()
41 .get_contents_unlocked();
42 }
43
44 /*
45 * Convert a BER object into a string object
46 */
47 std::string to_string(const BER_Object& obj)
48 {
49 return to_string(obj.value);
50 }
51
52 /*
53 * Do heuristic tests for BER data
54 */
55 bool maybe_BER(DataSource& source)
56 {
57 uint8_t first_u8;
58 if(!source.peek_byte(first_u8))
59 {
60 BOTAN_ASSERT_EQUAL(source.read_byte(first_u8), 0, "Expected EOF");
61 throw Stream_IO_Error("ASN1::maybe_BER: Source was empty");
62 }
63
64 if(first_u8 == (SEQUENCE | CONSTRUCTED))
65 return true;
66 return false;
67 }
68
69 }
70
71 }
Botan::Stream_IO_Error
Definition: exceptn.h:216
Botan::BER_Decoding_Error::BER_Decoding_Error
BER_Decoding_Error(const std::string &)
Definition: asn1_obj.cpp:20
Botan::BER_Bad_Tag::BER_Bad_Tag
BER_Bad_Tag(const std::string &msg, ASN1_Tag tag)
Definition: asn1_obj.cpp:23
Botan::DER_Encoder::get_contents_unlocked
std::vector< uint8_t > get_contents_unlocked()
Definition: der_enc.h:27
std
Definition: bigint.h:619
Botan::ASN1::maybe_BER
bool maybe_BER(DataSource &source)
Definition: asn1_obj.cpp:55
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:47
Botan::DER_Encoder::end_cons
DER_Encoder & end_cons()
Definition: der_enc.cpp:147
Botan::DataSource
Definition: data_src.h:21
Botan::DER_Encoder::raw_bytes
DER_Encoder & raw_bytes(const uint8_t val[], size_t len)
Definition: der_enc.cpp:195
Botan::DER_Encoder
Definition: der_enc.h:22
Botan::BER_Object::value
secure_vector< uint8_t > value
Definition: asn1_obj.h:94
Botan::CONSTRUCTED
Definition: asn1_obj.h:27
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_obj.h:22
BOTAN_ASSERT_EQUAL
#define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made)
Definition: assert.h:53
Botan::Decoding_Error
Definition: exceptn.h:189
Botan::SEQUENCE
Definition: asn1_obj.h:39
Botan
Definition: alg_id.cpp:13
Botan::DataSource::read_byte
size_t read_byte(uint8_t &out)
Definition: data_src.cpp:22
Botan::ASN1::put_in_sequence
std::vector< uint8_t > put_in_sequence(const std::vector< uint8_t > &contents)
Definition: asn1_obj.cpp:35
Botan::to_string
std::string to_string(const secure_vector< uint8_t > &bytes)
Definition: stl_util.h:25
Botan::DataSource::peek_byte
size_t peek_byte(uint8_t &out) const
Definition: data_src.cpp:30
Botan::BER_Decoding_Error
Definition: asn1_obj.h:118
Botan::DER_Encoder::start_cons
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:137
Botan::BER_Object
Definition: asn1_obj.h:85