diff options
Diffstat (limited to 'rfc4251.C')
| -rw-r--r-- | rfc4251.C | 41 |
1 files changed, 20 insertions, 21 deletions
@@ -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; } |
