3c3d07db9e1a6e70db6534e973572b8fd49e5f74
[libdcp.git] / src / decrypted_kdm.h
1 /*
2     Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/decrypted_kdm.h
21  *  @brief DecryptedKDM class.
22  */
23
24 #include "key.h"
25 #include "local_time.h"
26 #include "decrypted_kdm_key.h"
27 #include "types.h"
28 #include <boost/filesystem.hpp>
29
30 namespace dcp {
31
32 class DecryptedKDMKey;
33 class EncryptedKDM;
34 class Signer;
35 class Certificate;
36 class CPL;
37
38 /** @class DecryptedKDM
39  *  @brief A decrypted KDM.
40  *
41  *  This is a KDM that has either been decrypted by a target private key, or one which
42  *  has been created (by some other means) ready for encryption later.
43  *
44  *  A DecryptedKDM object can be created either from an EncryptedKDM and private key file,
45  *  or from the details of the MXFs that the KDM should protect.
46  */
47 class DecryptedKDM
48 {
49 public:
50         /** @param kdm Encrypted KDM.
51          *  @param private_key Private key file name.
52          */
53         DecryptedKDM (EncryptedKDM const & kdm, boost::filesystem::path private_key);
54
55         /** Construct a DecryptedKDM.
56          *  @param cpl CPL that the keys are for.
57          *  @param not_valid_before Start time for the KDM.
58          *  @param not_valid_after End time for the KDM.
59          */
60         DecryptedKDM (
61                 boost::shared_ptr<const CPL> cpl,
62                 LocalTime not_valid_before,
63                 LocalTime not_valid_after,
64                 std::string annotation_text,
65                 std::string content_title_text,
66                 std::string issue_date
67                 );
68
69         /** Add a key to this KDM.
70          *  @param type Key type (MDIK, MDAK etc.)
71          *  @param id Key id.
72          *  @param key the key itself (which has been used to encrypt a MXF).
73          */
74         void add_key (std::string type, std::string id, Key key);
75
76         /** Encrypt this KDM's keys and sign the whole KDM.
77          *  @param signer Signer.
78          *  @param recipient Certificate of the projector/server which should receive this KDM's keys.
79          *  @param formulation Formulation to use for the encrypted KDM.
80          *  @return Encrypted KDM.
81          */
82         EncryptedKDM encrypt (boost::shared_ptr<const Signer> signer, boost::shared_ptr<const Certificate> recipient, Formulation formulation) const;
83
84         /** @return This KDM's (decrypted) keys, which could be used to decrypt MXFs. */
85         std::list<DecryptedKDMKey> keys () const {
86                 return _keys;
87         }
88
89 private:
90         LocalTime _not_valid_before;
91         LocalTime _not_valid_after;
92         std::string _annotation_text;
93         std::string _content_title_text;
94         std::string _issue_date;
95         std::list<DecryptedKDMKey> _keys;
96 };
97
98 }