From 98c2cae73faf52dc346758e893f7e38d2c349c03 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 24 May 2017 12:47:36 +0100 Subject: Better exception when loading a KDM fails. --- src/encrypted_kdm.cc | 13 +++++++++---- src/exceptions.cc | 6 ++++++ src/exceptions.h | 6 ++++++ 3 files changed, 21 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/encrypted_kdm.cc b/src/encrypted_kdm.cc index b6a992fb..054162cc 100644 --- a/src/encrypted_kdm.cc +++ b/src/encrypted_kdm.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2016 Carl Hetherington + Copyright (C) 2013-2017 Carl Hetherington This file is part of libdcp. @@ -34,6 +34,7 @@ #include "encrypted_kdm.h" #include "util.h" #include "certificate_chain.h" +#include "exceptions.h" #include #include #include @@ -525,9 +526,13 @@ public: EncryptedKDM::EncryptedKDM (string s) { - shared_ptr doc (new cxml::Document ("DCinemaSecurityMessage")); - doc->read_string (s); - _data = new data::EncryptedKDMData (doc); + try { + shared_ptr doc (new cxml::Document ("DCinemaSecurityMessage")); + doc->read_string (s); + _data = new data::EncryptedKDMData (doc); + } catch (xmlpp::parse_error& e) { + throw KDMFormatError (e.what ()); + } } EncryptedKDM::EncryptedKDM ( diff --git a/src/exceptions.cc b/src/exceptions.cc index b541beda..fbd8c85f 100644 --- a/src/exceptions.cc +++ b/src/exceptions.cc @@ -96,3 +96,9 @@ KDMDecryptionError::KDMDecryptionError (std::string message) { } + +KDMFormatError::KDMFormatError (std::string message) + : runtime_error (String::compose ("Could not parse KDM (%1)", message)) +{ + +} diff --git a/src/exceptions.h b/src/exceptions.h index 2688ee86..ed77ae3a 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -179,6 +179,12 @@ public: KDMDecryptionError (std::string message); }; +class KDMFormatError : public std::runtime_error +{ +public: + KDMFormatError (std::string message); +}; + } #endif -- cgit v1.2.3