2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
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.
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.
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/>.
21 /** @file src/asset.cc
22 * @brief Parent class for assets of DCPs made up of MXF files.
25 #include "raw_convert.h"
32 #include "exceptions.h"
33 #include "dcp_assert.h"
34 #include "compose.hpp"
35 #include <libxml++/nodes/element.h>
36 #include <boost/filesystem.hpp>
43 using boost::shared_ptr;
44 using boost::dynamic_pointer_cast;
48 : _decryption_context (0)
55 delete _decryption_context;
59 MXF::fill_writer_info (ASDCP::WriterInfo* writer_info, string id, Standard standard) const
61 writer_info->ProductVersion = _metadata.product_version;
62 writer_info->CompanyName = _metadata.company_name;
63 writer_info->ProductName = _metadata.product_name.c_str();
65 if (standard == INTEROP) {
66 writer_info->LabelSetType = ASDCP::LS_MXF_INTEROP;
68 writer_info->LabelSetType = ASDCP::LS_MXF_SMPTE;
71 Kumu::hex2bin (id.c_str(), writer_info->AssetUUID, Kumu::UUID_Length, &c);
72 DCP_ASSERT (c == Kumu::UUID_Length);
74 writer_info->UsesHMAC = true;
77 Kumu::GenRandomUUID (writer_info->ContextID);
78 writer_info->EncryptedEssence = true;
81 Kumu::hex2bin (_key_id.get().c_str(), writer_info->CryptographicKeyID, Kumu::UUID_Length, &c);
82 DCP_ASSERT (c == Kumu::UUID_Length);
86 /** Set the (private) key that will be used to encrypt or decrypt this MXF's content.
87 * This is the top-secret key that is distributed (itself encrypted) to cinemas
88 * via Key Delivery Messages (KDMs).
89 * @param key Key to use.
92 MXF::set_key (Key key)
97 /* No key ID so far; we now need one */
98 _key_id = make_uuid ();
101 _decryption_context = new ASDCP::AESDecContext;
102 if (ASDCP_FAILURE (_decryption_context->InitKey (_key->value ()))) {
103 throw MiscError ("could not set up decryption context");
108 MXF::read_writer_info (ASDCP::WriterInfo const & info)
112 if (info.EncryptedEssence) {
113 Kumu::bin2UUIDhex (info.CryptographicKeyID, ASDCP::UUIDlen, buffer, sizeof (buffer));
117 _metadata.read (info);
119 Kumu::bin2UUIDhex (info.AssetUUID, ASDCP::UUIDlen, buffer, sizeof (buffer));