Apply the same rules to closed captions.
[libdcp.git] / src / encrypted_kdm.cc
index 23052f8a2c438bd358acb3e0b8f63628a68c5b30..e8e8987085014297831f97880c2edcd90c783272 100644 (file)
@@ -554,6 +554,7 @@ public:
                        xmlAddID (0, document->cobj(), (const xmlChar *) i->first.c_str(), i->second->cobj ());
                }
 
+               indent (document->get_root_node(), 0);
                return document;
        }
 
@@ -670,7 +671,7 @@ EncryptedKDM::EncryptedKDM (
        xmlpp::Node::NodeList children = doc->get_root_node()->get_children ();
        for (xmlpp::Node::NodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
                if ((*i)->get_name() == "Signature") {
-                       signer->add_signature_value (*i, "ds");
+                       signer->add_signature_value (dynamic_cast<xmlpp::Element*>(*i), "ds", false);
                }
        }
 
@@ -706,9 +707,15 @@ void
 EncryptedKDM::as_xml (boost::filesystem::path path) const
 {
        FILE* f = fopen_boost (path, "w");
+       if (!f) {
+               throw FileError ("Could not open KDM file for writing", path, errno);
+       }
        string const x = as_xml ();
-       fwrite (x.c_str(), 1, x.length(), f);
+       size_t const written = fwrite (x.c_str(), 1, x.length(), f);
        fclose (f);
+       if (written != x.length()) {
+               throw FileError ("Could not write to KDM file", path, errno);
+       }
 }
 
 string
@@ -771,6 +778,17 @@ EncryptedKDM::recipient_x509_subject_name () const
        return _data->authenticated_public.required_extensions.kdm_required_extensions.recipient.x509_subject_name;
 }
 
+CertificateChain
+EncryptedKDM::signer_certificate_chain () const
+{
+       CertificateChain chain;
+       BOOST_FOREACH (data::X509Data const & i, _data->signature.x509_data) {
+               string s = "-----BEGIN CERTIFICATE-----\n" + i.x509_certificate + "\n-----END CERTIFICATE-----";
+               chain.add (Certificate(s));
+       }
+       return chain;
+}
+
 bool
 dcp::operator== (EncryptedKDM const & a, EncryptedKDM const & b)
 {