Throw NotEncryptedError on an attempt to generate KDM for a non-encrypted asset....
authorCarl Hetherington <cth@carlh.net>
Wed, 28 May 2014 22:13:37 +0000 (23:13 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 28 May 2014 22:13:37 +0000 (23:13 +0100)
src/exceptions.cc
src/exceptions.h
src/kdm.cc

index 951627a5afe65e55e034696067c7ed75dc7bbde6..eb655bfa3df682f6a477cc282312aec9f89d4aed 100644 (file)
 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))
+{
+
+}
index 2070dd0fa44d38cb3f2b682790a827d9ad5c3d2f..dfbea60bcdb8490666783498357e4e676242e66c 100644 (file)
 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 () {}
 };
        
 }
index 4a03b33fe53f7940a3a3bbcb05c768c80d5aa9a9..21fa0eaa5dac5488d0f4fbd7084e1cc76c4b16a8 100644 (file)
@@ -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