Tidying.
[libdcp.git] / src / encrypted_kdm.h
1 /*
2     Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34
35 /** @file  src/encrypted_kdm.h
36  *  @brief EncryptedKDM class
37  */
38
39
40 #ifndef LIBDCP_ENCRYPTED_KDM_H
41 #define LIBDCP_ENCRYPTED_KDM_H
42
43
44 #include "local_time.h"
45 #include "types.h"
46 #include <boost/filesystem.hpp>
47 #include <boost/optional.hpp>
48 #include <boost/date_time/local_time/local_time.hpp>
49
50
51 namespace cxml {
52         class Node;
53 }
54
55
56 namespace dcp {
57
58
59 namespace data {
60         class EncryptedKDMData;
61 }
62
63
64 class CertificateChain;
65 class Certificate;
66
67
68 /** @class EncryptedKDM
69  *  @brief An encrypted KDM
70  *
71  *  This is a KDM whose keys are encrypted using the target projector's private key.
72  *  An EncryptedKDM object can be initialised from a KDM XML file, or created from
73  *  a DecryptedKDM (using DecryptedKDM::encrypt).
74  */
75 class EncryptedKDM
76 {
77 public:
78         explicit EncryptedKDM (std::string);
79         EncryptedKDM (EncryptedKDM const & kdm);
80         EncryptedKDM & operator= (EncryptedKDM const &);
81         ~EncryptedKDM ();
82
83         /** Write this KDM as XML to a file.
84          *  @param file File to write to.
85          */
86         void as_xml (boost::filesystem::path file) const;
87
88         /** @return This KDM as XML */
89         std::string as_xml () const;
90
91         /** @return The base64-encoded and encrypted keys that this KDM delivers.
92          *  Note that the returned `keys' contain more than just the asset decryption
93          *  keys (also key id, CPL id etc.)
94          */
95         std::vector<std::string> keys () const;
96
97         std::string id () const;
98         boost::optional<std::string> annotation_text () const;
99         std::string content_title_text () const;
100         std::string issue_date () const;
101         std::string cpl_id () const;
102         LocalTime not_valid_before () const;
103         LocalTime not_valid_after () const;
104         std::string recipient_x509_subject_name () const;
105         CertificateChain signer_certificate_chain () const;
106
107 private:
108
109         friend class DecryptedKDM;
110
111         /** Construct an EncryptedKDM from a set of details */
112         EncryptedKDM (
113                 std::shared_ptr<const CertificateChain> signer,
114                 Certificate recipient,
115                 std::vector<std::string> trusted_devices,
116                 std::string cpl_id,
117                 std::string cpl_content_title_text,
118                 boost::optional<std::string> annotation_text,
119                 LocalTime not_valid_before,
120                 LocalTime not_valid_after,
121                 Formulation formulation,
122                 bool disable_forensic_marking_picture,
123                 boost::optional<int> disable_forensic_marking_audio,
124                 std::vector<std::pair<std::string, std::string>> key_ids,
125                 std::vector<std::string> keys
126                 );
127
128         data::EncryptedKDMData* _data = nullptr;
129 };
130
131
132 extern bool operator== (EncryptedKDM const & a, EncryptedKDM const & b);
133
134 }
135
136
137 #endif