57 static void from_istream(std::istream &in,
const std::string &title, CertList *cert_list, CRLList *crl_list)
59 static const char cert_start[] =
"-----BEGIN CERTIFICATE-----";
60 static const char cert_end[] =
"-----END CERTIFICATE-----";
61 static const char crl_start[] =
"-----BEGIN X509 CRL-----";
62 static const char crl_end[] =
"-----END X509 CRL-----";
72 int state = S_OUTSIDE;
73 std::string item =
"";
76 while (std::getline(in, line))
80 if (state == S_OUTSIDE)
82 if (line == cert_start)
85 OPENVPN_THROW(parse_cert_crl_error, title <<
":" << line_num <<
" : not expecting a CERT");
88 else if (line == crl_start)
91 OPENVPN_THROW(parse_cert_crl_error, title <<
":" << line_num <<
" : not expecting a CRL");
95 if (state != S_OUTSIDE)
100 if (state == S_IN_CERT && line == cert_end)
104 cert_list->emplace_back(item, title);
106 catch (
const std::exception &e)
108 OPENVPN_THROW(parse_cert_crl_error, title <<
":" << line_num <<
" : error parsing CERT: " << e.what());
113 if (state == S_IN_CRL && line == crl_end)
117 crl_list->emplace_back(item);
119 catch (
const std::exception &e)
121 OPENVPN_THROW(parse_cert_crl_error, title <<
":" << line_num <<
" : error parsing CRL: " << e.what());
127 if (state != S_OUTSIDE)
128 OPENVPN_THROW(parse_cert_crl_error, title <<
" : CERT/CRL content ended unexpectedly without END marker");