diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-12-06 17:40:25 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-12-22 01:21:00 +0100 |
| commit | b60fd2d2b68be2a2fcfe067fd5a96af5b08e3a8d (patch) | |
| tree | 206cae9720d37ce7830a5758cd71794afe2ed9c8 /src | |
| parent | e975e945a5520654db949324de7992ea70d442ee (diff) | |
Use regex and check <IssueDate> in CPL.
Diffstat (limited to 'src')
| -rw-r--r-- | src/verify.cc | 50 | ||||
| -rw-r--r-- | src/verify.h | 2 |
2 files changed, 34 insertions, 18 deletions
diff --git a/src/verify.cc b/src/verify.cc index f4b89afd..032a3f39 100644 --- a/src/verify.cc +++ b/src/verify.cc @@ -39,8 +39,10 @@ #include "reel_sound_asset.h" #include "exceptions.h" #include "compose.hpp" +#include "raw_convert.h" #include <boost/foreach.hpp> #include <boost/algorithm/string.hpp> +#include <boost/regex.hpp> #include <list> #include <vector> #include <iostream> @@ -96,37 +98,44 @@ verify_asset (shared_ptr<DCP> dcp, shared_ptr<ReelMXF> reel_mxf, function<void ( static bool -hex (string s) +good_urn_uuid (string id) { - for (size_t i = 0; i < s.length(); ++i) { - if (string("0123456789abcdef").find(s[i]) == string::npos) { - return false; - } - } - - return true; + boost::regex ex("urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"); + return boost::regex_match (id, ex); } static bool -good_urn_uuid (string id) +good_date (string date) { - if (id.length() != 45) { + boost::regex ex("\\d{4}-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})[+-](\\d{2}):(\\d{2})"); + boost::match_results<string::const_iterator> res; + if (!regex_match (date, res, ex, boost::match_default)) { return false; } - - if (!boost::algorithm::starts_with(id, "urn:uuid:")) { + int const month = dcp::raw_convert<int>(res[1].str()); + if (month < 1 || month > 12) { return false; } - - if (id[17] != '-' || id[22] != '-' || id[27] != '-' || id[32] != '-') { + int const day = dcp::raw_convert<int>(res[2].str()); + if (day < 1 || day > 31) { return false; } - - if (!hex(id.substr(9, 8)) || !hex(id.substr(18, 4)) || !hex(id.substr(23, 4)) || !hex(id.substr(28, 4)) || !hex(id.substr(33, 8))) { + if (dcp::raw_convert<int>(res[3].str()) > 23) { + return false; + } + if (dcp::raw_convert<int>(res[4].str()) > 59) { + return false; + } + if (dcp::raw_convert<int>(res[5].str()) > 59) { + return false; + } + if (dcp::raw_convert<int>(res[6].str()) > 23) { + return false; + } + if (dcp::raw_convert<int>(res[7].str()) > 59) { return false; } - return true; } @@ -158,6 +167,9 @@ dcp::verify (vector<boost::filesystem::path> directories, function<void (string, if (!good_urn_uuid(cpl_doc.string_child("Id"))) { notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::Code::BAD_URN_UUID, string("CPL <Id> is malformed"))); } + if (!good_date(cpl_doc.string_child("IssueDate"))) { + notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::Code::BAD_DATE, string("CPL <IssueDate> is malformed"))); + } /* Check that the CPL's hash corresponds to the PKL */ BOOST_FOREACH (shared_ptr<PKL> i, dcp->pkls()) { @@ -252,7 +264,9 @@ dcp::note_to_string (dcp::VerificationNote note) case dcp::VerificationNote::MISMATCHED_STANDARD: return "The DCP contains both SMPTE and Interop parts."; case dcp::VerificationNote::BAD_URN_UUID: - return "There is a badly formed urn:uuid."; + return "There is a badly-formed urn:uuid."; + case dcp::VerificationNote::BAD_DATE: + return "There is a badly-formed date."; } return ""; diff --git a/src/verify.h b/src/verify.h index 1403797c..4007f8fb 100644 --- a/src/verify.h +++ b/src/verify.h @@ -77,6 +77,8 @@ public: MISMATCHED_STANDARD, /** A urn:uuid ID is badly formed */ BAD_URN_UUID, + /** A date is badly formed */ + BAD_DATE, }; VerificationNote (Type type, Code code) |
