summaryrefslogtreecommitdiff
path: root/src/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-08 19:00:15 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-08 19:00:15 +0100
commit62f94281437fc54f4806cc65e3aecca5cd118f7c (patch)
treebbb44c0266b21f112f4a6d4f64e777d6894b2e8e /src/util.cc
parent321d1b056040a472aba7ac43dc4938087124ec2e (diff)
Use openssl's base-64 decoding for KDMs.
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index e909e3cb..18fa1b17 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -405,3 +405,30 @@ bool libdcp::operator!= (libdcp::Size const & a, libdcp::Size const & b)
return !(a == b);
}
+/** The base64 decode routine in KM_util.cpp gives different values to both
+ * this and the command-line base64 for some inputs. Not sure why.
+ */
+int
+libdcp::base64_decode (string const & in, unsigned char* out, int out_length)
+{
+ BIO* b64 = BIO_new (BIO_f_base64 ());
+
+ /* This means the input should have no newlines */
+ BIO_set_flags (b64, BIO_FLAGS_BASE64_NO_NL);
+
+ /* Copy our input string, removing newlines */
+ char in_buffer[in.size() + 1];
+ char* p = in_buffer;
+ for (size_t i = 0; i < in.size(); ++i) {
+ if (in[i] != '\n' && in[i] != '\r') {
+ *p++ = in[i];
+ }
+ }
+
+ BIO* bmem = BIO_new_mem_buf (in_buffer, p - in_buffer);
+ bmem = BIO_push (b64, bmem);
+ int const N = BIO_read (bmem, out, out_length);
+ BIO_free_all (bmem);
+
+ return N;
+}