Bump libcxml.
[libdcp.git] / src / encrypted_kdm.h
1 /*
2     Copyright (C) 2013-2016 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 /** @file  src/encrypted_kdm.h
35  *  @brief EncryptedKDM class.
36  */
37
38 #ifndef LIBDCP_ENCRYPTED_KDM_H
39 #define LIBDCP_ENCRYPTED_KDM_H
40
41 #include "local_time.h"
42 #include "types.h"
43 #include <boost/filesystem.hpp>
44 #include <boost/optional.hpp>
45 #include <boost/date_time/local_time/local_time.hpp>
46
47 namespace cxml {
48         class Node;
49 }
50
51 namespace dcp {
52
53 namespace data {
54         class EncryptedKDMData;
55 }
56
57 class CertificateChain;
58 class Certificate;
59
60 /** @class EncryptedKDM
61  *  @brief An encrypted KDM.
62  *
63  *  This is a KDM whose keys are encrypted using the target projector's private key.
64  *  An EncryptedKDM object can be initialised from a KDM XML file, or created from
65  *  a DecryptedKDM (using DecryptedKDM::encrypt).
66  */
67 class EncryptedKDM
68 {
69 public:
70         explicit EncryptedKDM (std::string);
71         EncryptedKDM (EncryptedKDM const & kdm);
72         EncryptedKDM & operator= (EncryptedKDM const &);
73         ~EncryptedKDM ();
74
75         /** Write this KDM as XML to a file.
76          *  @param file File to write to.
77          */
78         void as_xml (boost::filesystem::path file) const;
79
80         /** @return This KDM as XML */
81         std::string as_xml () const;
82
83         /** @return The base64-encoded and encrypted keys that this KDM delivers.
84          *  Note that the returned `keys' contain more than just the asset decryption
85          *  keys (also key id, CPL id etc.)
86          */
87         std::list<std::string> keys () const;
88
89         boost::optional<std::string> annotation_text () const;
90         std::string content_title_text () const;
91         std::string issue_date () const;
92         std::string cpl_id () const;
93         LocalTime not_valid_before () const;
94         LocalTime not_valid_after () const;
95         std::string recipient_x509_subject_name () const;
96
97 private:
98
99         friend class DecryptedKDM;
100
101         /** Construct an EncryptedKDM from a set of details */
102         EncryptedKDM (
103                 boost::shared_ptr<const CertificateChain> signer,
104                 Certificate recipient,
105                 std::vector<Certificate> trusted_devices,
106                 std::string cpl_id,
107                 std::string cpl_content_title_text,
108                 boost::optional<std::string> annotation_text,
109                 LocalTime not_valid_before,
110                 LocalTime not_valid_after,
111                 Formulation formulation,
112                 std::list<std::pair<std::string, std::string> > key_ids,
113                 std::list<std::string> keys
114                 );
115
116         data::EncryptedKDMData* _data;
117 };
118
119 extern bool operator== (EncryptedKDM const & a, EncryptedKDM const & b);
120
121 }
122
123 #endif