Botan 2.19.0
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | List of all members
Botan::ASN1_String Class Referencefinal

#include <asn1_obj.h>

Inheritance diagram for Botan::ASN1_String:
Botan::ASN1_Object

Public Member Functions

 ASN1_String (const std::string &utf8, ASN1_Tag tag)
 
 ASN1_String (const std::string &utf8="")
 
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 392 of file asn1_obj.h.

Constructor & Destructor Documentation

◆ ASN1_String() [1/2]

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 {}

◆ ASN1_String() [2/2]

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

Definition at line 84 of file asn1_str.cpp.

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 }
@ DIRECTORY_STRING
Definition: asn1_obj.h:59

References Botan::DIRECTORY_STRING.

Member Function Documentation

◆ BER_encode()

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.

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

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().

◆ decode_from()

void Botan::ASN1_String::decode_from ( class BER_Decoder from)
overridevirtual

Decode whatever this object is from from

Parameters
fromthe BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 129 of file asn1_str.cpp.

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 }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213
std::string ucs4_to_utf8(const uint8_t ucs4[], size_t len)
Definition: charset.cpp:78
std::string ucs2_to_utf8(const uint8_t ucs2[], size_t len)
Definition: charset.cpp:61
@ UNIVERSAL_STRING
Definition: asn1_obj.h:51
@ BMP_STRING
Definition: asn1_obj.h:52

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.

◆ empty()

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

Definition at line 404 of file asn1_obj.h.

404{ return m_utf8_str.empty(); }

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

◆ encode_into()

void Botan::ASN1_String::encode_into ( class DER_Encoder to) const
overridevirtual

Encode whatever this object is into to

Parameters
tothe DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 113 of file asn1_str.cpp.

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 }
ASN1_Tag tagging() const
Definition: asn1_obj.h:398
@ UNIVERSAL
Definition: asn1_obj.h:26

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

◆ is_string_type()

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.

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 }
@ IA5_STRING
Definition: asn1_obj.h:49
@ PRINTABLE_STRING
Definition: asn1_obj.h:47
@ T61_STRING
Definition: asn1_obj.h:48
@ UTF8_STRING
Definition: asn1_obj.h:45
@ NUMERIC_STRING
Definition: asn1_obj.h:46
@ VISIBLE_STRING
Definition: asn1_obj.h:50

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().

◆ iso_8859()

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

Definition at line 105 of file asn1_str.cpp.

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

References Botan::utf8_to_latin1().

◆ operator==()

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

Definition at line 415 of file asn1_obj.h.

416 { return value() == other.value(); }
const std::string & value() const
Definition: asn1_obj.h:400

◆ size()

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

Definition at line 402 of file asn1_obj.h.

402{ return value().size(); }

◆ tagging()

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

Definition at line 398 of file asn1_obj.h.

398{ return m_tag; }

Referenced by encode_into().

◆ value()

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

Definition at line 400 of file asn1_obj.h.

400{ return m_utf8_str; }

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


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