diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-08-25 14:00:33 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-08-25 14:00:33 +0100 |
| commit | 14ce6b8765f47db4f2cc4ab4d2eff64486792e62 (patch) | |
| tree | 7274c9d4b633964c4f54bbe67ba6bd2ca0dfc0a8 /src/certificate_chain.cc | |
| parent | 04def4c193777d7a6cbd306d0a3ba3944335e444 (diff) | |
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.
Diffstat (limited to 'src/certificate_chain.cc')
| -rw-r--r-- | src/certificate_chain.cc | 19 |
1 files changed, 19 insertions, 0 deletions
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 <boost/algorithm/string.hpp> #include <boost/foreach.hpp> #include <fstream> +#include <iostream> 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 |
