Botan: Botan::ASN1_String Class Reference

Botan 1.10.17

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

`#include <asn1_str.h>`

Inheritance diagram for Botan::ASN1_String:

## Public Member Functions
| ASN1_String (const std::string &="")
| ASN1_String (const std::string &, ASN1_Tag)
void | decode_from (class BER_Decoder &)
void | encode_into (class DER_Encoder &) const
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

## ◆ ASN1_String() [1/2]

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

Definition at line 86 of file asn1_str.cpp.

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

Referenced by decode_from().

87 {
88 iso_8859_str = Charset::transcode(str, LOCAL_CHARSET, LATIN1_CHARSET);
89 tag = choose_encoding(iso_8859_str, "latin1");
90 }
Botan::Charset::transcode
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:103
Botan::LATIN1_CHARSET
Definition: charset.h:23
Botan::LOCAL_CHARSET
Definition: charset.h:20

## ◆ ASN1_String() [2/2]

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::LATIN1_CHARSET, Botan::LOCAL_CHARSET, Botan::NUMERIC_STRING, Botan::PRINTABLE_STRING, Botan::T61_STRING, Botan::to_string(), Botan::Charset::transcode(), Botan::UTF8_STRING, and Botan::VISIBLE_STRING.

65 : tag(t)
66 {
67 iso_8859_str = Charset::transcode(str, LOCAL_CHARSET, LATIN1_CHARSET);
68
69 if(tag == DIRECTORY_STRING)
70 tag = choose_encoding(iso_8859_str, "latin1");
71
72 if(tag != NUMERIC_STRING &&
73 tag != PRINTABLE_STRING &&
74 tag != VISIBLE_STRING &&
75 tag != T61_STRING &&
76 tag != IA5_STRING &&
77 tag != UTF8_STRING &&
78 tag != BMP_STRING)
79 throw Invalid_Argument("ASN1_String: Unknown string type " +
80 to_string(tag));
81 }
Botan::BMP_STRING
Definition: asn1_int.h:44
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::PRINTABLE_STRING
Definition: asn1_int.h:40
Botan::Charset::transcode
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:103
Botan::T61_STRING
Definition: asn1_int.h:41
Botan::LATIN1_CHARSET
Definition: charset.h:23
Botan::DIRECTORY_STRING
Definition: asn1_int.h:50
Botan::VISIBLE_STRING
Definition: asn1_int.h:43
Botan::LOCAL_CHARSET
Definition: charset.h:20
Botan::NUMERIC_STRING
Definition: asn1_int.h:39
Botan::UTF8_STRING
Definition: asn1_int.h:38
Botan::to_string
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42
Botan::IA5_STRING
Definition: asn1_int.h:42

## Member Function Documentation

## ◆ decode_from()

void Botan::ASN1_String::decode_from | ( | class BER_Decoder & | from | ) |
| 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 130 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.

131 {
132 BER_Object obj = source.get_next_object();
133
134 Character_Set charset_is;
135
136 if(obj.type_tag == BMP_STRING)
137 charset_is = UCS2_CHARSET;
138 else if(obj.type_tag == UTF8_STRING)
139 charset_is = UTF8_CHARSET;
140 else
141 charset_is = LATIN1_CHARSET;
142
143 *this = ASN1_String(
144 Charset::transcode(ASN1::to_string(obj), charset_is, LOCAL_CHARSET),
145 obj.type_tag);
146 }
Botan::BMP_STRING
Definition: asn1_int.h:44
Botan::UTF8_CHARSET
Definition: charset.h:22
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_int.cpp:46
Botan::Character_Set
Character_Set
Definition: charset.h:19
Botan::Charset::transcode
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:103
Botan::ASN1_String::ASN1_String
ASN1_String(const std::string &="")
Definition: asn1_str.cpp:86
Botan::LATIN1_CHARSET
Definition: charset.h:23
Botan::LOCAL_CHARSET
Definition: charset.h:20
Botan::UTF8_STRING
Definition: asn1_int.h:38
Botan::UCS2_CHARSET
Definition: charset.h:21

## ◆ encode_into()

void Botan::ASN1_String::encode_into | ( | class DER_Encoder & | to | ) | const
| 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 119 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().

120 {
121 std::string value = iso_8859();
122 if(tagging() == UTF8_STRING)
123 value = Charset::transcode(value, LATIN1_CHARSET, UTF8_CHARSET);
124 encoder.add_object(tagging(), UNIVERSAL, value);
125 }
Botan::ASN1_String::iso_8859
std::string iso_8859() const
Definition: asn1_str.cpp:95
Botan::UTF8_CHARSET
Definition: charset.h:22
Botan::UNIVERSAL
Definition: asn1_int.h:20
Botan::Charset::transcode
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:103
Botan::ASN1_String::value
std::string value() const
Definition: asn1_str.cpp:103
Botan::LATIN1_CHARSET
Definition: charset.h:23
Botan::UTF8_STRING
Definition: asn1_int.h:38
Botan::ASN1_String::tagging
ASN1_Tag tagging() const
Definition: asn1_str.cpp:111

## ◆ iso_8859()

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

Definition at line 95 of file asn1_str.cpp.

Referenced by encode_into().

96 {
97 return iso_8859_str;
98 }

## ◆ tagging()

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

Definition at line 111 of file asn1_str.cpp.

Referenced by encode_into().

112 {
113 return tag;
114 }

## ◆ value()

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

Definition at line 103 of file asn1_str.cpp.

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

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

104 {
105 return Charset::transcode(iso_8859_str, LATIN1_CHARSET, LOCAL_CHARSET);
106 }
Botan::Charset::transcode
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:103
Botan::LATIN1_CHARSET
Definition: charset.h:23
Botan::LOCAL_CHARSET
Definition: charset.h:20

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

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