From ab2842d6f28680b1cac18d5ff6b70b395d1ffb65 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sun, 2 Oct 2016 14:14:44 -0400 Subject: Have cli cert_info parse multiple certs from file --- src/cli/x509.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/cli/x509.cpp') diff --git a/src/cli/x509.cpp b/src/cli/x509.cpp index 90979aa53..e65398439 100644 --- a/src/cli/x509.cpp +++ b/src/cli/x509.cpp @@ -71,12 +71,34 @@ BOTAN_REGISTER_COMMAND("sign_cert", Sign_Cert); class Cert_Info final : public Command { public: - Cert_Info() : Command("cert_info file") {} + Cert_Info() : Command("cert_info --ber file") {} void go() override { - Botan::X509_Certificate cert(get_arg("file")); - output() << cert.to_string() << "\n"; + Botan::DataSource_Stream in(get_arg("file"), flag_set("ber")); + + while(!in.end_of_data()) + { + try + { + Botan::X509_Certificate cert(in); + + try + { + output() << cert.to_string() << std::endl; + } + catch(Botan::Exception& e) + { + // to_string failed - report the exception and continue + output() << "X509_Certificate::to_string failed: " << e.what() << "\n"; + } + } + catch(Botan::Exception& e) + { + if(!in.end_of_data()) + output() << "X509_Certificate parsing failed " << e.what() << "\n"; + } + } } }; -- cgit v1.2.3