0d459d5a300aeb6d949717a237c5c4aa755de5ff
[libdcp.git] / src / encrypted_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/encrypted_kdm.h
21  *  @brief EncryptedKDM class.
22  */
23
24 #ifndef LIBDCP_ENCRYPTED_KDM_H
25 #define LIBDCP_ENCRYPTED_KDM_H
26
27 #include "local_time.h"
28 #include "types.h"
29 #include <boost/filesystem.hpp>
30 #include <boost/date_time/local_time/local_time.hpp>
31
32 namespace cxml {
33         class Node;
34 }
35
36 namespace dcp {
37
38 namespace data {
39         class EncryptedKDMData;
40 }
41
42 class Signer;   
43 class Certificate;
44
45 /** @class EncryptedKDM
46  *  @brief An encrypted KDM.
47  *
48  *  This is a KDM whose keys are encrypted using the target projector's private key.
49  *  An EncryptedKDM object can be initialised from a KDM XML file, or created from
50  *  a DecryptedKDM (using DecryptedKDM::encrypt).
51  */
52 class EncryptedKDM
53 {
54 public:
55         /** Read a KDM from an XML file.
56          *  @param file XML file to read.
57          */
58         EncryptedKDM (boost::filesystem::path file);
59
60         EncryptedKDM (EncryptedKDM const & kdm);
61         EncryptedKDM & operator= (EncryptedKDM const &);
62         ~EncryptedKDM ();
63
64         /** Write this KDM as XML to a file.
65          *  @param file File to write to.
66          */
67         void as_xml (boost::filesystem::path file) const;
68
69         /** @return This KDM as XML */
70         std::string as_xml () const;
71
72         /** @return The base64-encoded and encrypted keys that this KDM delivers.
73          *  Note that the returned `keys' contain more than just the asset decryption
74          *  keys (also key id, CPL id etc.)
75          */
76         std::list<std::string> keys () const;
77         
78 private:
79
80         friend class DecryptedKDM;
81
82         /** Construct an EncryptedKDM from a set of details */
83         EncryptedKDM (
84                 boost::shared_ptr<const Signer> signer,
85                 boost::shared_ptr<const Certificate> recipient,
86                 std::string device_list_description,
87                 std::string cpl_id,
88                 std::string cpl_content_title_text,
89                 LocalTime not_valid_before,
90                 LocalTime not_valid_after,
91                 Formulation formulation,
92                 std::list<std::pair<std::string, std::string> > key_ids,
93                 std::list<std::string> keys
94                 );
95         
96         data::EncryptedKDMData* _data;
97 };
98
99 }
100
101 #endif