Disable test building for cdist linux builds.
[libdcp.git] / src / signer_chain.cc
index d407286ee3dc72854a716c010cc42ffee0ed1324..3b75b06ccae717939c46fea3bf52a6b2417682fa 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 */
 
-#include <fstream>
-#include <sstream>
-#include <boost/filesystem.hpp>
-#include <boost/algorithm/string.hpp>
-#include <openssl/sha.h>
-#include <openssl/bio.h>
-#include <openssl/evp.h>
-#include "KM_util.h"
+/** @file  src/signer_chain.cc
+ *  @brief Functions to make signer chains.
+ */
+
 #include "signer_chain.h"
 #include "exceptions.h"
 #include "util.h"
+#include "KM_util.h"
+#include <openssl/sha.h>
+#include <openssl/bio.h>
+#include <openssl/evp.h>
+#include <boost/filesystem.hpp>
+#include <boost/algorithm/string.hpp>
+#include <fstream>
+#include <sstream>
 
 using std::string;
 using std::ofstream;
@@ -35,7 +39,11 @@ using std::ifstream;
 using std::stringstream;
 using std::cout;
 
-static void command (string cmd)
+/** Run a shell command.
+ *  @param cmd Command to run (UTF8-encoded).
+ */
+static void
+command (string cmd)
 {
 #ifdef LIBDCP_WINDOWS
        /* We need to use CreateProcessW on Windows so that the UTF-8/16 mess
@@ -70,22 +78,22 @@ static void command (string cmd)
 
        delete[] buffer;
 #else
+       cmd += " 2> /dev/null";
        int const r = system (cmd.c_str ());
        int const code = WEXITSTATUS (r);
 #endif
        if (code) {
                stringstream s;
                s << "error " << code << " in " << cmd << " within " << boost::filesystem::current_path();
-               throw libdcp::MiscError (s.str());
+               throw dcp::MiscError (s.str());
        }
 }
 
 /** Extract a public key from a private key and create a SHA1 digest of it.
- *  @param key Private key
+ *  @param private_key Private key
  *  @param openssl openssl binary name (or full path if openssl is not on the system path).
  *  @return SHA1 digest of corresponding public key, with escaped / characters.
  */
-       
 static string
 public_key_digest (boost::filesystem::path private_key, boost::filesystem::path openssl)
 {
@@ -101,7 +109,7 @@ public_key_digest (boost::filesystem::path private_key, boost::filesystem::path
        string pub;
        ifstream f (public_name.string().c_str ());
        if (!f.good ()) {
-               throw libdcp::MiscError ("public key not found");
+               throw dcp::MiscError ("public key not found");
        }
 
        bool read = false;
@@ -120,22 +128,22 @@ public_key_digest (boost::filesystem::path private_key, boost::filesystem::path
        /* Decode the base64 of the public key */
                
        unsigned char buffer[512];
-       int const N = libdcp::base64_decode (pub, buffer, 1024);
+       int const N = dcp::base64_decode (pub, buffer, 1024);
 
        /* Hash it with SHA1 (without the first 24 bytes, for reasons that are not entirely clear) */
 
        SHA_CTX context;
        if (!SHA1_Init (&context)) {
-               throw libdcp::MiscError ("could not init SHA1 context");
+               throw dcp::MiscError ("could not init SHA1 context");
        }
 
        if (!SHA1_Update (&context, buffer + 24, N - 24)) {
-               throw libdcp::MiscError ("could not update SHA1 digest");
+               throw dcp::MiscError ("could not update SHA1 digest");
        }
 
        unsigned char digest[SHA_DIGEST_LENGTH];
        if (!SHA1_Final (digest, &context)) {
-               throw libdcp::MiscError ("could not finish SHA1 digest");
+               throw dcp::MiscError ("could not finish SHA1 digest");
        }
 
        char digest_base64[64];
@@ -148,8 +156,12 @@ public_key_digest (boost::filesystem::path private_key, boost::filesystem::path
        return dig;
 }
 
+/** Generate a chain of root, intermediate and leaf keys by running an OpenSSL binary.
+ *  @param directory Directory to write the files to.
+ *  @param openssl openssl binary path.
+ */
 void
-libdcp::make_signer_chain (boost::filesystem::path directory, boost::filesystem::path openssl)
+dcp::make_signer_chain (boost::filesystem::path directory, boost::filesystem::path openssl)
 {
        boost::filesystem::path const cwd = boost::filesystem::current_path ();