From 14ce6b8765f47db4f2cc4ab4d2eff64486792e62 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 25 Aug 2016 14:00:33 +0100 Subject: Allow reading of certificate chains from strings. This also makes the Certificate constructor throw if it finds extra stuff after a certificate it is loading. --- src/certificate_chain.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/certificate_chain.cc') diff --git a/src/certificate_chain.cc b/src/certificate_chain.cc index df68cb9f..ac01d860 100644 --- a/src/certificate_chain.cc +++ b/src/certificate_chain.cc @@ -55,6 +55,7 @@ #include #include #include +#include using std::string; using std::ofstream; @@ -312,6 +313,24 @@ CertificateChain::CertificateChain ( boost::filesystem::remove_all (directory); } +CertificateChain::CertificateChain (string s) +{ + while (true) { + try { + Certificate c; + s = c.read_string (s); + _certificates.push_back (c); + } catch (MiscError& e) { + /* Failed to read a certificate, just stop */ + break; + } + } + + if (!attempt_reorder ()) { + throw MiscError ("could not find certificate chain order"); + } +} + /** @return Root certificate */ Certificate CertificateChain::root () const -- cgit v1.2.3