aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/asn1
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/asn1
parent6ff498730653d9837af32efaa5d4298d302cec73 (diff)
Consolidate function for testing for ASN.1 string types
Diffstat (limited to 'src/lib/asn1')
-rw-r--r--src/lib/asn1/asn1_str.cpp23
-rw-r--r--src/lib/asn1/asn1_str.h6
2 files changed, 21 insertions, 8 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: