From 8f675da301eafe79897f3ad67ff5450fcc397f78 Mon Sep 17 00:00:00 2001 From: Timo Weingärtner Date: Mon, 31 Aug 2015 20:22:37 +0200 Subject: move rfc4251 types into their own namespace --- rfc4251_gmp.C | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'rfc4251_gmp.C') diff --git a/rfc4251_gmp.C b/rfc4251_gmp.C index db46429..fe1f770 100644 --- a/rfc4251_gmp.C +++ b/rfc4251_gmp.C @@ -1,5 +1,5 @@ /* - * rfc4251_gmp.C -- implements mpint/gmp conversions for rfc4251string + * rfc4251_gmp.C -- implements mpint/gmp conversions for rfc4251::string * * these functions need linking against libgmp * @@ -23,7 +23,9 @@ #include "rfc4251.H" -rfc4251string::rfc4251string (mpz_srcptr x) { +namespace rfc4251 { + +string::string (mpz_srcptr x) { if (mpz_sgn(x) == 0) return; @@ -32,7 +34,7 @@ rfc4251string::rfc4251string (mpz_srcptr x) { size_t bytes{(bits + 7) / 8}; size_t extrabyte{(bits % 8) == 0}; // need extra byte if MSB is 1 to keep it non-negative if (bytes + extrabyte > std::numeric_limits::max()) - throw std::length_error{"32-bit limit for rfc4251string exceeded"}; + throw std::length_error{"32-bit limit for rfc4251::string exceeded"}; value.resize(bytes + extrabyte); value[0] = 0; mpz_export(value.data() + extrabyte, nullptr, 1, 1, 1, 0, x); @@ -49,7 +51,7 @@ rfc4251string::rfc4251string (mpz_srcptr x) { } } -rfc4251string::operator mpz_class () const { +string::operator mpz_class () const { mpz_class ret; mpz_import(ret.get_mpz_t(), value.size(), 1, 1, 1, 0, value.data()); if (mpz_sizeinbase(ret.get_mpz_t(), 2) == value.size() * 8) { // negative @@ -59,3 +61,5 @@ rfc4251string::operator mpz_class () const { } return ret; } + +} -- cgit v1.2.3