Add method to detect utf8 strings.
[libdcp.git] / src / certificate.cc
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)
 {