Tidy up storage of key type in DecryptedKDMKey.
authorCarl Hetherington <cth@carlh.net>
Tue, 14 Feb 2017 16:26:15 +0000 (16:26 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 14 Feb 2017 16:26:15 +0000 (16:26 +0000)
src/decrypted_kdm.cc
src/decrypted_kdm.h
src/decrypted_kdm_key.h
tools/dcpkdm.cc

index 8355e1c852ee917e772cb3f1a5a231ae42a63f43..96d5f225430cb7d4b6880eb98eeceea4c5130ff4 100644 (file)
@@ -58,6 +58,7 @@ using std::hex;
 using std::pair;
 using std::map;
 using boost::shared_ptr;
+using boost::optional;
 using namespace dcp;
 
 static void
@@ -166,7 +167,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 ("", key_id, Key (p), cpl_id);
+                       add_key (optional<string>(), key_id, Key (p), cpl_id);
                        break;
                }
                case 138:
@@ -277,7 +278,7 @@ DecryptedKDM::DecryptedKDM (
  *  @param cpl_id ID of CPL that the key is for.
  */
 void
-DecryptedKDM::add_key (string type, string key_id, Key key, string cpl_id)
+DecryptedKDM::add_key (optional<string> type, string key_id, Key key, string cpl_id)
 {
        _keys.push_back (DecryptedKDMKey (type, key_id, key, cpl_id));
 }
@@ -294,7 +295,9 @@ DecryptedKDM::encrypt (shared_ptr<const CertificateChain> signer, Certificate re
        list<pair<string, string> > key_ids;
        list<string> keys;
        BOOST_FOREACH (DecryptedKDMKey const & i, _keys) {
-               key_ids.push_back (make_pair (i.type(), i.id ()));
+               /* We're making SMPTE keys so we must have a type for each one */
+               DCP_ASSERT (i.type());
+               key_ids.push_back (make_pair (i.type().get(), i.id ()));
 
                /* XXX: SMPTE only */
                uint8_t block[138];
@@ -308,7 +311,7 @@ DecryptedKDM::encrypt (shared_ptr<const CertificateChain> signer, Certificate re
                p += 20;
 
                put_uuid (&p, i.cpl_id ());
-               put (&p, i.type ());
+               put (&p, i.type().get());
                put_uuid (&p, i.id ());
                put (&p, _not_valid_before.as_string ());
                put (&p, _not_valid_after.as_string ());
index 752ced04a6d3bcce50cdc4708959f0160d2c68ab..585cc615759dd5959e196173a20b38ba8065c646 100644 (file)
@@ -133,7 +133,7 @@ public:
                Formulation formulation
                ) const;
 
-       void add_key (std::string type, std::string key_id, Key key, std::string cpl_id);
+       void add_key (boost::optional<std::string> type, std::string key_id, Key key, std::string cpl_id);
        void add_key (DecryptedKDMKey key);
 
        /** @return This KDM's (decrypted) keys, which could be used to decrypt assets. */
index 95ffccb80fd908e6687689afcb0da347095e17aa..1e03ee0a15118a15ab21f1df213ef50b605960ad 100644 (file)
@@ -39,6 +39,7 @@
 #define LIBDCP_DECRYPTED_KDM_KEY_H
 
 #include "key.h"
+#include <boost/optional.hpp>
 
 namespace dcp {
 
@@ -48,14 +49,14 @@ namespace dcp {
 class DecryptedKDMKey
 {
 public:
-       DecryptedKDMKey (std::string type, std::string id, Key key, std::string cpl_id)
+       DecryptedKDMKey (boost::optional<std::string> type, std::string id, Key key, std::string cpl_id)
                : _type (type)
                , _id (id)
                , _key (key)
                , _cpl_id (cpl_id)
        {}
 
-       std::string type () const {
+       boost::optional<std::string> type () const {
                return _type;
        }
 
@@ -72,7 +73,7 @@ public:
        }
 
 private:
-       std::string _type;
+       boost::optional<std::string> _type;
        std::string _id;
        Key _key;
        std::string _cpl_id;
index 00ab201f62fbd91d796fce56e9cb5242294062de..197397cb980a593902ba7d2ef78324e37777dc51 100644 (file)
@@ -103,7 +103,9 @@ main (int argc, char* argv[])
                        BOOST_FOREACH (dcp::DecryptedKDMKey i, dec_kdm.keys ()) {
                                cout << "\n";
                                cout << "\tID:   " << i.id() << "\n";
-                               cout << "\tType: " << i.type() << "\n";
+                               if (i.type()) {
+                                       cout << "\tType: " << i.type().get() << "\n";
+                               }
                                cout << "\tKey:  " << i.key().hex() << "\n";
                        }
                } catch (dcp::KDMDecryptionError& e) {