Merge pull request #2481 from pobregat0/beast-base64

use base64 from boost::beast for basic authorization
This commit is contained in:
orignal
2026-08-15 21:03:56 -04:00
committed by GitHub
4 changed files with 6 additions and 14 deletions
+1 -1
View File
@@ -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;
}
-11
View File
@@ -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;
}
/*
*
-1
View File
@@ -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
+5 -1
View File
@@ -11,6 +11,7 @@
#include <stdio.h>
#include <ctime>
#include <charconv>
#include <boost/beast/core/detail/base64.hpp>
#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