Clarify success message from dcpverify a little.
[libdcp.git] / tools / dcpdecryptmxf.cc
index 8280cfffb8102820b27878f96501af1b402deb2c..1cdb58ec0b0441aa2f42a37eb145357195d1f73d 100644 (file)
@@ -44,6 +44,7 @@
 #include "mono_picture_asset.h"
 #include "mono_picture_asset_writer.h"
 #include "util.h"
+#include "version.h"
 #include <asdcp/AS_DCP.h>
 #include <getopt.h>
 #include <iostream>
@@ -68,17 +69,20 @@ help (string n)
             << "  -o, --output       output filename\n"
             << "  -k, --kdm          KDM file\n"
             << "  -p, --private-key  private key file\n"
-            << "  -t, --type         MXF type: picture or atmos\n";
+            << "  -t, --type         MXF type: picture or atmos\n"
+            << "  -i, --ignore-hmac  don't raise an error if HMACs don't agree\n";
 }
 
 template <class T, class U>
-void copy (T const& in, shared_ptr<U> writer)
+void copy (T const& in, shared_ptr<U> writer, bool ignore_hmac)
 {
        auto reader = in.start_read();
+       reader->set_check_hmac (!ignore_hmac);
        for (int64_t i = 0; i < in.intrinsic_duration(); ++i) {
                auto frame = reader->get_frame (i);
                writer->write (frame->data(), frame->size());
        }
+       writer->finalize();
 };
 
 
@@ -91,6 +95,7 @@ main (int argc, char* argv[])
        optional<boost::filesystem::path> output_file;
        optional<boost::filesystem::path> kdm_file;
        optional<boost::filesystem::path> private_key_file;
+       bool ignore_hmac = false;
 
        enum class Type {
                PICTURE,
@@ -109,10 +114,11 @@ main (int argc, char* argv[])
                        { "kdm", required_argument, 0, 'k'},
                        { "private-key", required_argument, 0, 'p'},
                        { "type", required_argument, 0, 't' },
+                       { "ignore-hmac", no_argument, 0, 'i' },
                        { 0, 0, 0, 0 }
                };
 
-               int c = getopt_long (argc, argv, "Avho:k:p:t:", long_options, &option_index);
+               int c = getopt_long (argc, argv, "Avho:k:p:t:i", long_options, &option_index);
 
                if (c == -1) {
                        break;
@@ -120,7 +126,7 @@ main (int argc, char* argv[])
 
                switch (c) {
                case 'A':
-                       cout << "libdcp version " << LIBDCP_VERSION << "\n";
+                       cout << "libdcp version " << dcp::version << "\n";
                        exit (EXIT_SUCCESS);
                case 'v':
                        verbose = true;
@@ -147,6 +153,9 @@ main (int argc, char* argv[])
                                exit (EXIT_FAILURE);
                        }
                        break;
+               case 'i':
+                       ignore_hmac = true;
+                       break;
                }
        }
 
@@ -212,8 +221,8 @@ main (int argc, char* argv[])
                                in.max_object_count(),
                                in.atmos_version()
                                );
-                       auto writer = out.start_write (output_file.get());
-                       copy (in, writer);
+                       auto writer = out.start_write(output_file.get());
+                       copy (in, writer, ignore_hmac);
                        break;
                }
                case Type::PICTURE:
@@ -221,8 +230,8 @@ main (int argc, char* argv[])
                        dcp::MonoPictureAsset in (input_file);
                        add_key (in, decrypted_kdm);
                        dcp::MonoPictureAsset out (in.edit_rate(), dcp::Standard::SMPTE);
-                       auto writer = out.start_write (output_file.get(), false);
-                       copy (in, writer);
+                       auto writer = out.start_write(output_file.get(), dcp::PictureAsset::Behaviour::MAKE_NEW);
+                       copy (in, writer, ignore_hmac);
                        break;
                }
                }