summaryrefslogtreecommitdiff
path: root/src/encrypted_kdm.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-01-08 21:49:47 +0100
committerCarl Hetherington <cth@carlh.net>2021-01-08 21:49:53 +0100
commit56b6a62a28734ad66d0f4c8ea9452b89f4cc5f45 (patch)
tree7150f6cc02654723bb7466c4942601eb624bf258 /src/encrypted_kdm.cc
parent4245000bfc5aa1d61428a6a983c2b0425d17ae42 (diff)
More c++11 tidying.
Diffstat (limited to 'src/encrypted_kdm.cc')
-rw-r--r--src/encrypted_kdm.cc101
1 files changed, 48 insertions, 53 deletions
diff --git a/src/encrypted_kdm.cc b/src/encrypted_kdm.cc
index ca2a8346..77345a5d 100644
--- a/src/encrypted_kdm.cc
+++ b/src/encrypted_kdm.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
This file is part of libdcp.
@@ -42,12 +42,12 @@
#include <libxml/parser.h>
#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/foreach.hpp>
#include <boost/format.hpp>
using std::list;
using std::vector;
using std::string;
+using std::make_shared;
using std::map;
using std::pair;
using std::shared_ptr;
@@ -141,12 +141,11 @@ public:
explicit SignedInfo (shared_ptr<const cxml::Node> node)
{
- list<shared_ptr<cxml::Node> > references = node->node_children ("Reference");
- for (list<shared_ptr<cxml::Node> >::const_iterator i = references.begin(); i != references.end(); ++i) {
- if ((*i)->string_attribute ("URI") == "#ID_AuthenticatedPublic") {
- authenticated_public = Reference (*i);
- } else if ((*i)->string_attribute ("URI") == "#ID_AuthenticatedPrivate") {
- authenticated_private = Reference (*i);
+ for (auto i: node->node_children ("Reference")) {
+ if (i->string_attribute("URI") == "#ID_AuthenticatedPublic") {
+ authenticated_public = Reference(i);
+ } else if (i->string_attribute("URI") == "#ID_AuthenticatedPrivate") {
+ authenticated_private = Reference(i);
}
/* XXX: do something if we don't recognise the node */
@@ -181,9 +180,8 @@ public:
: signed_info (node->node_child ("SignedInfo"))
, signature_value (node->string_child ("SignatureValue"))
{
- list<shared_ptr<cxml::Node> > x509_data_nodes = node->node_child("KeyInfo")->node_children ("X509Data");
- for (list<shared_ptr<cxml::Node> >::const_iterator i = x509_data_nodes.begin(); i != x509_data_nodes.end(); ++i) {
- x509_data.push_back (X509Data (*i));
+ for (auto i: node->node_child("KeyInfo")->node_children ("X509Data")) {
+ x509_data.push_back(X509Data(i));
}
}
@@ -192,9 +190,9 @@ public:
signed_info.as_xml (node->add_child ("SignedInfo", "ds"));
node->add_child("SignatureValue", "ds")->add_child_text (signature_value);
- xmlpp::Element* key_info_node = node->add_child ("KeyInfo", "ds");
- for (std::list<X509Data>::const_iterator i = x509_data.begin(); i != x509_data.end(); ++i) {
- i->as_xml (key_info_node->add_child ("X509Data", "ds"));
+ auto key_info_node = node->add_child("KeyInfo", "ds");
+ for (auto i: x509_data) {
+ i.as_xml (key_info_node->add_child("X509Data", "ds"));
}
}
@@ -210,9 +208,8 @@ public:
explicit AuthenticatedPrivate (shared_ptr<const cxml::Node> node)
{
- list<shared_ptr<cxml::Node> > encrypted_key_nodes = node->node_children ("EncryptedKey");
- for (list<shared_ptr<cxml::Node> >::const_iterator i = encrypted_key_nodes.begin(); i != encrypted_key_nodes.end(); ++i) {
- encrypted_key.push_back ((*i)->node_child("CipherData")->string_child ("CipherValue"));
+ for (auto i: node->node_children ("EncryptedKey")) {
+ encrypted_key.push_back (i->node_child("CipherData")->string_child("CipherValue"));
}
}
@@ -220,18 +217,18 @@ public:
{
references["ID_AuthenticatedPrivate"] = node->set_attribute ("Id", "ID_AuthenticatedPrivate");
- for (list<string>::const_iterator i = encrypted_key.begin(); i != encrypted_key.end(); ++i) {
- xmlpp::Element* encrypted_key = node->add_child ("EncryptedKey", "enc");
+ for (auto i: encrypted_key) {
+ auto encrypted_key = node->add_child ("EncryptedKey", "enc");
/* XXX: hack for testing with Dolby */
encrypted_key->set_namespace_declaration ("http://www.w3.org/2001/04/xmlenc#", "enc");
- xmlpp::Element* encryption_method = encrypted_key->add_child ("EncryptionMethod", "enc");
+ auto encryption_method = encrypted_key->add_child("EncryptionMethod", "enc");
encryption_method->set_attribute ("Algorithm", "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p");
- xmlpp::Element* digest_method = encryption_method->add_child ("DigestMethod", "ds");
+ auto digest_method = encryption_method->add_child ("DigestMethod", "ds");
/* XXX: hack for testing with Dolby */
digest_method->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "ds");
digest_method->set_attribute ("Algorithm", "http://www.w3.org/2000/09/xmldsig#sha1");
- xmlpp::Element* cipher_data = encrypted_key->add_child ("CipherData", "enc");
- cipher_data->add_child("CipherValue", "enc")->add_child_text (*i);
+ auto cipher_data = encrypted_key->add_child("CipherData", "enc");
+ cipher_data->add_child("CipherValue", "enc")->add_child_text (i);
}
}
@@ -279,16 +276,15 @@ public:
explicit KeyIdList (shared_ptr<const cxml::Node> node)
{
- list<shared_ptr<cxml::Node> > typed_key_id_nodes = node->node_children ("TypedKeyId");
- for (list<shared_ptr<cxml::Node> >::const_iterator i = typed_key_id_nodes.begin(); i != typed_key_id_nodes.end(); ++i) {
- typed_key_id.push_back (TypedKeyId (*i));
+ for (auto i: node->node_children ("TypedKeyId")) {
+ typed_key_id.push_back(TypedKeyId(i));
}
}
void as_xml (xmlpp::Element* node) const
{
- for (list<TypedKeyId>::const_iterator i = typed_key_id.begin(); i != typed_key_id.end(); ++i) {
- i->as_xml (node->add_child("TypedKeyId"));
+ for (auto const& i: typed_key_id) {
+ i.as_xml (node->add_child("TypedKeyId"));
}
}
@@ -304,7 +300,7 @@ public:
: device_list_identifier (remove_urn_uuid (node->string_child ("DeviceListIdentifier")))
, device_list_description (node->optional_string_child ("DeviceListDescription"))
{
- BOOST_FOREACH (cxml::ConstNodePtr i, node->node_child("DeviceList")->node_children("CertificateThumbprint")) {
+ for (auto i: node->node_child("DeviceList")->node_children("CertificateThumbprint")) {
certificate_thumbprints.push_back (i->content ());
}
}
@@ -315,8 +311,8 @@ public:
if (device_list_description) {
node->add_child ("DeviceListDescription")->add_child_text (device_list_description.get());
}
- xmlpp::Element* device_list = node->add_child ("DeviceList");
- BOOST_FOREACH (string i, certificate_thumbprints) {
+ auto device_list = node->add_child ("DeviceList");
+ for (auto i: certificate_thumbprints) {
device_list->add_child("CertificateThumbprint")->add_child_text (i);
}
}
@@ -388,14 +384,14 @@ public:
disable_forensic_marking_picture = false;
disable_forensic_marking_audio = optional<int>();
if (node->optional_node_child("ForensicMarkFlagList")) {
- BOOST_FOREACH (cxml::ConstNodePtr i, node->node_child("ForensicMarkFlagList")->node_children("ForensicMarkFlag")) {
+ for (auto i: node->node_child("ForensicMarkFlagList")->node_children("ForensicMarkFlag")) {
if (i->content() == picture_disable) {
disable_forensic_marking_picture = true;
} else if (starts_with(i->content(), audio_disable)) {
disable_forensic_marking_audio = 0;
string const above = audio_disable + "-above-channel-";
if (starts_with(i->content(), above)) {
- string above_number = i->content().substr(above.length());
+ auto above_number = i->content().substr(above.length());
if (above_number == "") {
throw KDMFormatError("Badly-formatted ForensicMarkFlag");
}
@@ -424,12 +420,12 @@ public:
key_id_list.as_xml (node->add_child ("KeyIdList"));
if (disable_forensic_marking_picture || disable_forensic_marking_audio) {
- xmlpp::Element* forensic_mark_flag_list = node->add_child ("ForensicMarkFlagList");
+ auto forensic_mark_flag_list = node->add_child ("ForensicMarkFlagList");
if (disable_forensic_marking_picture) {
forensic_mark_flag_list->add_child("ForensicMarkFlag")->add_child_text(picture_disable);
}
if (disable_forensic_marking_audio) {
- string mrkflg = audio_disable;
+ auto mrkflg = audio_disable;
if (*disable_forensic_marking_audio > 0) {
mrkflg += String::compose ("-above-channel-%1", *disable_forensic_marking_audio);
}
@@ -550,8 +546,8 @@ public:
authenticated_private.as_xml (root->add_child ("AuthenticatedPrivate"), references);
signature.as_xml (root->add_child ("Signature", "ds"));
- for (map<string, xmlpp::Attribute*>::const_iterator i = references.begin(); i != references.end(); ++i) {
- xmlAddID (0, document->cobj(), (const xmlChar *) i->first.c_str(), i->second->cobj ());
+ for (auto i: references) {
+ xmlAddID (0, document->cobj(), (const xmlChar *) i.first.c_str(), i.second->cobj());
}
indent (document->get_root_node(), 0);
@@ -569,7 +565,7 @@ public:
EncryptedKDM::EncryptedKDM (string s)
{
try {
- shared_ptr<cxml::Document> doc (new cxml::Document ("DCinemaSecurityMessage"));
+ auto doc = make_shared<cxml::Document>("DCinemaSecurityMessage");
doc->read_string (s);
_data = new data::EncryptedKDMData (doc);
} catch (xmlpp::parse_error& e) {
@@ -611,7 +607,7 @@ EncryptedKDM::EncryptedKDM (
aup.signer.x509_serial_number = signer->leaf().serial ();
aup.annotation_text = annotation_text;
- data::KDMRequiredExtensions& kre = _data->authenticated_public.required_extensions.kdm_required_extensions;
+ auto& kre = _data->authenticated_public.required_extensions.kdm_required_extensions;
kre.recipient.x509_issuer_serial.x509_issuer_name = recipient.issuer ();
kre.recipient.x509_issuer_serial.x509_serial_number = recipient.serial ();
kre.recipient.x509_subject_name = recipient.subject ();
@@ -628,7 +624,7 @@ EncryptedKDM::EncryptedKDM (
if (formulation != MODIFIED_TRANSITIONAL_TEST) {
kre.authorized_device_info = data::AuthorizedDeviceInfo ();
kre.authorized_device_info->device_list_identifier = make_uuid ();
- string n = recipient.subject_common_name ();
+ auto n = recipient.subject_common_name ();
if (n.find (".") != string::npos) {
n = n.substr (n.find (".") + 1);
}
@@ -653,30 +649,29 @@ EncryptedKDM::EncryptedKDM (
recipient's thumbprint (recipient.thumbprint()).
Waimea uses only the trusted devices here, too.
*/
- BOOST_FOREACH (string i, trusted_devices) {
- kre.authorized_device_info->certificate_thumbprints.push_back (i);
+ for (auto i: trusted_devices) {
+ kre.authorized_device_info->certificate_thumbprints.push_back(i);
}
}
}
}
- for (list<pair<string, string> >::const_iterator i = key_ids.begin(); i != key_ids.end(); ++i) {
- kre.key_id_list.typed_key_id.push_back (data::TypedKeyId (i->first, i->second));
+ for (auto i: key_ids) {
+ kre.key_id_list.typed_key_id.push_back(data::TypedKeyId(i.first, i.second));
}
_data->authenticated_private.encrypted_key = keys;
/* Read the XML so far and sign it */
- shared_ptr<xmlpp::Document> doc = _data->as_xml ();
- xmlpp::Node::NodeList children = doc->get_root_node()->get_children ();
- for (xmlpp::Node::NodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
- if ((*i)->get_name() == "Signature") {
- signer->add_signature_value (dynamic_cast<xmlpp::Element*>(*i), "ds", false);
+ auto doc = _data->as_xml ();
+ for (auto i: doc->get_root_node()->get_children()) {
+ if (i->get_name() == "Signature") {
+ signer->add_signature_value(dynamic_cast<xmlpp::Element*>(i), "ds", false);
}
}
/* Read the bits that add_signature_value did back into our variables */
- shared_ptr<cxml::Node> signed_doc (new cxml::Node (doc->get_root_node ()));
+ auto signed_doc = make_shared<cxml::Node>(doc->get_root_node());
_data->signature = data::Signature (signed_doc->node_child ("Signature"));
}
@@ -706,11 +701,11 @@ EncryptedKDM::~EncryptedKDM ()
void
EncryptedKDM::as_xml (boost::filesystem::path path) const
{
- FILE* f = fopen_boost (path, "w");
+ auto f = fopen_boost (path, "w");
if (!f) {
throw FileError ("Could not open KDM file for writing", path, errno);
}
- string const x = as_xml ();
+ auto const x = as_xml ();
size_t const written = fwrite (x.c_str(), 1, x.length(), f);
fclose (f);
if (written != x.length()) {
@@ -782,7 +777,7 @@ CertificateChain
EncryptedKDM::signer_certificate_chain () const
{
CertificateChain chain;
- BOOST_FOREACH (data::X509Data const & i, _data->signature.x509_data) {
+ for (auto const& i: _data->signature.x509_data) {
string s = "-----BEGIN CERTIFICATE-----\n" + i.x509_certificate + "\n-----END CERTIFICATE-----";
chain.add (Certificate(s));
}