diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-10-08 00:10:01 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-10-08 00:10:01 +0100 |
| commit | 6a9f36928b7404250fc71694e88a73d5b4125695 (patch) | |
| tree | 0ba85c77e2661f07399fd7f810d52198f6d228e0 /src | |
| parent | 4debca21936fd004fdcabe8d6178694f8cbf5f4d (diff) | |
Allow DecryptedKDM to be built up from individual keys.
Diffstat (limited to 'src')
| -rw-r--r-- | src/decrypted_kdm.cc | 33 | ||||
| -rw-r--r-- | src/decrypted_kdm.h | 21 | ||||
| -rw-r--r-- | src/encrypted_kdm.cc | 7 | ||||
| -rw-r--r-- | src/encrypted_kdm.h | 2 |
4 files changed, 62 insertions, 1 deletions
diff --git a/src/decrypted_kdm.cc b/src/decrypted_kdm.cc index f12752b6..3e48e23f 100644 --- a/src/decrypted_kdm.cc +++ b/src/decrypted_kdm.cc @@ -188,6 +188,22 @@ DecryptedKDM::DecryptedKDM (EncryptedKDM const & kdm, string private_key) } DecryptedKDM::DecryptedKDM ( + LocalTime not_valid_before, + LocalTime not_valid_after, + string annotation_text, + string content_title_text, + string issue_date + ) + : _not_valid_before (not_valid_before) + , _not_valid_after (not_valid_after) + , _annotation_text (annotation_text) + , _content_title_text (content_title_text) + , _issue_date (issue_date) +{ + +} + +DecryptedKDM::DecryptedKDM ( boost::shared_ptr<const CPL> cpl, Key key, LocalTime not_valid_before, @@ -215,6 +231,23 @@ DecryptedKDM::DecryptedKDM ( } } +/** @param type (MDIK, MDAK etc.) + * @param key_id Key ID. + * @param key The actual symmetric key. + * @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) +{ + _keys.push_back (DecryptedKDMKey (type, key_id, key, cpl_id)); +} + +void +DecryptedKDM::add_key (DecryptedKDMKey key) +{ + _keys.push_back (key); +} + EncryptedKDM DecryptedKDM::encrypt (shared_ptr<const CertificateChain> signer, Certificate recipient, Formulation formulation) const { diff --git a/src/decrypted_kdm.h b/src/decrypted_kdm.h index 06e2f9e1..2cb934bb 100644 --- a/src/decrypted_kdm.h +++ b/src/decrypted_kdm.h @@ -55,7 +55,23 @@ public: */ DecryptedKDM (EncryptedKDM const & kdm, std::string private_key); - /** Construct a DecryptedKDM. + /** Create an empty DecryptedKDM. After creation you must call + * add_key() to add each key that you want in the KDM. + * + * @param not_valid_before Start time for the KDM. + * @param not_valid_after End time for the KDM. + */ + DecryptedKDM ( + LocalTime not_valid_before, + LocalTime not_valid_after, + std::string annotation_text, + std::string content_title_text, + std::string issue_date + ); + + /** Create a DecryptedKDM by taking a CPL and setting up to encrypt each of its + * assets with the same symmetric key. + * * @param cpl CPL that the keys are for. * @param key Key that was used to encrypt the assets. * @param not_valid_before Start time for the KDM. @@ -79,6 +95,9 @@ public: */ EncryptedKDM encrypt (boost::shared_ptr<const CertificateChain> signer, Certificate recipient, Formulation formulation) const; + void add_key (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. */ std::list<DecryptedKDMKey> keys () const { return _keys; diff --git a/src/encrypted_kdm.cc b/src/encrypted_kdm.cc index d856c5e1..c0c81952 100644 --- a/src/encrypted_kdm.cc +++ b/src/encrypted_kdm.cc @@ -626,3 +626,10 @@ EncryptedKDM::issue_date () const { return _data->authenticated_public.issue_date; } + +bool +dcp::operator== (EncryptedKDM const & a, EncryptedKDM const & b) +{ + /* Not exactly efficient... */ + return a.as_xml() == b.as_xml(); +} diff --git a/src/encrypted_kdm.h b/src/encrypted_kdm.h index 6e08199f..a22b3b40 100644 --- a/src/encrypted_kdm.h +++ b/src/encrypted_kdm.h @@ -96,6 +96,8 @@ private: data::EncryptedKDMData* _data; }; +extern bool operator== (EncryptedKDM const & a, EncryptedKDM const & b); + } #endif |
