summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-08-11 17:17:02 +0100
committerCarl Hetherington <cth@carlh.net>2016-08-11 17:17:02 +0100
commit8c93d334d182394217cb5e77f0aa50d6ac2acf6c (patch)
tree4f678e8ecf4a8f7fb054f77dc4552ef4bfcf417d /src
parent5eb08eb89a70466b7808b327d79fa74f52f0265b (diff)
More stringstream removal.
Diffstat (limited to 'src')
-rw-r--r--src/certificate.cc48
1 files changed, 34 insertions, 14 deletions
diff --git a/src/certificate.cc b/src/certificate.cc
index 34f79754..a30b77cd 100644
--- a/src/certificate.cc
+++ b/src/certificate.cc
@@ -103,35 +103,56 @@ Certificate::read_string (string cert)
See http://comments.gmane.org/gmane.comp.encryption.openssl.user/55593
*/
- locked_stringstream s (cert);
+ list<string> lines;
string line;
- /* BEGIN */
- do {
- getline (s, line);
+ for (size_t i = 0; i < cert.length(); ++i) {
+ line += cert[i];
+ if (cert[i] == '\r' || cert[i] == '\n') {
+ boost::algorithm::trim (line);
+ lines.push_back (line);
+ line = "";
+ }
+ }
+
+ if (!line.empty()) {
boost::algorithm::trim (line);
- } while (s.good() && line != begin_certificate);
+ lines.push_back (line);
+ }
+
+ list<string>::iterator i = lines.begin ();
- if (line != begin_certificate) {
+ /* BEGIN */
+ while (i != lines.end() && *i != begin_certificate) {
+ ++i;
+ }
+
+ if (i == lines.end()) {
throw MiscError ("missing BEGIN line in certificate");
}
+ /* Skip over the BEGIN line */
+ ++i;
+
/* The base64 data */
bool got_end = false;
string base64 = "";
- while (getline (s, line)) {
- boost::algorithm::trim (line);
- if (line == end_certificate) {
+ while (i != lines.end()) {
+ if (*i == end_certificate) {
got_end = true;
break;
}
- base64 += line;
+ base64 += *i;
+ ++i;
}
if (!got_end) {
throw MiscError ("missing END line in certificate");
}
+ /* Skip over the END line */
+ ++i;
+
/* Make up the fixed version */
string fixed = begin_certificate + "\n";
@@ -156,11 +177,10 @@ Certificate::read_string (string cert)
BIO_free (bio);
/* See if there are any non-blank lines after the certificate that we read */
- line.clear ();
- while (s.good() && line.empty()) {
- getline (s, line);
+ while (i != lines.end() && i->empty()) {
+ ++i;
}
- return (s.good() && !line.empty());
+ return i != lines.end();
}
/** Destructor */