summaryrefslogtreecommitdiff
path: root/test/ecinema_kdm_test.cc
blob: e44a626baf0954e721e0f7ceb1b66253e90e74de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
    Copyright (C) 2019 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/decrypted_ecinema_kdm.h"
#include "lib/encrypted_ecinema_kdm.h"
#include "lib/config.h"
#include <boost/test/unit_test.hpp>
extern "C" {
#include <libavutil/aes_ctr.h>
}
#include <fstream>

using std::string;
using boost::optional;

#ifdef DCPOMATIC_VARIANT_SWAROOP

BOOST_AUTO_TEST_CASE (ecinema_kdm_roundtrip_test1)
{
	dcp::Key key (AES_CTR_KEY_SIZE);
	DecryptedECinemaKDM dec ("123-456-789-0", "Hello world", key, optional<dcp::LocalTime>(), optional<dcp::LocalTime>());
	EncryptedECinemaKDM enc = dec.encrypt (Config::instance()->decryption_chain()->leaf());
	DecryptedECinemaKDM dec2 (enc, *Config::instance()->decryption_chain()->key());
	BOOST_CHECK_EQUAL (dec2.id(), "123-456-789-0");
	BOOST_CHECK_EQUAL (dec2.name(), "Hello world");
	BOOST_CHECK (dec2.key() == key);
	BOOST_CHECK (!static_cast<bool>(dec2.not_valid_before()));
	BOOST_CHECK (!static_cast<bool>(dec2.not_valid_after()));
}

BOOST_AUTO_TEST_CASE (ecinema_kdm_roundtrip_test2)
{
	dcp::Key key (AES_CTR_KEY_SIZE);
	DecryptedECinemaKDM dec ("123-456-789-0", "Hello world", key, dcp::LocalTime("2019-06-01T15:05:23+01:00"), dcp::LocalTime("2019-07-02T19:10:12+02:00"));
	EncryptedECinemaKDM enc = dec.encrypt (Config::instance()->decryption_chain()->leaf());
	DecryptedECinemaKDM dec2 (enc, *Config::instance()->decryption_chain()->key());
	BOOST_CHECK_EQUAL (dec2.id(), "123-456-789-0");
	BOOST_CHECK_EQUAL (dec2.name(), "Hello world");
	BOOST_CHECK (dec2.key() == key);
	BOOST_REQUIRE (static_cast<bool>(dec2.not_valid_before()));
	BOOST_CHECK_EQUAL (dec2.not_valid_before()->as_string(), "2019-06-01T15:05:23+01:00");
	BOOST_REQUIRE (static_cast<bool>(dec2.not_valid_after()));
	BOOST_CHECK_EQUAL (dec2.not_valid_after()->as_string(), "2019-07-02T19:10:12+02:00");
}

BOOST_AUTO_TEST_CASE (ecinema_kdm_roundtrip_test3)
{
	dcp::Key key (AES_CTR_KEY_SIZE);
	DecryptedECinemaKDM dec ("123-456-789-0", "Hello world", key, optional<dcp::LocalTime>(), optional<dcp::LocalTime>());
	EncryptedECinemaKDM enc = dec.encrypt (Config::instance()->decryption_chain()->leaf());
	string const enc_xml = enc.as_xml ();
	EncryptedECinemaKDM enc2 (enc_xml);
	DecryptedECinemaKDM dec2 (enc2, *Config::instance()->decryption_chain()->key());
	BOOST_CHECK_EQUAL (dec2.id(), "123-456-789-0");
	BOOST_CHECK_EQUAL (dec2.name(), "Hello world");
	BOOST_CHECK (dec2.key() == key);
	BOOST_CHECK (!static_cast<bool>(dec2.not_valid_before()));
	BOOST_CHECK (!static_cast<bool>(dec2.not_valid_after()));
}

BOOST_AUTO_TEST_CASE (ecinema_kdm_roundtrip_test4)
{
	dcp::Key key (AES_CTR_KEY_SIZE);
	DecryptedECinemaKDM dec ("123-456-789-0", "Hello world", key, dcp::LocalTime("2019-06-01T15:05:23+01:00"), dcp::LocalTime("2019-07-02T19:10:12+02:00"));
	EncryptedECinemaKDM enc = dec.encrypt (Config::instance()->decryption_chain()->leaf());
	string const enc_xml = enc.as_xml();
	EncryptedECinemaKDM enc2 (dcp::file_to_string("build/test/shit_the_bed.xml"));
	DecryptedECinemaKDM dec2 (enc2, *Config::instance()->decryption_chain()->key());
	BOOST_CHECK_EQUAL (dec2.id(), "123-456-789-0");
	BOOST_CHECK_EQUAL (dec2.name(), "Hello world");
	BOOST_CHECK (dec2.key() == key);
	BOOST_REQUIRE (static_cast<bool>(dec2.not_valid_before()));
	BOOST_CHECK_EQUAL (dec2.not_valid_before()->as_string(), "2019-06-01T15:05:23+01:00");
	BOOST_REQUIRE (static_cast<bool>(dec2.not_valid_after()));
	BOOST_CHECK_EQUAL (dec2.not_valid_after()->as_string(), "2019-07-02T19:10:12+02:00");
}

#endif