summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-05-28 23:13:37 +0100
committerCarl Hetherington <cth@carlh.net>2014-05-28 23:13:37 +0100
commitff9a83e4d57c30409162ae1cb94fe471d8f2cf6f (patch)
treeb48eda076d3d1cc20c032af6bf43d39dc0626bf8 /src
parentc272879a8e748be83acbb190257d78a34be3f25f (diff)
Throw NotEncryptedError on an attempt to generate KDM for a non-encrypted asset. Tidy exceptions a bit.
Diffstat (limited to 'src')
-rw-r--r--src/exceptions.cc9
-rw-r--r--src/exceptions.h78
-rw-r--r--src/kdm.cc12
3 files changed, 58 insertions, 41 deletions
diff --git a/src/exceptions.cc b/src/exceptions.cc
index 951627a5..eb655bfa 100644
--- a/src/exceptions.cc
+++ b/src/exceptions.cc
@@ -23,11 +23,16 @@
using std::string;
using namespace libdcp;
-FileError::FileError (std::string const & message, boost::filesystem::path filename, int number)
- : _message (String::compose ("%1 (%2) (error %3)", message, filename.string(), number))
+FileError::FileError (string const & message, boost::filesystem::path filename, int number)
+ : StringError (String::compose ("%1 (%2) (error %3)", message, filename.string(), number))
, _filename (filename)
, _number (number)
{
}
+NotEncryptedError::NotEncryptedError (string const & what)
+ : StringError (String::compose ("%1 asset is not encrypted", what))
+{
+
+}
diff --git a/src/exceptions.h b/src/exceptions.h
index 2070dd0f..dfbea60b 100644
--- a/src/exceptions.h
+++ b/src/exceptions.h
@@ -29,18 +29,31 @@
namespace libdcp
{
-/** @brief An exception related to a file */
-class FileError : public std::exception
+class StringError : public std::exception
{
public:
- FileError (std::string const & message, boost::filesystem::path filename, int number);
- ~FileError () throw () {}
+ StringError (std::string const & message)
+ : _message (message)
+ {}
+
+ ~StringError () throw () {}
/** @return error message */
char const * what () const throw () {
return _message.c_str ();
}
-
+
+private:
+ std::string _message;
+};
+
+/** @brief An exception related to a file */
+class FileError : public StringError
+{
+public:
+ FileError (std::string const & message, boost::filesystem::path filename, int number);
+ ~FileError () throw () {}
+
/** @return filename of file that was involved */
boost::filesystem::path filename () const {
return _filename;
@@ -52,8 +65,6 @@ public:
}
private:
- /** message part */
- std::string _message;
/** filename of file that was involved */
boost::filesystem::path _filename;
int _number;
@@ -69,54 +80,43 @@ public:
};
/** @brief A miscellaneous exception */
-class MiscError : public std::exception
+class MiscError : public StringError
{
public:
- MiscError (std::string const & message) : _message (message) {}
+ MiscError (std::string const & message)
+ : StringError (message)
+ {}
+
~MiscError () throw () {}
-
- /** @return error message */
- char const * what () const throw () {
- return _message.c_str ();
- }
-
-private:
- /** error message */
- std::string _message;
};
/** @brief A DCP read exception */
-class DCPReadError : public std::exception
+class DCPReadError : public StringError
{
public:
- DCPReadError (std::string const & message) : _message (message) {}
+ DCPReadError (std::string const & message)
+ : StringError (message)
+ {}
+
~DCPReadError () throw () {}
-
- /** @return error message */
- char const * what () const throw () {
- return _message.c_str ();
- }
-
-private:
- /** error message */
- std::string _message;
};
/** @brief An XML error */
-class XMLError : public std::exception
+class XMLError : public StringError
{
public:
- XMLError (std::string const & message) : _message (message) {}
- ~XMLError () throw () {}
+ XMLError (std::string const & message)
+ : StringError (message)
+ {}
- /** @return error message */
- char const * what () const throw () {
- return _message.c_str ();
- }
+ ~XMLError () throw () {}
+};
-private:
- /** error message */
- std::string _message;
+class NotEncryptedError : public StringError
+{
+public:
+ NotEncryptedError (std::string const & asset);
+ ~NotEncryptedError () throw () {}
};
}
diff --git a/src/kdm.cc b/src/kdm.cc
index 4a03b33f..21fa0eaa 100644
--- a/src/kdm.cc
+++ b/src/kdm.cc
@@ -158,6 +158,10 @@ KDM::KDM (
/* XXX: subtitle assets? */
if ((*i)->asset_list->main_picture) {
+ if ((*i)->asset_list->main_picture->key_id.empty ()) {
+ throw NotEncryptedError ("MainPicture");
+ }
+
KDMKey kkey (
signer, cpl.id.substr (9), "MDIK", (*i)->asset_list->main_picture->key_id.substr (9),
not_valid_before, not_valid_after, key
@@ -168,6 +172,10 @@ KDM::KDM (
}
if ((*i)->asset_list->main_stereoscopic_picture) {
+ if ((*i)->asset_list->main_stereoscopic_picture->key_id.empty ()) {
+ throw NotEncryptedError ("MainStereoscopicPicture");
+ }
+
KDMKey kkey (
signer, cpl.id.substr (9), "MDIK", (*i)->asset_list->main_stereoscopic_picture->key_id.substr (9),
not_valid_before, not_valid_after, key
@@ -178,6 +186,10 @@ KDM::KDM (
}
if ((*i)->asset_list->main_sound) {
+ if ((*i)->asset_list->main_sound->key_id.empty ()) {
+ throw NotEncryptedError ("MainSound");
+ }
+
KDMKey kkey (
signer, cpl.id.substr (9), "MDAK", (*i)->asset_list->main_sound->key_id.substr (9),
not_valid_before, not_valid_after, key