aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-11-14 17:30:05 -0500
committerJack Lloyd <[email protected]>2017-11-14 17:30:05 -0500
commit76fd273cadcdeebd6f9e0f79f47c21971088a37a (patch)
treee651320011374ba723e9983cc646e3ba21c09e7e /src/lib
parent6ff498730653d9837af32efaa5d4298d302cec73 (diff)
Consolidate function for testing for ASN.1 string types
Diffstat (limited to 'src/lib')
-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
3 files changed, 24 insertions, 27 deletions
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)