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