From ed3326d5ac0f05762f820a341332718ebea220f5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 30 Apr 2015 23:19:51 +0100 Subject: [PATCH 1/1] Some BOOST_FOREACH. --- src/cpl.cc | 33 ++++++++++++++-------------- src/dcp.cc | 51 +++++++++++++++++++++----------------------- src/decrypted_kdm.cc | 25 ++++++++++------------ 3 files changed, 52 insertions(+), 57 deletions(-) diff --git a/src/cpl.cc b/src/cpl.cc index b0fc8d77..b11452d9 100644 --- a/src/cpl.cc +++ b/src/cpl.cc @@ -30,6 +30,7 @@ #include "dcp_assert.h" #include "compose.hpp" #include +#include using std::string; using std::stringstream; @@ -135,9 +136,9 @@ CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptradd_child("RatingList"); xmlpp::Element* reel_list = root->add_child ("ReelList"); - - for (list >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { - (*i)->write_to_cpl (reel_list, standard); + + BOOST_FOREACH (shared_ptr i, _reels) { + i->write_to_cpl (reel_list, standard); } if (signer) { @@ -155,15 +156,15 @@ CPL::reel_assets () const { list > c; - for (list >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { - if ((*i)->main_picture ()) { - c.push_back ((*i)->main_picture()); + BOOST_FOREACH (shared_ptr i, _reels) { + if (i->main_picture ()) { + c.push_back (i->main_picture()); } - if ((*i)->main_sound ()) { - c.push_back ((*i)->main_sound()); + if (i->main_sound ()) { + c.push_back (i->main_sound()); } - if ((*i)->main_subtitle ()) { - c.push_back ((*i)->main_subtitle()); + if (i->main_subtitle ()) { + c.push_back (i->main_subtitle()); } } @@ -213,8 +214,8 @@ CPL::equals (shared_ptr other, EqualityOptions opt, NoteHandler not bool CPL::encrypted () const { - for (list >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { - if ((*i)->encrypted ()) { + BOOST_FOREACH (shared_ptr i, _reels) { + if (i->encrypted ()) { return true; } } @@ -229,16 +230,16 @@ CPL::encrypted () const void CPL::add (DecryptedKDM const & kdm) { - for (list >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { - (*i)->add (kdm); + BOOST_FOREACH (shared_ptr i, _reels) { + i->add (kdm); } } void CPL::resolve_refs (list > objects) { - for (list >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) { - (*i)->resolve_refs (objects); + BOOST_FOREACH (shared_ptr i, _reels) { + i->resolve_refs (objects); } } diff --git a/src/dcp.cc b/src/dcp.cc index dd360edd..f98fa1d3 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -44,6 +44,7 @@ #include #include #include +#include #include using std::string; @@ -98,15 +99,15 @@ DCP::read (bool keep_going, ReadErrors* errors) asset_map.read_file (asset_map_file); list > asset_nodes = asset_map.node_child("AssetList")->node_children ("Asset"); map paths; - for (list >::const_iterator i = asset_nodes.begin(); i != asset_nodes.end(); ++i) { - if ((*i)->node_child("ChunkList")->node_children("Chunk").size() != 1) { + BOOST_FOREACH (shared_ptr i, asset_nodes) { + if (i->node_child("ChunkList")->node_children("Chunk").size() != 1) { boost::throw_exception (XMLError ("unsupported asset chunk count")); } - string p = (*i)->node_child("ChunkList")->node_child("Chunk")->string_child ("Path"); + string p = i->node_child("ChunkList")->node_child("Chunk")->string_child ("Path"); if (starts_with (p, "file://")) { p = p.substr (7); } - paths.insert (make_pair ((*i)->string_child ("Id"), p)); + paths.insert (make_pair (i->string_child ("Id"), p)); } /* Read all the assets from the asset map */ @@ -166,9 +167,8 @@ DCP::read (bool keep_going, ReadErrors* errors) } } - list > cpl = cpls (); - for (list >::const_iterator i = cpl.begin(); i != cpl.end(); ++i) { - (*i)->resolve_refs (list_of_type (assets ())); + BOOST_FOREACH (shared_ptr i, cpls ()) { + i->resolve_refs (list_of_type (assets ())); } } @@ -185,9 +185,9 @@ DCP::equals (DCP const & other, EqualityOptions opt, NoteHandler note) const bool r = true; - for (list >::const_iterator i = a.begin(); i != a.end(); ++i) { + BOOST_FOREACH (shared_ptr i, a) { list >::const_iterator j = b.begin (); - while (j != b.end() && !(*j)->equals (*i, opt, note)) { + while (j != b.end() && !(*j)->equals (i, opt, note)) { ++j; } @@ -208,9 +208,8 @@ DCP::add (boost::shared_ptr asset) bool DCP::encrypted () const { - list > cpl = cpls (); - for (list >::const_iterator i = cpl.begin(); i != cpl.end(); ++i) { - if ((*i)->encrypted ()) { + BOOST_FOREACH (shared_ptr i, cpls ()) { + if (i->encrypted ()) { return true; } } @@ -222,12 +221,11 @@ void DCP::add (DecryptedKDM const & kdm) { list keys = kdm.keys (); - list > cpl = cpls (); - - for (list >::iterator i = cpl.begin(); i != cpl.end(); ++i) { - for (list::iterator j = keys.begin(); j != keys.end(); ++j) { - if (j->cpl_id() == (*i)->id()) { - (*i)->add (kdm); + + BOOST_FOREACH (shared_ptr i, cpls ()) { + BOOST_FOREACH (DecryptedKDMKey const & j, kdm.keys ()) { + if (j.cpl_id() == i->id()) { + i->add (kdm); } } } @@ -262,8 +260,8 @@ DCP::write_pkl (Standard standard, string pkl_uuid, XMLMetadata metadata, shared pkl->add_child("Creator")->add_child_text (metadata.creator); xmlpp::Element* asset_list = pkl->add_child("AssetList"); - for (list >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) { - (*i)->write_to_pkl (asset_list, standard); + BOOST_FOREACH (shared_ptr i, _assets) { + i->write_to_pkl (asset_list, standard); } if (signer) { @@ -371,9 +369,9 @@ DCP::write_assetmap (Standard standard, string pkl_uuid, int pkl_length, XMLMeta chunk->add_child("VolumeIndex")->add_child_text ("1"); chunk->add_child("Offset")->add_child_text ("0"); chunk->add_child("Length")->add_child_text (raw_convert (pkl_length)); - - for (list >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) { - (*i)->write_to_assetmap (asset_list, _directory); + + BOOST_FOREACH (shared_ptr i, _assets) { + i->write_to_assetmap (asset_list, _directory); } /* This must not be the _formatted version otherwise signature digests will be wrong */ @@ -392,10 +390,9 @@ DCP::write_xml ( shared_ptr signer ) { - list > cpl = cpls (); - for (list >::const_iterator i = cpl.begin(); i != cpl.end(); ++i) { - string const filename = (*i)->id() + "_cpl.xml"; - (*i)->write_xml (_directory / filename, standard, signer); + BOOST_FOREACH (shared_ptr i, cpls ()) { + string const filename = i->id() + "_cpl.xml"; + i->write_xml (_directory / filename, standard, signer); } string const pkl_uuid = make_uuid (); diff --git a/src/decrypted_kdm.cc b/src/decrypted_kdm.cc index 5f374dc7..bf9daa1a 100644 --- a/src/decrypted_kdm.cc +++ b/src/decrypted_kdm.cc @@ -33,6 +33,7 @@ #include #include #include +#include using std::list; using std::string; @@ -116,12 +117,10 @@ DecryptedKDM::DecryptedKDM (EncryptedKDM const & kdm, string private_key) /* Use the private key to decrypt the keys */ - list const encrypted_keys = kdm.keys (); - for (list::const_iterator i = encrypted_keys.begin(); i != encrypted_keys.end(); ++i) { - + BOOST_FOREACH (string const & i, kdm.keys ()) { /* Decode the base-64-encoded cipher value from the KDM */ unsigned char cipher_value[256]; - int const cipher_value_len = base64_decode (*i, cipher_value, sizeof (cipher_value)); + int const cipher_value_len = base64_decode (i, cipher_value, sizeof (cipher_value)); /* Decrypt it */ unsigned char * decrypted = new unsigned char[RSA_size(rsa)]; @@ -200,10 +199,9 @@ DecryptedKDM::DecryptedKDM ( , _issue_date (issue_date) { /* Create DecryptedKDMKey objects for each MXF asset */ - list > assets = cpl->reel_assets (); - for (list >::iterator i = assets.begin(); i != assets.end(); ++i) { + BOOST_FOREACH(shared_ptr i, cpl->reel_assets ()) { /* XXX: do non-MXF assets need keys? */ - shared_ptr mxf = boost::dynamic_pointer_cast (*i); + shared_ptr mxf = boost::dynamic_pointer_cast (i); if (mxf) { if (mxf->key_id().empty ()) { throw NotEncryptedError (mxf->id()); @@ -218,9 +216,8 @@ DecryptedKDM::encrypt (shared_ptr signer, Certificate recipient, F { list > key_ids; list keys; - for (list::const_iterator i = _keys.begin(); i != _keys.end(); ++i) { - - key_ids.push_back (make_pair (i->type(), i->id ())); + BOOST_FOREACH (DecryptedKDMKey const & i, _keys) { + key_ids.push_back (make_pair (i.type(), i.id ())); /* XXX: SMPTE only */ uint8_t block[138]; @@ -233,12 +230,12 @@ DecryptedKDM::encrypt (shared_ptr signer, Certificate recipient, F base64_decode (signer->certificates().leaf().thumbprint (), p, 20); p += 20; - put_uuid (&p, i->cpl_id ()); - put (&p, i->type ()); - put_uuid (&p, i->id ()); + put_uuid (&p, i.cpl_id ()); + put (&p, i.type ()); + put_uuid (&p, i.id ()); put (&p, _not_valid_before.as_string ()); put (&p, _not_valid_after.as_string ()); - put (&p, i->key().value(), ASDCP::KeyLen); + put (&p, i.key().value(), ASDCP::KeyLen); /* Encrypt using the projector's public key */ RSA* rsa = recipient.public_key (); -- 2.30.2