Fill test disk partitions with random noise to expose more bugs.
[dcpomatic.git] / test / crypto_test.cc
index 576a6ebc6bdbb28772ebe940ecb82a1dfd941e5d..53451b352360b2d3ec386b97822d9bf214ccbe16 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+
 #include "lib/crypto.h"
 #include "lib/exceptions.h"
 #include "test.h"
 #include <openssl/rand.h>
 #include <boost/test/unit_test.hpp>
 
+
 using std::string;
 using std::list;
-using boost::shared_array;
+
 
 BOOST_AUTO_TEST_CASE (crypto_test)
 {
-       shared_array<unsigned char> key (new unsigned char[dcpomatic::crypto_key_length()]);
-       shared_array<unsigned char> iv = dcpomatic::random_iv ();
+       dcp::ArrayData key (dcpomatic::crypto_key_length());
+       dcp::ArrayData iv = dcpomatic::random_iv ();
 
-       RAND_bytes (key.get(), dcpomatic::crypto_key_length());
+       RAND_bytes (key.data(), dcpomatic::crypto_key_length());
 
-       dcp::Data ciphertext = dcpomatic::encrypt ("Can you see any fish?", key, iv);
+       auto ciphertext = dcpomatic::encrypt ("Can you see any fish?", key, iv);
        BOOST_REQUIRE_EQUAL (dcpomatic::decrypt (ciphertext, key, iv), "Can you see any fish?");
 
-       key[5]++;
+       key.data()[5]++;
+       key.data()[6]++;
        BOOST_REQUIRE_THROW (dcpomatic::decrypt (ciphertext, key, iv), CryptoError);
 }