aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli/asn1.cpp8
-rw-r--r--src/lib/asn1/asn1_str.cpp23
-rw-r--r--src/lib/asn1/asn1_str.h6
-rw-r--r--src/lib/x509/asn1_alt_name.cpp22
4 files changed, 25 insertions, 34 deletions
diff --git a/src/cli/asn1.cpp b/src/cli/asn1.cpp
index 234cbd6e6..08c2562ba 100644
--- a/src/cli/asn1.cpp
+++ b/src/cli/asn1.cpp
@@ -336,13 +336,7 @@ void decode(std::ostream& output,
emit(output, type_name(type_tag), level, length, bit_str);
}
- else if(type_tag == Botan::PRINTABLE_STRING ||
- type_tag == Botan::NUMERIC_STRING ||
- type_tag == Botan::IA5_STRING ||
- type_tag == Botan::T61_STRING ||
- type_tag == Botan::VISIBLE_STRING ||
- type_tag == Botan::UTF8_STRING ||
- type_tag == Botan::BMP_STRING)
+ else if(Botan::ASN1_String::is_string_type(type_tag))
{
Botan::ASN1_String str;
data.decode(str);
diff --git a/src/lib/asn1/asn1_str.cpp b/src/lib/asn1/asn1_str.cpp
index d90aa215b..8b9524de2 100644
--- a/src/lib/asn1/asn1_str.cpp
+++ b/src/lib/asn1/asn1_str.cpp
@@ -55,14 +55,7 @@ ASN1_Tag choose_encoding(const std::string& str)
void assert_is_string_type(ASN1_Tag tag)
{
- if(tag != NUMERIC_STRING &&
- tag != PRINTABLE_STRING &&
- tag != VISIBLE_STRING &&
- tag != T61_STRING &&
- tag != IA5_STRING &&
- tag != UTF8_STRING &&
- tag != BMP_STRING &&
- tag != UNIVERSAL_STRING)
+ if(!ASN1_String::is_string_type(tag))
{
throw Invalid_Argument("ASN1_String: Unknown string type " +
std::to_string(tag));
@@ -71,6 +64,20 @@ void assert_is_string_type(ASN1_Tag tag)
}
+//static
+bool ASN1_String::is_string_type(ASN1_Tag tag)
+ {
+ return (tag == NUMERIC_STRING ||
+ tag == PRINTABLE_STRING ||
+ tag == VISIBLE_STRING ||
+ tag == T61_STRING ||
+ tag == IA5_STRING ||
+ tag == UTF8_STRING ||
+ tag == BMP_STRING ||
+ tag == UNIVERSAL_STRING);
+ }
+
+
/*
* Create an ASN1_String
*/
diff --git a/src/lib/asn1/asn1_str.h b/src/lib/asn1/asn1_str.h
index f19265494..77e2fc145 100644
--- a/src/lib/asn1/asn1_str.h
+++ b/src/lib/asn1/asn1_str.h
@@ -29,6 +29,12 @@ class BOTAN_PUBLIC_API(2,0) ASN1_String final : public ASN1_Object
std::string BOTAN_DEPRECATED("Use value() to get UTF-8 string instead")
iso_8859() const;
+ /**
+ * 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
+ */
+ static bool is_string_type(ASN1_Tag tag);
+
explicit ASN1_String(const std::string& utf8 = "");
ASN1_String(const std::string& utf8, ASN1_Tag tag);
private:
diff --git a/src/lib/x509/asn1_alt_name.cpp b/src/lib/x509/asn1_alt_name.cpp
index 04e11bbcd..6b3eda917 100644
--- a/src/lib/x509/asn1_alt_name.cpp
+++ b/src/lib/x509/asn1_alt_name.cpp
@@ -16,24 +16,6 @@
namespace Botan {
-namespace {
-
-/*
-* Check if type is a known ASN.1 string type
-*/
-bool is_string_type(ASN1_Tag tag)
- {
- return (tag == NUMERIC_STRING ||
- tag == PRINTABLE_STRING ||
- tag == VISIBLE_STRING ||
- tag == T61_STRING ||
- tag == IA5_STRING ||
- tag == UTF8_STRING ||
- tag == BMP_STRING);
- }
-
-}
-
/*
* Create an AlternativeName
*/
@@ -219,8 +201,10 @@ void AlternativeName::decode_from(BER_Decoder& source)
const ASN1_Tag value_type = value.type_tag;
- if(is_string_type(value_type) && value.class_tag == UNIVERSAL)
+ if(ASN1_String::is_string_type(value_type) && value.class_tag == UNIVERSAL)
+ {
add_othername(oid, ASN1::to_string(value), value_type);
+ }
}
}
else if(tag == 1 || tag == 2 || tag == 6)