Botan  2.1.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::ASN1_String Class Referencefinal

#include <asn1_str.h>

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

Public Member Functions

 ASN1_String (const std::string &="")
 
 ASN1_String (const std::string &, ASN1_Tag)
 
void decode_from (class BER_Decoder &) override
 
void encode_into (class DER_Encoder &) const override
 
std::string iso_8859 () const
 
ASN1_Tag tagging () const
 
std::string value () const
 

Detailed Description

Simple String

Definition at line 18 of file asn1_str.h.

Constructor & Destructor Documentation

Botan::ASN1_String::ASN1_String ( const std::string &  str = "")
explicit

Definition at line 85 of file asn1_str.cpp.

Referenced by decode_from().

85  : m_iso_8859_str(Charset::transcode(str, LOCAL_CHARSET, LATIN1_CHARSET)), m_tag(choose_encoding(m_iso_8859_str, "latin1"))
86  {}
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:103
Botan::ASN1_String::ASN1_String ( const std::string &  str,
ASN1_Tag  t 
)

Definition at line 65 of file asn1_str.cpp.

References Botan::BMP_STRING, Botan::DIRECTORY_STRING, Botan::IA5_STRING, Botan::NUMERIC_STRING, Botan::PRINTABLE_STRING, Botan::T61_STRING, Botan::ASN1::to_string(), Botan::UTF8_STRING, and Botan::VISIBLE_STRING.

65  : m_iso_8859_str(Charset::transcode(str, LOCAL_CHARSET, LATIN1_CHARSET)), m_tag(t)
66  {
67 
68  if(m_tag == DIRECTORY_STRING)
69  m_tag = choose_encoding(m_iso_8859_str, "latin1");
70 
71  if(m_tag != NUMERIC_STRING &&
72  m_tag != PRINTABLE_STRING &&
73  m_tag != VISIBLE_STRING &&
74  m_tag != T61_STRING &&
75  m_tag != IA5_STRING &&
76  m_tag != UTF8_STRING &&
77  m_tag != BMP_STRING)
78  throw Invalid_Argument("ASN1_String: Unknown string type " +
79  std::to_string(m_tag));
80  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:47
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:103

Member Function Documentation

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 126 of file asn1_str.cpp.

References ASN1_String(), Botan::BMP_STRING, Botan::BER_Decoder::get_next_object(), Botan::LATIN1_CHARSET, Botan::LOCAL_CHARSET, Botan::ASN1::to_string(), Botan::Charset::transcode(), Botan::BER_Object::type_tag, Botan::UCS2_CHARSET, Botan::UTF8_CHARSET, and Botan::UTF8_STRING.

127  {
128  BER_Object obj = source.get_next_object();
129 
130  Character_Set charset_is;
131 
132  if(obj.type_tag == BMP_STRING)
133  charset_is = UCS2_CHARSET;
134  else if(obj.type_tag == UTF8_STRING)
135  charset_is = UTF8_CHARSET;
136  else
137  charset_is = LATIN1_CHARSET;
138 
139  *this = ASN1_String(
141  obj.type_tag);
142  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:47
Character_Set
Definition: charset.h:19
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:103
ASN1_String(const std::string &="")
Definition: asn1_str.cpp:85
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 115 of file asn1_str.cpp.

References Botan::DER_Encoder::add_object(), iso_8859(), Botan::LATIN1_CHARSET, tagging(), Botan::Charset::transcode(), Botan::UNIVERSAL, Botan::UTF8_CHARSET, Botan::UTF8_STRING, and value().

116  {
117  std::string value = iso_8859();
118  if(tagging() == UTF8_STRING)
120  encoder.add_object(tagging(), UNIVERSAL, value);
121  }
ASN1_Tag tagging() const
Definition: asn1_str.cpp:107
std::string value() const
Definition: asn1_str.cpp:99
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:103
std::string iso_8859() const
Definition: asn1_str.cpp:91
std::string Botan::ASN1_String::iso_8859 ( ) const

Definition at line 91 of file asn1_str.cpp.

Referenced by encode_into().

92  {
93  return m_iso_8859_str;
94  }
ASN1_Tag Botan::ASN1_String::tagging ( ) const

Definition at line 107 of file asn1_str.cpp.

Referenced by encode_into().

108  {
109  return m_tag;
110  }
std::string Botan::ASN1_String::value ( ) const

Definition at line 99 of file asn1_str.cpp.

References Botan::LATIN1_CHARSET, Botan::LOCAL_CHARSET, and Botan::Charset::transcode().

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

100  {
101  return Charset::transcode(m_iso_8859_str, LATIN1_CHARSET, LOCAL_CHARSET);
102  }
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:103

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