summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-12-22 22:43:56 +0000
committerCarl Hetherington <cth@carlh.net>2018-12-23 21:04:49 +0000
commit5ab0c3bc04e4aa5acd883bb8126fc6b185c6c5d6 (patch)
treed03668797778e28f2b601f72aff30bdb093de61a /test
parent4f47104941f57dda9994d45bfebbcfedd3db2e84 (diff)
Incomplete encryption of private keys.
Diffstat (limited to 'test')
-rw-r--r--test/crypto_test.cc44
-rw-r--r--test/wscript1
2 files changed, 45 insertions, 0 deletions
diff --git a/test/crypto_test.cc b/test/crypto_test.cc
new file mode 100644
index 000000000..576a6ebc6
--- /dev/null
+++ b/test/crypto_test.cc
@@ -0,0 +1,44 @@
+/*
+ Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#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 ();
+
+ RAND_bytes (key.get(), dcpomatic::crypto_key_length());
+
+ dcp::Data 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]++;
+ BOOST_REQUIRE_THROW (dcpomatic::decrypt (ciphertext, key, iv), CryptoError);
+}
+
diff --git a/test/wscript b/test/wscript
index 47f3dc275..23f31dadc 100644
--- a/test/wscript
+++ b/test/wscript
@@ -57,6 +57,7 @@ def build(bld):
colour_conversion_test.cc
config_test.cc
content_test.cc
+ crypto_test.cc
dcpomatic_time_test.cc
dcp_playback_test.cc
dcp_subtitle_test.cc