summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-06-04 22:24:26 +0100
committerCarl Hetherington <cth@carlh.net>2015-06-05 14:35:31 +0100
commit29844b3efd68ee102686e0ae6a04a926c1dbbbd8 (patch)
tree7a8cd97644335364b7ab708e9a8e03a2da003bc6 /src
parent55686953bfecd42fac24bdf2668920954a8173be (diff)
Keep encryption context in MXFWriter.
Diffstat (limited to 'src')
-rw-r--r--src/decrypted_kdm.cc1
-rw-r--r--src/mono_picture_mxf_writer.cc4
-rw-r--r--src/mxf.cc17
-rw-r--r--src/mxf.h6
-rw-r--r--src/mxf_writer.cc19
-rw-r--r--src/mxf_writer.h5
-rw-r--r--src/picture_mxf_writer_common.cc1
-rw-r--r--src/sound_mxf_writer.cc5
-rw-r--r--src/stereo_picture_mxf_writer.cc4
9 files changed, 29 insertions, 33 deletions
diff --git a/src/decrypted_kdm.cc b/src/decrypted_kdm.cc
index 4d9c44a8..ddcacb34 100644
--- a/src/decrypted_kdm.cc
+++ b/src/decrypted_kdm.cc
@@ -200,7 +200,6 @@ DecryptedKDM::DecryptedKDM (
{
/* Create DecryptedKDMKey objects for each MXF asset */
BOOST_FOREACH(shared_ptr<const ReelAsset> i, cpl->reel_assets ()) {
- /* XXX: do non-MXF assets need keys? */
shared_ptr<const ReelMXFAsset> mxf = boost::dynamic_pointer_cast<const ReelMXFAsset> (i);
if (mxf) {
if (!mxf->key_id ()) {
diff --git a/src/mono_picture_mxf_writer.cc b/src/mono_picture_mxf_writer.cc
index 7d8335c0..7ad2c1b6 100644
--- a/src/mono_picture_mxf_writer.cc
+++ b/src/mono_picture_mxf_writer.cc
@@ -48,7 +48,7 @@ MonoPictureMXFWriter::MonoPictureMXFWriter (PictureMXF* asset, boost::filesystem
: PictureMXFWriter (asset, file, standard, overwrite)
, _state (new MonoPictureMXFWriter::ASDCPState)
{
- _state->encryption_context = asset->encryption_context ();
+
}
void
@@ -74,7 +74,7 @@ MonoPictureMXFWriter::write (uint8_t* data, int size)
uint64_t const before_offset = _state->mxf_writer.Tell ();
string hash;
- ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _state->encryption_context, 0, &hash);
+ ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _encryption_context, 0, &hash);
if (ASDCP_FAILURE (r)) {
boost::throw_exception (MXFFileError ("error in writing video MXF", _file.string(), r));
}
diff --git a/src/mxf.cc b/src/mxf.cc
index 3a7080a9..d259bd97 100644
--- a/src/mxf.cc
+++ b/src/mxf.cc
@@ -43,15 +43,13 @@ using boost::dynamic_pointer_cast;
using namespace dcp;
MXF::MXF ()
- : _encryption_context (0)
- , _decryption_context (0)
+ : _decryption_context (0)
{
}
MXF::MXF (boost::filesystem::path file)
: Asset (file)
- , _encryption_context (0)
, _decryption_context (0)
{
@@ -59,7 +57,6 @@ MXF::MXF (boost::filesystem::path file)
MXF::~MXF ()
{
- delete _encryption_context;
delete _decryption_context;
}
@@ -132,18 +129,6 @@ MXF::set_key (Key key)
if (ASDCP_FAILURE (_decryption_context->InitKey (_key->value ()))) {
throw MiscError ("could not set up decryption context");
}
-
- _encryption_context = new ASDCP::AESEncContext;
- if (ASDCP_FAILURE (_encryption_context->InitKey (_key->value ()))) {
- throw MiscError ("could not set up encryption context");
- }
-
- uint8_t cbc_buffer[ASDCP::CBC_BLOCK_SIZE];
-
- Kumu::FortunaRNG rng;
- if (ASDCP_FAILURE (_encryption_context->SetIVec (rng.FillRandom (cbc_buffer, ASDCP::CBC_BLOCK_SIZE)))) {
- throw MiscError ("could not set up CBC initialization vector");
- }
}
void
diff --git a/src/mxf.h b/src/mxf.h
index ff480598..be94b293 100644
--- a/src/mxf.h
+++ b/src/mxf.h
@@ -82,11 +82,6 @@ public:
return _key;
}
- /** @return encryption context, set up with any key that has been passed to set_key() */
- ASDCP::AESEncContext* encryption_context () const {
- return _encryption_context;
- }
-
/** Set the metadata that is written to the MXF file.
* @param m Metadata.
*/
@@ -110,7 +105,6 @@ protected:
*/
void fill_writer_info (ASDCP::WriterInfo* w, Standard standard);
- ASDCP::AESEncContext* _encryption_context;
ASDCP::AESDecContext* _decryption_context;
/** ID of the key used for encryption/decryption, if there is one */
boost::optional<std::string> _key_id;
diff --git a/src/mxf_writer.cc b/src/mxf_writer.cc
index d4aba72f..d616c913 100644
--- a/src/mxf_writer.cc
+++ b/src/mxf_writer.cc
@@ -24,6 +24,8 @@
#include "mxf_writer.h"
#include "mxf.h"
#include "dcp_assert.h"
+#include "AS_DCP.h"
+#include "KM_prng.h"
using namespace dcp;
@@ -36,13 +38,28 @@ MXFWriter::MXFWriter (MXF* mxf, boost::filesystem::path file)
, _file (file)
, _frames_written (0)
, _finalized (false)
+ , _encryption_context (0)
{
mxf->set_file (file);
+
+ if (mxf->key ()) {
+ _encryption_context = new ASDCP::AESEncContext;
+ if (ASDCP_FAILURE (_encryption_context->InitKey (mxf->key()->value ()))) {
+ throw MiscError ("could not set up encryption context");
+ }
+
+ uint8_t cbc_buffer[ASDCP::CBC_BLOCK_SIZE];
+
+ Kumu::FortunaRNG rng;
+ if (ASDCP_FAILURE (_encryption_context->SetIVec (rng.FillRandom (cbc_buffer, ASDCP::CBC_BLOCK_SIZE)))) {
+ throw MiscError ("could not set up CBC initialization vector");
+ }
+ }
}
MXFWriter::~MXFWriter ()
{
-
+ delete _encryption_context;
}
void
diff --git a/src/mxf_writer.h b/src/mxf_writer.h
index b4e20f33..c7924c9a 100644
--- a/src/mxf_writer.h
+++ b/src/mxf_writer.h
@@ -26,6 +26,10 @@
#include <boost/filesystem.hpp>
+namespace ASDCP {
+ class AESEncContext;
+}
+
namespace dcp {
class MXF;
@@ -55,6 +59,7 @@ protected:
int64_t _frames_written;
/** true if finalize() has been called on this object */
bool _finalized;
+ ASDCP::AESEncContext* _encryption_context;
};
}
diff --git a/src/picture_mxf_writer_common.cc b/src/picture_mxf_writer_common.cc
index d8d1589b..dc5b340a 100644
--- a/src/picture_mxf_writer_common.cc
+++ b/src/picture_mxf_writer_common.cc
@@ -29,7 +29,6 @@ struct ASDCPStateBase
ASDCP::JP2K::FrameBuffer frame_buffer;
ASDCP::WriterInfo writer_info;
ASDCP::JP2K::PictureDescriptor picture_descriptor;
- ASDCP::AESEncContext* encryption_context;
};
template <class P, class Q>
diff --git a/src/sound_mxf_writer.cc b/src/sound_mxf_writer.cc
index 19250d9d..6da009fc 100644
--- a/src/sound_mxf_writer.cc
+++ b/src/sound_mxf_writer.cc
@@ -32,7 +32,6 @@ struct SoundMXFWriter::ASDCPState
ASDCP::PCM::FrameBuffer frame_buffer;
ASDCP::WriterInfo writer_info;
ASDCP::PCM::AudioDescriptor audio_desc;
- ASDCP::AESEncContext* encryption_context;
};
SoundMXFWriter::SoundMXFWriter (SoundMXF* m, boost::filesystem::path file, Standard standard)
@@ -41,8 +40,6 @@ SoundMXFWriter::SoundMXFWriter (SoundMXF* m, boost::filesystem::path file, Stand
, _sound_mxf (m)
, _frame_buffer_offset (0)
{
- _state->encryption_context = m->encryption_context ();
-
/* Derived from ASDCP::Wav::SimpleWaveHeader::FillADesc */
_state->audio_desc.EditRate = ASDCP::Rational (_sound_mxf->edit_rate().numerator, _sound_mxf->edit_rate().denominator);
_state->audio_desc.AudioSamplingRate = ASDCP::Rational (_sound_mxf->sampling_rate(), 1);
@@ -98,7 +95,7 @@ SoundMXFWriter::write (float const * const * data, int frames)
void
SoundMXFWriter::write_current_frame ()
{
- ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _state->encryption_context, 0);
+ ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _encryption_context, 0);
if (ASDCP_FAILURE (r)) {
boost::throw_exception (MiscError (String::compose ("could not write audio MXF frame (%1)", int (r))));
}
diff --git a/src/stereo_picture_mxf_writer.cc b/src/stereo_picture_mxf_writer.cc
index a4bd7d9f..328db829 100644
--- a/src/stereo_picture_mxf_writer.cc
+++ b/src/stereo_picture_mxf_writer.cc
@@ -42,7 +42,7 @@ StereoPictureMXFWriter::StereoPictureMXFWriter (PictureMXF* mxf, boost::filesyst
, _state (new StereoPictureMXFWriter::ASDCPState)
, _next_eye (EYE_LEFT)
{
- _state->encryption_context = mxf->encryption_context ();
+
}
void
@@ -75,7 +75,7 @@ StereoPictureMXFWriter::write (uint8_t* data, int size)
Kumu::Result_t r = _state->mxf_writer.WriteFrame (
_state->frame_buffer,
_next_eye == EYE_LEFT ? ASDCP::JP2K::SP_LEFT : ASDCP::JP2K::SP_RIGHT,
- _state->encryption_context,
+ _encryption_context,
0,
&hash
);