Add method to detect utf8 strings.
authorCarl Hetherington <cth@carlh.net>
Thu, 8 Mar 2018 21:26:21 +0000 (21:26 +0000)
committerCarl Hetherington <cth@carlh.net>
Thu, 8 Mar 2018 21:26:21 +0000 (21:26 +0000)
src/certificate.cc
src/certificate.h
test/wscript

index 64fb36261b402baa390032e168a880902bd9508f..8064e4abf0265dda905d56b0c33dde237fc7e9c5 100644 (file)
@@ -408,6 +408,22 @@ Certificate::public_key () const
        return _public_key;
 }
 
+static bool string_is_utf8 (X509_NAME* n, int nid)
+{
+       int p = -1;
+       p = X509_NAME_get_index_by_NID (n, nid, p);
+       return p != -1 && X509_NAME_ENTRY_get_data(X509_NAME_get_entry(n, p))->type == V_ASN1_UTF8STRING;
+}
+
+bool
+Certificate::has_utf8_strings () const
+{
+       X509_NAME* n = X509_get_subject_name (_certificate);
+       return string_is_utf8(n, NID_commonName) ||
+               string_is_utf8(n, NID_organizationName) ||
+               string_is_utf8(n, NID_organizationalUnitName);
+}
+
 bool
 dcp::operator== (Certificate const & a, Certificate const & b)
 {
index 326f277b0820a2b224f0cfc28de46845b01c4896..0d333f1e2f61b6104de9a3d6866d7f98eab74565 100644 (file)
@@ -90,6 +90,8 @@ public:
 
        std::string thumbprint () const;
 
+       bool has_utf8_strings () const;
+
 private:
 
        static std::string name_for_xml (X509_NAME *);
index 1afce80521d4c915248b8acbe84d04295a647df8..a11dc2a7a03608e18009e2b044bda34dd941683a 100644 (file)
@@ -94,6 +94,7 @@ def build(bld):
                  sound_frame_test.cc
                  test.cc
                  util_test.cc
+                 utf8_test.cc
                  write_subtitle_test.cc
                  """
     obj.target = 'tests'