8#include <botan/asn1_obj.h>
10#include <botan/ber_dec.h>
11#include <botan/der_enc.h>
12#include <botan/internal/charset.h>
13#include <botan/internal/ct_utils.h>
14#include <botan/internal/fmt.h>
23ASN1_Type choose_encoding(std::string_view str) {
26 for(
size_t i = 0; i != str.size(); ++i) {
27 const uint8_t c =
static_cast<uint8_t
>(str[i]);
33 auto is_print_punc =
CT::Mask<uint8_t>::is_any_of(c, {
' ',
'(',
')',
'+',
',',
'-',
'.',
'/',
':',
'=',
'?'});
35 auto is_printable = is_alpha_lower | is_alpha_upper | is_decimal | is_print_punc;
37 all_printable &= is_printable;
40 if(all_printable.as_bool()) {
47bool is_utf8_subset_string_type(
ASN1_Type tag) {
61 return is_asn1_string_type(tag);
65 if(!is_utf8_subset_string_type(m_tag)) {
66 throw Invalid_Argument(
"ASN1_String only supports encoding to UTF-8 or a UTF-8 subset");
91 if(!is_asn1_string_type(obj.
type())) {
92 auto typ =
static_cast<uint32_t
>(obj.
type());
100 m_utf8_str =
ucs2_to_utf8(m_data.data(), m_data.size());
102 m_utf8_str =
ucs4_to_utf8(m_data.data(), m_data.size());
#define BOTAN_ASSERT_NOMSG(expr)
void encode_into(DER_Encoder &) const override
ASN1_String(std::string_view utf8="")
static bool is_string_type(ASN1_Type tag)
ASN1_Type tagging() const
void decode_from(BER_Decoder &) override
BER_Object get_next_object()
const uint8_t * bits() const
static constexpr Mask< T > set()
static constexpr Mask< T > is_within_range(T v, T l, T u)
static constexpr Mask< T > is_any_of(T v, std::initializer_list< T > accepted)
DER_Encoder & add_object(ASN1_Type type_tag, ASN1_Class class_tag, const uint8_t rep[], size_t length)
std::string to_string(const BER_Object &obj)
std::string fmt(std::string_view format, const T &... args)
std::string ucs2_to_utf8(const uint8_t ucs2[], size_t len)
std::string latin1_to_utf8(const uint8_t chars[], size_t len)
std::string ucs4_to_utf8(const uint8_t ucs4[], size_t len)