Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | List of all members
Botan::ASN1_String Class Referencefinal

`#include <asn1_str.h>`

Inheritance diagram for Botan::ASN1_String:

## Public Member Functions
| ASN1_String (const std::string &utf8="")
| ASN1_String (const std::string &utf8, ASN1_Tag tag)
std::vector< uint8_t > | BER_encode () const
void | decode_from (class BER_Decoder &) override
bool | empty () const
void | encode_into (class DER_Encoder &) const override
std::string | iso_8859 () const
bool | operator== (const ASN1_String &other) const
size_t | size () const
ASN1_Tag | tagging () const
const std::string & | value () const

## Static Public Member Functions
static bool | is_string_type (ASN1_Tag tag)

## Detailed Description

ASN.1 string type This class normalizes all inputs to a UTF-8 std::string

Definition at line 19 of file asn1_str.h.

## Constructor & Destructor Documentation

Botan::ASN1_String::ASN1_String | ( | const std::string & | utf8 = `""` | ) |
| explicit

Definition at line 97 of file asn1_str.cpp.

97 :
98 m_utf8_str(str),
99 m_tag(choose_encoding(m_utf8_str))
100 {}

Botan::ASN1_String::ASN1_String | ( | const std::string & | utf8,
|  | ASN1_Tag | tag
| ) |  |

Definition at line 84 of file asn1_str.cpp.

References Botan::DIRECTORY_STRING.

84 : m_utf8_str(str), m_tag(t)
85 {
86 if(m_tag == DIRECTORY_STRING)
87 {
88 m_tag = choose_encoding(m_utf8_str);
89 }
90
91 assert_is_string_type(m_tag);
92 }
Botan::DIRECTORY_STRING
Definition: asn1_obj.h:57

## Member Function Documentation

std::vector< uint8_t > Botan::ASN1_Object::BER_encode | ( |  | ) | const
| inherited

Return the encoding of this object. This is a convenience method when just one object needs to be serialized. Use DER_Encoder for complicated encodings.

Definition at line 16 of file asn1_obj.cpp.

References Botan::ASN1_Object::encode_into().

Referenced by Botan::PSSR::config_for_x509(), Botan::Certificate_Store_In_SQL::find_all_certs(), Botan::Certificate_Store_In_SQL::find_cert(), Botan::X509_Certificate::fingerprint(), Botan::Certificate_Store_In_SQL::insert_cert(), Botan::X509_Object::PEM_encode(), and Botan::Certificate_Store_In_SQL::revoke_cert().

17 {
18 std::vector<uint8_t> output;
19 DER_Encoder der(output);
20 this->encode_into(der);
21 return output;
22 }
Botan::ASN1_Object::encode_into
virtual void encode_into(DER_Encoder &to) const =0

void Botan::ASN1_String::decode_from | ( | class BER_Decoder & | from | ) |
| override virtual

Decode whatever this object is from from

Parameters

  from | the BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 129 of file asn1_str.cpp.

References Botan::BER_Object::bits(), Botan::BMP_STRING, Botan::BER_Decoder::get_next_object(), Botan::BER_Object::length(), Botan::ASN1::to_string(), Botan::BER_Object::type(), Botan::ucs2_to_utf8(), Botan::ucs4_to_utf8(), and Botan::UNIVERSAL_STRING.

130 {
131 BER_Object obj = source.get_next_object();
132
133 assert_is_string_type(obj.type());
134
135 m_tag = obj.type();
136 m_data.assign(obj.bits(), obj.bits() + obj.length());
137
138 if(m_tag == BMP_STRING)
139 {
140 m_utf8_str = ucs2_to_utf8(m_data.data(), m_data.size());
141 }
142 else if(m_tag == UNIVERSAL_STRING)
143 {
144 m_utf8_str = ucs4_to_utf8(m_data.data(), m_data.size());
145 }
146 else
147 {
148 // All other supported string types are UTF-8 or some subset thereof
149 m_utf8_str = ASN1::to_string(obj);
150 }
151 }
Botan::ucs4_to_utf8
std::string ucs4_to_utf8(const uint8_t ucs4[], size_t len)
Definition: charset.cpp:78
Botan::UNIVERSAL_STRING
Definition: asn1_obj.h:49
Botan::ucs2_to_utf8
std::string ucs2_to_utf8(const uint8_t ucs2[], size_t len)
Definition: charset.cpp:61
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213
Botan::BMP_STRING
Definition: asn1_obj.h:50

