More stringstream removal.
authorCarl Hetherington <cth@carlh.net>
Thu, 11 Aug 2016 15:22:28 +0000 (16:22 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 11 Aug 2016 15:22:28 +0000 (16:22 +0100)
src/certificate_chain.cc
src/key.cc
src/types.cc

index 0cf9ee06f676c856cc4eb660d65e059859ed4cb0..df68cb9ffb0fa64926002c64a22e44c7c69dc02d 100644 (file)
@@ -106,9 +106,7 @@ command (string cmd)
        int const code = WEXITSTATUS (r);
 #endif
        if (code) {
-               locked_stringstream s;
-               s << "error " << code << " in " << cmd << " within " << boost::filesystem::current_path();
-               throw dcp::MiscError (s.str());
+               throw dcp::MiscError (String::compose ("error %1 in %2 within %3", code, cmd, boost::filesystem::current_path().string()));
        }
 }
 
@@ -123,9 +121,7 @@ public_key_digest (boost::filesystem::path private_key, boost::filesystem::path
        boost::filesystem::path public_name = private_key.string() + ".public";
 
        /* Create the public key from the private key */
-       locked_stringstream s;
-       s << "\"" << openssl.string() << "\" rsa -outform PEM -pubout -in " << private_key.string() << " -out " << public_name.string ();
-       command (s.str().c_str ());
+       command (String::compose("\"%1\" rsa -outform PEM -pubout -in %2 -out %3", openssl.string(), private_key.string(), public_name.string ()));
 
        /* Read in the public key from the file */
 
@@ -220,11 +216,13 @@ CertificateChain::CertificateChain (
                "/dnQualifier=" + public_key_digest ("ca.key", openssl);
 
        {
-               locked_stringstream c;
-               c << quoted_openssl
-                 << " req -new -x509 -sha256 -config ca.cnf -days 3650 -set_serial 5"
-                 << " -subj \"" << ca_subject << "\" -key ca.key -outform PEM -out ca.self-signed.pem";
-               command (c.str().c_str());
+               command (
+                       String::compose (
+                               "%1 req -new -x509 -sha256 -config ca.cnf -days 3650 -set_serial 5"
+                               " -subj \"%2\" -key ca.key -outform PEM -out ca.self-signed.pem",
+                               quoted_openssl, ca_subject
+                               )
+                       );
        }
 
        command (quoted_openssl + " genrsa -out intermediate.key 2048");
@@ -251,13 +249,14 @@ CertificateChain::CertificateChain (
                "/dnQualifier=" + public_key_digest ("intermediate.key", openssl);
 
        {
-               locked_stringstream s;
-               s << quoted_openssl
-                 << " req -new -config intermediate.cnf -days 3649 -subj \"" << inter_subject << "\" -key intermediate.key -out intermediate.csr";
-               command (s.str().c_str());
+               command (
+                       String::compose (
+                               "%1 req -new -config intermediate.cnf -days 3649 -subj \"%2\" -key intermediate.key -out intermediate.csr",
+                               quoted_openssl, inter_subject
+                               )
+                       );
        }
 
-
        command (
                quoted_openssl +
                " x509 -req -sha256 -days 3649 -CA ca.self-signed.pem -CAkey ca.key -set_serial 6"
@@ -288,9 +287,12 @@ CertificateChain::CertificateChain (
                "/dnQualifier=" + public_key_digest ("leaf.key", openssl);
 
        {
-               locked_stringstream s;
-               s << quoted_openssl << " req -new -config leaf.cnf -days 3648 -subj \"" << leaf_subject << "\" -key leaf.key -outform PEM -out leaf.csr";
-               command (s.str().c_str());
+               command (
+                       String::compose (
+                               "%1 req -new -config leaf.cnf -days 3648 -subj \"%2\" -key leaf.key -outform PEM -out leaf.csr",
+                               quoted_openssl, leaf_subject
+                               )
+                       );
        }
 
        command (
index cf7b4d6d720a25acdfadf275aadbd450f02f4070..9b586ead13eed52a71ce2856fe921fe39f0a5a11 100644 (file)
@@ -36,7 +36,7 @@
  */
 
 #include "key.h"
-#include <locked_sstream.h>
+#include "dcp_assert.h"
 #include <asdcp/AS_DCP.h>
 #include <asdcp/KM_prng.h>
 #include <asdcp/KM_util.h>
@@ -93,13 +93,17 @@ Key::operator= (Key const & other)
 string
 Key::hex () const
 {
-       locked_stringstream g;
+       DCP_ASSERT (ASDCP::KeyLen == 16);
 
-       for (unsigned int i = 0; i < ASDCP::KeyLen; ++i) {
-               g << setw(2) << setfill('0') << std::hex << static_cast<int> (_value[i]);
-       }
+       char buffer[33];
+       snprintf (
+               buffer, sizeof(buffer),
+               "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
+               _value[0], _value[1], _value[2], _value[3], _value[4], _value[5], _value[6], _value[7],
+               _value[8], _value[9], _value[10], _value[11], _value[12], _value[13], _value[14], _value[15]
+               );
 
-       return g.str ();
+       return buffer;
 }
 
 bool
index cf3229dfcb00d24fb4dd07798f7a8f6a085cb3c7..812e0f8986275182695e216085ba771d0f531fda 100644 (file)
@@ -121,16 +121,9 @@ Colour::Colour (string argb_hex)
 string
 Colour::to_argb_string () const
 {
-       locked_stringstream s;
-       s << "FF";
-       s << hex
-         << setw(2) << setfill('0') << r
-         << setw(2) << setfill('0') << g
-         << setw(2) << setfill('0') << b;
-
-       string t = s.str();
-       to_upper (t);
-       return t;
+       char buffer[9];
+       snprintf (buffer, sizeof(buffer), "FF%02X%02X%02X", r, g, b);
+       return buffer;
 }
 
 /** operator== for Colours.