aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Weingärtner <timo@tiwe.de>2013-07-02 01:32:13 +0200
committerTimo Weingärtner <timo@tiwe.de>2013-07-19 21:37:44 +0200
commit9e8adf8438d3ca343a9161725e6f0ff68e44832c (patch)
tree7f1fca454337f28e160a0f565c5d9cb4d40161e2
parent6ba5bcba015ddcda1b81bd83a3dface81fdee52c (diff)
downloadssh-agent-filter-9e8adf8438d3ca343a9161725e6f0ff68e44832c.tar.gz
rfc4251string: implement name-list (as vector<string>)
-rw-r--r--rfc4251.h31
1 files changed, 30 insertions, 1 deletions
diff --git a/rfc4251.h b/rfc4251.h
index 3365064..3f442f1 100644
--- a/rfc4251.h
+++ b/rfc4251.h
@@ -5,7 +5,7 @@
* rfc4251bool bool
* rfc4251uint32 uint32
* rfc4251uint64 uint64
- * rfc4251string string, incl. mpint and (without splitting) name-list
+ * rfc4251string string, incl. mpint and name-list
*
* those structs contain the objects in their RFC 4251 representation,
* conversions are provided via constructors and cast operators
@@ -168,6 +168,7 @@ struct rfc4251string {
inline explicit rfc4251string (char const *);
inline explicit rfc4251string (char const *, size_t);
inline explicit rfc4251string (std::string const & s) : rfc4251string{s.data(), s.size()} {}
+ inline explicit rfc4251string (std::vector<std::string> const &);
inline explicit rfc4251string (mpz_srcptr);
inline explicit rfc4251string (mpz_class const & x) : rfc4251string{x.get_mpz_t()} {}
@@ -175,6 +176,7 @@ struct rfc4251string {
rfc4251string & operator= (rfc4251string &&) = default;
inline operator std::string () const;
+ inline operator std::vector<std::string> () const;
inline operator mpz_class () const;
};
@@ -187,6 +189,16 @@ inline rfc4251string::rfc4251string (char const * s, size_t l) {
value.insert(value.end(), s, s + l);
}
+inline rfc4251string::rfc4251string (std::vector<std::string> const & v) {
+ if (v.size()) {
+ value.assign(v.begin()->data(), v.begin()->data() + v.begin()->size());
+ for (auto it = v.begin() + 1; it != v.end(); ++it) {
+ value.push_back(',');
+ value.insert(value.end(), it->data(), it->data() + it->size());
+ }
+ }
+}
+
inline rfc4251string::rfc4251string (mpz_srcptr x) {
if (mpz_sgn(x) == 0) {
} else if (mpz_sgn(x) == 1) {
@@ -215,6 +227,23 @@ inline rfc4251string::operator std::string () const {
return std::string(value.begin(), value.end());
}
+inline rfc4251string::operator std::vector<std::string> () const {
+ std::vector<std::string> ret;
+ auto name_start = value.begin();
+ if (name_start != value.end())
+ for (auto it = name_start; ; ++it) {
+ if (it == value.end() or *it == ',') {
+ if (it == name_start)
+ throw std::length_error("name of zero length");
+ ret.emplace_back(name_start, it);
+ name_start = it + 1;
+ }
+ if (it == value.end())
+ break;
+ }
+ return ret;
+}
+
inline rfc4251string::operator mpz_class () const {
mpz_class ret;
mpz_import(ret.get_mpz_t(), value.size(), 1, 1, 1, 0, value.data());