From b929b048a1839c3da1cadf7f116b0f767f40267e Mon Sep 17 00:00:00 2001 From: Timo Weingärtner Date: Thu, 22 Apr 2021 23:29:10 +0200 Subject: implement separate rfc4251::(string|mpint|name_list) types --- rfc4251.C | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'rfc4251.C') 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. + * These are the conversions between an rfc4251::name_list and + * std::vector. * - * Copyright (C) 2013,2015 Timo Weingärtner + * Copyright (C) 2013,2015,2021 Timo Weingärtner * * This file is part of ssh-agent-filter. * @@ -26,34 +26,33 @@ namespace rfc4251 { -string::string (std::vector const & v) { +name_list::name_list (std::vector 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::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 () const { - std::vector 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 () const { + std::vector 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; } -- cgit v1.2.3