Comment typo.
[libdcp.git] / src / decrypted_kdm.cc
index 7113afb8ab512b3ff3d0a6e359abd29f333e7de6..1f68c2835cfc68861249a582d273a07756345f92 100644 (file)
@@ -101,7 +101,11 @@ string
 DecryptedKDM::get_uuid (unsigned char ** p)
 {
        char buffer[37];
+#ifdef LIBDCP_WINDOWS
+       __mingw_snprintf (
+#else
        snprintf (
+#endif
                buffer, sizeof(buffer), "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
                (*p)[0], (*p)[1], (*p)[2], (*p)[3], (*p)[4], (*p)[5], (*p)[6], (*p)[7],
                (*p)[8], (*p)[9], (*p)[10], (*p)[11], (*p)[12], (*p)[13], (*p)[14], (*p)[15]
@@ -149,7 +153,11 @@ DecryptedKDM::DecryptedKDM (EncryptedKDM const & kdm, string private_key)
                int const decrypted_len = RSA_private_decrypt (cipher_value_len, cipher_value, decrypted, rsa, RSA_PKCS1_OAEP_PADDING);
                if (decrypted_len == -1) {
                        delete[] decrypted;
-                       throw KDMDecryptionError (ERR_error_string (ERR_get_error(), 0));
+#if OPENSSL_VERSION_NUMBER > 0x10100000L
+                       throw KDMDecryptionError (ERR_error_string (ERR_get_error(), 0), cipher_value_len, RSA_bits(rsa));
+#else
+                       throw KDMDecryptionError (ERR_error_string (ERR_get_error(), 0), cipher_value_len, rsa->n->dmax);
+#endif
                }
 
                unsigned char* p = decrypted;
@@ -170,7 +178,7 @@ DecryptedKDM::DecryptedKDM (EncryptedKDM const & kdm, string private_key)
                        /* 93 is not-valid-after (a string) [25 bytes] */
                        p += 25;
                        /* 118 is the key [ASDCP::KeyLen bytes] */
-                       add_key (optional<string>(), key_id, Key (p), cpl_id);
+                       add_key (optional<string>(), key_id, Key (p), cpl_id, INTEROP);
                        break;
                }
                case 138:
@@ -192,7 +200,7 @@ DecryptedKDM::DecryptedKDM (EncryptedKDM const & kdm, string private_key)
                        /* 97 is not-valid-after (a string) [25 bytes] */
                        p += 25;
                        /* 112 is the key [ASDCP::KeyLen bytes] */
-                       add_key (key_type, key_id, Key (p), cpl_id);
+                       add_key (key_type, key_id, Key (p), cpl_id, SMPTE);
                        break;
                }
                default:
@@ -242,7 +250,7 @@ DecryptedKDM::DecryptedKDM (
        , _issue_date (issue_date)
 {
        for (map<shared_ptr<const ReelMXF>, Key>::const_iterator i = keys.begin(); i != keys.end(); ++i) {
-               add_key (i->first->key_type(), i->first->key_id().get(), i->second, cpl_id);
+               add_key (i->first->key_type(), i->first->key_id().get(), i->second, cpl_id, SMPTE);
        }
 }
 
@@ -263,10 +271,9 @@ DecryptedKDM::DecryptedKDM (
 {
        /* Create DecryptedKDMKey objects for each encryptable asset */
        bool did_one = false;
-       BOOST_FOREACH(shared_ptr<const ReelAsset> i, cpl->reel_assets ()) {
-               shared_ptr<const ReelMXF> mxf = boost::dynamic_pointer_cast<const ReelMXF> (i);
-               if (mxf && mxf->key_id ()) {
-                       add_key (mxf->key_type(), mxf->key_id().get(), key, cpl->id ());
+       BOOST_FOREACH(shared_ptr<const ReelMXF> i, cpl->reel_mxfs()) {
+               if (i->key_id()) {
+                       add_key (i->key_type(), i->key_id().get(), key, cpl->id(), SMPTE);
                        did_one = true;
                }
        }
@@ -282,9 +289,9 @@ DecryptedKDM::DecryptedKDM (
  *  @param cpl_id ID of CPL that the key is for.
  */
 void
-DecryptedKDM::add_key (optional<string> type, string key_id, Key key, string cpl_id)
+DecryptedKDM::add_key (optional<string> type, string key_id, Key key, string cpl_id, Standard standard)
 {
-       _keys.push_back (DecryptedKDMKey (type, key_id, key, cpl_id));
+       _keys.push_back (DecryptedKDMKey (type, key_id, key, cpl_id, standard));
 }
 
 void
@@ -294,8 +301,25 @@ DecryptedKDM::add_key (DecryptedKDMKey key)
 }
 
 EncryptedKDM
-DecryptedKDM::encrypt (shared_ptr<const CertificateChain> signer, Certificate recipient, vector<Certificate> trusted_devices, Formulation formulation) const
+DecryptedKDM::encrypt (
+       shared_ptr<const CertificateChain> signer,
+       Certificate recipient,
+       vector<string> trusted_devices,
+       Formulation formulation,
+       bool disable_forensic_marking_picture,
+       optional<int> disable_forensic_marking_audio
+       ) const
 {
+       DCP_ASSERT (!_keys.empty ());
+
+       BOOST_FOREACH (dcp::Certificate i, signer->leaf_to_root()) {
+               if (day_greater_than_or_equal(dcp::LocalTime(i.not_before()), _not_valid_before)) {
+                       throw BadKDMDateError (true);
+               } else if (day_less_than_or_equal(dcp::LocalTime(i.not_after()), _not_valid_after)) {
+                       throw BadKDMDateError (false);
+               }
+       }
+
        list<pair<string, string> > key_ids;
        list<string> keys;
        BOOST_FOREACH (DecryptedKDMKey const & i, _keys) {
@@ -357,6 +381,8 @@ DecryptedKDM::encrypt (shared_ptr<const CertificateChain> signer, Certificate re
                _not_valid_before,
                _not_valid_after,
                formulation,
+               disable_forensic_marking_picture,
+               disable_forensic_marking_audio,
                key_ids,
                keys
                );