Small bits of pre-release tidying.
[libdcp.git] / tools / dcpdecryptmxf.cc
index e640620a8dbf6b789e279155788031773b1aac50..9dafa8c9faf5d332fe73b612088773a872740fc7 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "encrypted_kdm.h"
 #include "decrypted_kdm.h"
-#include "decryption_context.h"
+#include "crypto_context.h"
 #include "key.h"
 #include "util.h"
 #include "atmos_asset.h"
@@ -42,7 +42,6 @@
 #include "atmos_asset_writer.h"
 #include "exceptions.h"
 #include <asdcp/AS_DCP.h>
-#include <boost/foreach.hpp>
 #include <getopt.h>
 #include <string>
 
@@ -50,73 +49,24 @@ using std::string;
 using std::cerr;
 using std::cout;
 using boost::optional;
-using boost::shared_ptr;
+using std::shared_ptr;
 
 static void
 help (string n)
 {
        cerr << "Syntax: " << n << " [OPTION] <MXF>]\n"
-            << "  -v, --version      show DCP-o-matic version\n"
+            << "  -v, --version      show libdcp version\n"
             << "  -h, --help         show this help\n"
             << "  -o, --output       output filename\n"
             << "  -k, --kdm          KDM file\n"
             << "  -p, --private-key  private key file\n";
 }
 
-int
-atmos (
-       ASDCP::ATMOS::MXFReader& reader,
-       boost::filesystem::path output_file,
-       dcp::DecryptedKDM kdm
-       )
-{
-       ASDCP::WriterInfo info;
-       if (ASDCP_FAILURE (reader.FillWriterInfo (info))) {
-               cerr << "Could not read ATMOS MXF information\n";
-               exit (EXIT_FAILURE);
-       }
-
-       if (!info.EncryptedEssence) {
-               cerr << "MXF is not encrypted!\n";
-               exit (EXIT_FAILURE);
-       }
-
-       char key_buffer[64];
-       Kumu::bin2UUIDhex (info.CryptographicKeyID, ASDCP::UUIDlen, key_buffer, sizeof (key_buffer));
-       string const key_id = key_buffer;
-
-       optional<dcp::Key> key;
-       BOOST_FOREACH (dcp::DecryptedKDMKey const & i, kdm.keys()) {
-               if (i.id() == key_id) {
-                       key = i.key();
-               }
-       }
-
-       if (!key) {
-               cerr << "Could not find key in KDM.\n";
-               exit (EXIT_FAILURE);
-       }
-
-       dcp::DecryptionContext dc (key.get());
-
-       ASDCP::ATMOS::AtmosDescriptor desc;
-       if (ASDCP_FAILURE (reader.FillAtmosDescriptor (desc))) {
-               cerr << "could not read ATMOS descriptor.\n";
-               exit (EXIT_FAILURE);
-       }
-
-       ASDCP::DCData::FrameBuffer buffer (Kumu::Megabyte);
-
-       for (size_t i = 0; i < desc.ContainerDuration; ++i) {
-               reader.ReadFrame (i, buffer, dc.decryption(), 0);
-       }
-
-       return 0;
-}
-
 int
 main (int argc, char* argv[])
 {
+       dcp::init ();
+
        optional<boost::filesystem::path> output_file;
        optional<boost::filesystem::path> kdm_file;
        optional<boost::filesystem::path> private_key_file;
@@ -182,6 +132,8 @@ main (int argc, char* argv[])
        dcp::EncryptedKDM encrypted_kdm (dcp::file_to_string (kdm_file.get ()));
        dcp::DecryptedKDM decrypted_kdm (encrypted_kdm, dcp::file_to_string (private_key_file.get()));
 
+       /* XXX: only works for Atmos! */
+
        try {
                dcp::AtmosAsset in (input_file);
                shared_ptr<dcp::AtmosAssetReader> reader = in.start_read ();
@@ -190,7 +142,6 @@ main (int argc, char* argv[])
                        in.first_frame(),
                        in.max_channel_count(),
                        in.max_object_count(),
-                       in.atmos_id(),
                        in.atmos_version()
                        );
                shared_ptr<dcp::AtmosAssetWriter> writer = out.start_write (output_file.get());
@@ -198,7 +149,7 @@ main (int argc, char* argv[])
                        shared_ptr<const dcp::AtmosFrame> f = reader->get_frame (i);
                        writer->write (f->data(), f->size());
                }
-       } catch (dcp::DCPReadError& e) {
+       } catch (dcp::ReadError& e) {
                cerr << "Unknown MXF format.\n";
                return EXIT_FAILURE;
        }