diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index d7255508..3ee1517d 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -1275,7 +1275,7 @@ namespace http { auto provided = req.GetHeader ("Authorization"); if (provided.length () > 0) { - std::string expected = "Basic " + i2p::data::ToBase64Standard (user + ":" + pass); + std::string expected = i2p::http::CreateBasicAuthorizationString (user, pass); if (expected == provided) return true; } diff --git a/libi2pd/Base.cpp b/libi2pd/Base.cpp index 9817f2d7..9b300982 100644 --- a/libi2pd/Base.cpp +++ b/libi2pd/Base.cpp @@ -201,17 +201,6 @@ namespace data return outCount; } - std::string ToBase64Standard (std::string_view in) - { - auto str = ByteStreamToBase64 ((const uint8_t *)in.data (), in.length ()); - // replace '-' by '+' and '~' by '/' - for (auto& ch: str) - if (ch == '-') - ch = '+'; - else if (ch == '~') - ch = '/'; - return str; - } /* * diff --git a/libi2pd/Base.h b/libi2pd/Base.h index 945dc8b3..34531067 100644 --- a/libi2pd/Base.h +++ b/libi2pd/Base.h @@ -45,7 +45,6 @@ namespace data return 4 * d.quot; } - std::string ToBase64Standard (std::string_view in); // using standard table, for Proxy-Authorization } // data } // i2p diff --git a/libi2pd/HTTP.cpp b/libi2pd/HTTP.cpp index 5839dd25..03321cf5 100644 --- a/libi2pd/HTTP.cpp +++ b/libi2pd/HTTP.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "util.h" #include "Base.h" #include "HTTP.h" @@ -625,7 +626,10 @@ namespace http std::string CreateBasicAuthorizationString (const std::string& user, const std::string& pass) { if (user.empty () && pass.empty ()) return ""; - return "Basic " + i2p::data::ToBase64Standard (user + ":" + pass); + auto credentials = user + ":" + pass; + std::string encoded (boost::beast::detail::base64::encoded_size (credentials.length ()), 0); + encoded.resize (boost::beast::detail::base64::encode (encoded.data (), credentials.data (), credentials.length ())); + return "Basic " + encoded; } } // http