Fix missing version string when Popen communicate returns byte strings.
[libdcp.git] / src / util.cc
index f61a5f38732e1f9c0c1e7908830e4f064dab1bc4..3d90ccaa4fe7f6e1155c45cd8e2d6e7ec43e2c88 100644 (file)
     You should have received a copy of the GNU General Public License
     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
 
+    In addition, as a special exception, the copyright holders give
+    permission to link the code of portions of this program with the
+    OpenSSL library under certain conditions as described in each
+    individual source file, and distribute linked combinations
+    including the two.
+
+    You must obey the GNU General Public License in all respects
+    for all of the code used other than OpenSSL.  If you modify
+    file(s) with this exception, you may extend this exception to your
+    version of the file(s), but you are not obligated to do so.  If you
+    do not wish to do so, delete this exception statement from your
+    version.  If you delete this exception statement from all source
+    files in the program, then also delete it here.
 */
 
 /** @file  src/util.cc
 #include "openjpeg_image.h"
 #include "dcp_assert.h"
 #include "compose.hpp"
-#include "KM_util.h"
-#include "KM_fileio.h"
-#include "AS_DCP.h"
+#include <openjpeg.h>
+#include <asdcp/KM_util.h>
+#include <asdcp/KM_fileio.h>
+#include <asdcp/AS_DCP.h>
 #include <xmlsec/xmldsig.h>
 #include <xmlsec/dl.h>
 #include <xmlsec/app.h>
 #include <boost/filesystem.hpp>
 #include <boost/algorithm/string.hpp>
 #include <stdexcept>
-#include <sstream>
 #include <iostream>
 #include <iomanip>
 
 using std::string;
 using std::wstring;
 using std::cout;
-using std::stringstream;
 using std::min;
 using std::max;
 using std::list;
@@ -76,6 +88,17 @@ dcp::make_uuid ()
        return string (buffer);
 }
 
+string
+dcp::make_digest (Data data)
+{
+       SHA_CTX sha;
+       SHA1_Init (&sha);
+       SHA1_Update (&sha, data.data().get(), data.size());
+       byte_t byte_buffer[SHA_DIGEST_LENGTH];
+       SHA1_Final (byte_buffer, &sha);
+       char digest[64];
+       return Kumu::base64encode (byte_buffer, SHA_DIGEST_LENGTH, digest, 64);
+}
 
 /** Create a digest for a file.
  *  @param filename File name.
@@ -232,22 +255,8 @@ dcp::init ()
        if (xmlSecCryptoInit() < 0) {
                throw MiscError ("could not initialise xmlsec-crypto");
        }
-}
-
-bool dcp::operator== (dcp::Size const & a, dcp::Size const & b)
-{
-       return (a.width == b.width && a.height == b.height);
-}
 
-bool dcp::operator!= (dcp::Size const & a, dcp::Size const & b)
-{
-       return !(a == b);
-}
-
-ostream& dcp::operator<< (ostream& s, dcp::Size const & a)
-{
-       s << a.width << "x" << a.height;
-       return s;
+       OpenSSL_add_all_algorithms();
 }
 
 /** Decode a base64 string.  The base64 decode routine in KM_util.cpp
@@ -342,7 +351,7 @@ dcp::file_to_string (boost::filesystem::path p, uintmax_t max_length)
 {
        uintmax_t len = boost::filesystem::file_size (p);
        if (len > max_length) {
-               throw MiscError ("Unexpectedly long file");
+               throw MiscError (String::compose ("Unexpectedly long file (%1)", p.string()));
        }
 
        FILE* f = fopen_boost (p, "r");
@@ -402,3 +411,9 @@ dcp::remove_urn_uuid (string raw)
        DCP_ASSERT (raw.substr(0, 9) == "urn:uuid:");
        return raw.substr (9);
 }
+
+string
+dcp::openjpeg_version ()
+{
+       return opj_version ();
+}