bool Botan::ASN1_String::empty | ( |  | ) | const
| inline

Definition at line 31 of file asn1_str.h.

Referenced by Botan::X509_DN::add_attribute().

31 { return m_utf8_str.empty(); }

void Botan::ASN1_String::encode_into | ( | class DER_Encoder & | to | ) | const
| override virtual

Encode whatever this object is into to

Parameters

  to | the DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 113 of file asn1_str.cpp.

References Botan::DER_Encoder::add_object(), tagging(), and Botan::UNIVERSAL.

114 {
115 if(m_data.empty())
116 {
117 encoder.add_object(tagging(), UNIVERSAL, m_utf8_str);
118 }
119 else
120 {
121 // If this string was decoded, reserialize using original encoding
122 encoder.add_object(tagging(), UNIVERSAL, m_data.data(), m_data.size());
123 }
124 }
Botan::ASN1_String::tagging
ASN1_Tag tagging() const
Definition: asn1_str.h:25
Botan::UNIVERSAL
Definition: asn1_obj.h:24

bool Botan::ASN1_String::is_string_type | ( | ASN1_Tag | tag | ) |
| static

Return true iff this is a tag for a known string type we can handle. This ignores string types that are not supported, eg teletexString

Definition at line 68 of file asn1_str.cpp.

References Botan::BMP_STRING, Botan::IA5_STRING, Botan::NUMERIC_STRING, Botan::PRINTABLE_STRING, Botan::T61_STRING, Botan::UNIVERSAL_STRING, Botan::UTF8_STRING, and Botan::VISIBLE_STRING.

Referenced by Botan::AlternativeName::decode_from().

69 {
70 return (tag == NUMERIC_STRING ||
71 tag == PRINTABLE_STRING ||
72 tag == VISIBLE_STRING ||
73 tag == T61_STRING ||
74 tag == IA5_STRING ||
75 tag == UTF8_STRING ||
76 tag == BMP_STRING ||
77 tag == UNIVERSAL_STRING);
78 }
Botan::NUMERIC_STRING
Definition: asn1_obj.h:44
Botan::UNIVERSAL_STRING
Definition: asn1_obj.h:49
Botan::VISIBLE_STRING
Definition: asn1_obj.h:48
Botan::BMP_STRING
Definition: asn1_obj.h:50
Botan::IA5_STRING
Definition: asn1_obj.h:47
Botan::UTF8_STRING
Definition: asn1_obj.h:43
Botan::PRINTABLE_STRING
Definition: asn1_obj.h:45
Botan::T61_STRING
Definition: asn1_obj.h:46

std::string Botan::ASN1_String::iso_8859 | ( |  | ) | const

Definition at line 105 of file asn1_str.cpp.

References Botan::utf8_to_latin1().

106 {
107 return utf8_to_latin1(m_utf8_str);
108 }
Botan::utf8_to_latin1
std::string utf8_to_latin1(const std::string &utf8)
Definition: charset.cpp:98

bool Botan::ASN1_String::operator== | ( | const ASN1_String & | other | ) | const
| inline

Definition at line 42 of file asn1_str.h.

43 { return value() == other.value(); }
Botan::ASN1_String::value
const std::string & value() const
Definition: asn1_str.h:27

size_t Botan::ASN1_String::size | ( |  | ) | const
| inline

Definition at line 29 of file asn1_str.h.

29 { return value().size(); }
Botan::ASN1_String::value
const std::string & value() const
Definition: asn1_str.h:27

ASN1_Tag Botan::ASN1_String::tagging | ( |  | ) | const
| inline

Definition at line 25 of file asn1_str.h.

Referenced by encode_into().

25 { return m_tag; }

const std::string& Botan::ASN1_String::value | ( |  | ) | const
| inline

Definition at line 27 of file asn1_str.h.

Referenced by Botan::X509_DN::get_first_attribute(), and Botan::TLS::Session::Session().

27 { return m_utf8_str; }

The documentation for this class was generated from the following files:

- src/lib/asn1/asn1_str.h
- src/lib/asn1/asn1_str.cpp