Comments / tweaks.
[libdcp.git] / src / kdm.cc
index 9d40cff746df4408e5781c1602cc8f1aec7b91fe..fe7fe393381a8c977dd62e6c71012fb0283f944f 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 */
 
-#include <iomanip>
-#include <algorithm>
-#include <boost/algorithm/string.hpp>
-#include <openssl/rsa.h>
-#include <openssl/pem.h>
-#include <openssl/err.h>
-#include <libcxml/cxml.h>
-#include "AS_DCP.h"
-#include "KM_util.h"
+/** @file  src/kdm.cc
+ *  @brief KDM and KDMKey classes.
+ */
+
 #include "util.h"
 #include "kdm.h"
 #include "compose.hpp"
 #include "exceptions.h"
 #include "signer.h"
 #include "cpl.h"
-#include "mxf_asset.h"
-#include "xml/kdm_smpte.h"
+#include "mxf.h"
+#include "kdm_smpte_xml.h"
+#include "AS_DCP.h"
+#include "KM_util.h"
+#include <libcxml/cxml.h>
+#include <openssl/rsa.h>
+#include <openssl/pem.h>
+#include <openssl/err.h>
+#include <boost/algorithm/string.hpp>
+#include <iomanip>
+#include <algorithm>
 
 using std::list;
 using std::string;
@@ -43,7 +47,7 @@ using std::setw;
 using std::setfill;
 using std::cout;
 using boost::shared_ptr;
-using namespace libdcp;
+using namespace dcp;
 
 KDM::KDM (boost::filesystem::path kdm, boost::filesystem::path private_key)
        : _xml_kdm (new xml::DCinemaSecurityMessage (kdm))
@@ -52,13 +56,13 @@ KDM::KDM (boost::filesystem::path kdm, boost::filesystem::path private_key)
           
        FILE* private_key_file = fopen_boost (private_key, "r");
        if (!private_key_file) {
-               throw FileError ("could not find RSA private key file", private_key);
+               throw FileError ("could not find RSA private key file", private_key, errno);
        }
        
        RSA* rsa = PEM_read_RSAPrivateKey (private_key_file, 0, 0, 0);
        fclose (private_key_file);      
        if (!rsa) {
-               throw FileError ("could not read RSA private key file", private_key);
+               throw FileError ("could not read RSA private key file", private_key, errno);
        }
 
        /* Use it to decrypt the keys */
@@ -87,7 +91,9 @@ KDM::KDM (boost::filesystem::path kdm, boost::filesystem::path private_key)
 }
 
 KDM::KDM (
-       shared_ptr<const CPL> cpl, shared_ptr<const Signer> signer, shared_ptr<const Certificate> recipient_cert,
+       boost::shared_ptr<const CPL> cpl,
+       boost::shared_ptr<const Signer> signer,
+       boost::shared_ptr<const Certificate> recipient_cert,
        boost::posix_time::ptime not_valid_before, boost::posix_time::ptime not_valid_after,
        string annotation_text, string issue_date
        )
@@ -108,7 +114,7 @@ KDM::KDM (
        apu.recipient.x509_subject_name = recipient_cert->subject ();
        apu.composition_playlist_id = "urn:uuid:" + cpl->id ();
 //     apu.content_authenticator = signer->certificates().leaf()->thumbprint ();
-       apu.content_title_text = cpl->name ();
+       apu.content_title_text = cpl->content_title_text ();
        apu.content_keys_not_valid_before = ptime_to_string (not_valid_before);
        apu.content_keys_not_valid_after = ptime_to_string (not_valid_after);
        apu.authorized_device_info.device_list_identifier = "urn:uuid:" + make_uuid ();
@@ -124,10 +130,10 @@ KDM::KDM (
        */
        apu.authorized_device_info.device_list.push_back ("2jmj7l5rSw0yVb/vlWAYkK/YBwk=");
 
-       list<shared_ptr<const Asset> > assets = cpl->assets ();
-       for (list<shared_ptr<const Asset> >::iterator i = assets.begin(); i != assets.end(); ++i) {
+       list<shared_ptr<const Content> > content = cpl->content ();
+       for (list<shared_ptr<const Content> >::iterator i = content.begin(); i != content.end(); ++i) {
                /* XXX: non-MXF assets? */
-               shared_ptr<const MXFAsset> mxf = boost::dynamic_pointer_cast<const MXFAsset> (*i);
+               shared_ptr<const MXF> mxf = boost::dynamic_pointer_cast<const MXF> (*i);
                if (mxf) {
                        apu.key_id_list.push_back (xml::TypedKeyId (mxf->key_type(), "urn:uuid:" + mxf->key_id()));
                }
@@ -138,9 +144,9 @@ KDM::KDM (
 
        /* AuthenticatedPrivate */
 
-       for (list<shared_ptr<const Asset> >::iterator i = assets.begin(); i != assets.end(); ++i) {
+       for (list<shared_ptr<const Content> >::iterator i = content.begin(); i != content.end(); ++i) {
                /* XXX: non-MXF assets? */
-               shared_ptr<const MXFAsset> mxf = boost::dynamic_pointer_cast<const MXFAsset> (*i);
+               shared_ptr<const MXF> mxf = boost::dynamic_pointer_cast<const MXF> (*i);
                if (mxf) {
                        KDMKey kkey (
                                        signer, cpl->id (), mxf->key_type (), mxf->key_id (),
@@ -202,7 +208,13 @@ KDM::as_xml () const
 }
 
 KDMKey::KDMKey (
-       shared_ptr<const Signer> signer, string cpl_id, string key_type, string key_id, boost::posix_time::ptime from, boost::posix_time::ptime until, Key key
+       boost::shared_ptr<const Signer> signer,
+       string cpl_id,
+       string key_type,
+       string key_id,
+       boost::posix_time::ptime from,
+       boost::posix_time::ptime until,
+       Key key
        )
        : _cpl_id (cpl_id)
        , _key_type (key_type)
@@ -275,7 +287,7 @@ KDMKey::operator= (KDMKey const & other)
 }
 
 string
-KDMKey::encrypted_base64 (shared_ptr<const Certificate> recipient_cert) const
+KDMKey::encrypted_base64 (boost::shared_ptr<const Certificate> recipient_cert) const
 {
        assert (_key_type.length() == 4);
        assert (_not_valid_before.length() == 25);
@@ -383,7 +395,7 @@ KDMKey::put_uuid (uint8_t ** d, string id) const
 }
 
 bool
-libdcp::operator== (libdcp::KDMKey const & a, libdcp::KDMKey const & b)
+dcp::operator== (dcp::KDMKey const & a, dcp::KDMKey const & b)
 {
        if (memcmp (a._signer_thumbprint, b._signer_thumbprint, 20) != 0) {
                return false;