aboutsummaryrefslogtreecommitdiff
path: root/rfc4251.C
diff options
context:
space:
mode:
authorTimo Weingärtner <timo@tiwe.de>2021-04-22 23:29:10 +0200
committerTimo Weingärtner <timo@tiwe.de>2026-03-07 22:25:16 +0100
commitb929b048a1839c3da1cadf7f116b0f767f40267e (patch)
tree2ccd826673e1113b4eade64b2e04b20722471e91 /rfc4251.C
parent9d25142d506d1559b134d465ff0434ffbde7dca8 (diff)
downloadssh-agent-filter-b929b048a1839c3da1cadf7f116b0f767f40267e.tar.gz
implement separate rfc4251::(string|mpint|name_list) types
Diffstat (limited to 'rfc4251.C')
-rw-r--r--rfc4251.C41
1 files changed, 20 insertions, 21 deletions
diff --git a/rfc4251.C b/rfc4251.C
index 5ea0a93..05ef8b8 100644
--- a/rfc4251.C
+++ b/rfc4251.C
@@ -1,10 +1,10 @@
/*
* rfc4251.C -- support for name-list type from RFC 4251, section 5
*
- * These are the conversions between an rfc4251::string containing a name-list
- * and vector<string>.
+ * These are the conversions between an rfc4251::name_list and
+ * std::vector<std::string>.
*
- * Copyright (C) 2013,2015 Timo Weingärtner <timo@tiwe.de>
+ * Copyright (C) 2013,2015,2021 Timo Weingärtner <timo@tiwe.de>
*
* This file is part of ssh-agent-filter.
*
@@ -26,34 +26,33 @@
namespace rfc4251 {
-string::string (std::vector<std::string> const & v) {
+name_list::name_list (std::vector<std::string> const & v) {
for (auto it = v.begin(); it != v.end();) {
if (it->size() == 0)
throw std::length_error{"name of zero length"};
- if (value.size() + it->size() > std::numeric_limits<uint32_t>::max())
- throw std::length_error{"32-bit limit for rfc4251::string exceeded"};
- value.insert(value.end(), it->data(), it->data() + it->size());
+ check_length_against_limit(buf.size() + it->size());
+ buf.insert(buf.end(), it->data(), it->data() + it->size());
++it;
if (it == v.end())
break;
- value.push_back(',');
+ buf.push_back(',');
}
}
-string::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;
+name_list::operator std::vector<std::string> () const {
+ std::vector<std::string> ret{};
+ if (buf.empty()) return ret;
+ auto name_start = buf.begin();
+ for (auto it = name_start; ; ++it) {
+ if (it == buf.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 == buf.end())
+ break;
+ }
return ret;
}