mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-20 16:26:39 +01:00
ByteStreamToBase64 always returns std::string
This commit is contained in:
parent
8e6b9370d0
commit
bbf5c1655a
3 changed files with 2 additions and 82 deletions
|
@ -1419,13 +1419,11 @@ namespace http {
|
||||||
{
|
{
|
||||||
auto signatureLen = dest->GetIdentity ()->GetSignatureLen ();
|
auto signatureLen = dest->GetIdentity ()->GetSignatureLen ();
|
||||||
uint8_t * signature = new uint8_t[signatureLen];
|
uint8_t * signature = new uint8_t[signatureLen];
|
||||||
char * sig = new char[signatureLen*2];
|
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
|
|
||||||
out << name << "=" << dest->GetIdentity ()->ToBase64 ();
|
out << name << "=" << dest->GetIdentity ()->ToBase64 ();
|
||||||
dest->Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
|
dest->Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
|
||||||
auto len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2);
|
auto sig = i2p::data::ByteStreamToBase64 (signature, signatureLen);
|
||||||
sig[len] = 0;
|
|
||||||
out << "#!sig=" << sig;
|
out << "#!sig=" << sig;
|
||||||
s << "<b>" << tr("SUCCESS") << "</b>:<br>\r\n<form action=\"http://shx5vqsw7usdaunyzr2qmes2fq37oumybpudrd4jjj4e4vk4uusa.b32.i2p/add\" method=\"post\" rel=\"noreferrer\" target=\"_blank\">\r\n"
|
s << "<b>" << tr("SUCCESS") << "</b>:<br>\r\n<form action=\"http://shx5vqsw7usdaunyzr2qmes2fq37oumybpudrd4jjj4e4vk4uusa.b32.i2p/add\" method=\"post\" rel=\"noreferrer\" target=\"_blank\">\r\n"
|
||||||
"<textarea readonly name=\"record\" cols=\"80\" rows=\"10\">" << out.str () << "</textarea>\r\n<br>\r\n<br>\r\n"
|
"<textarea readonly name=\"record\" cols=\"80\" rows=\"10\">" << out.str () << "</textarea>\r\n<br>\r\n<br>\r\n"
|
||||||
|
@ -1434,7 +1432,6 @@ namespace http {
|
||||||
"<input type=\"submit\" value=\"" << tr("Submit") << "\">\r\n"
|
"<input type=\"submit\" value=\"" << tr("Submit") << "\">\r\n"
|
||||||
"</form>\r\n<br>\r\n";
|
"</form>\r\n<br>\r\n";
|
||||||
delete[] signature;
|
delete[] signature;
|
||||||
delete[] sig;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
s << "<b>" << tr("ERROR") << "</b>: " << tr("Domain can't end with .b32.i2p") << "\r\n<br>\r\n<br>\r\n";
|
s << "<b>" << tr("ERROR") << "</b>: " << tr("Domain can't end with .b32.i2p") << "\r\n<br>\r\n<br>\r\n";
|
||||||
|
|
|
@ -58,15 +58,13 @@ namespace data
|
||||||
/*
|
/*
|
||||||
* Reverse Substitution Table (built in run time)
|
* Reverse Substitution Table (built in run time)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char iT64[256];
|
static char iT64[256];
|
||||||
static int isFirstTime = 1;
|
static int isFirstTime = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Padding
|
* Padding
|
||||||
*/
|
*/
|
||||||
|
static constexpr char P64 = '=';
|
||||||
static char P64 = '=';
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -76,80 +74,6 @@ namespace data
|
||||||
* Converts binary encoded data to BASE64 format.
|
* Converts binary encoded data to BASE64 format.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
size_t ByteStreamToBase64 ( // Number of bytes in the encoded buffer
|
|
||||||
const uint8_t * InBuffer, // Input buffer, binary data
|
|
||||||
size_t InCount, // Number of bytes in the input buffer
|
|
||||||
char * OutBuffer, // output buffer
|
|
||||||
size_t len // length of output buffer
|
|
||||||
)
|
|
||||||
{
|
|
||||||
unsigned char * ps;
|
|
||||||
unsigned char * pd;
|
|
||||||
unsigned char acc_1;
|
|
||||||
unsigned char acc_2;
|
|
||||||
int i;
|
|
||||||
int n;
|
|
||||||
int m;
|
|
||||||
size_t outCount;
|
|
||||||
|
|
||||||
ps = (unsigned char *)InBuffer;
|
|
||||||
n = InCount / 3;
|
|
||||||
m = InCount % 3;
|
|
||||||
if (!m)
|
|
||||||
outCount = 4 * n;
|
|
||||||
else
|
|
||||||
outCount = 4 * (n + 1);
|
|
||||||
|
|
||||||
if (outCount > len) return 0;
|
|
||||||
|
|
||||||
pd = (unsigned char *)OutBuffer;
|
|
||||||
for ( i = 0; i < n; i++ )
|
|
||||||
{
|
|
||||||
acc_1 = *ps++;
|
|
||||||
acc_2 = (acc_1 << 4) & 0x30;
|
|
||||||
acc_1 >>= 2; // base64 digit #1
|
|
||||||
*pd++ = T64[acc_1];
|
|
||||||
acc_1 = *ps++;
|
|
||||||
acc_2 |= acc_1 >> 4; // base64 digit #2
|
|
||||||
*pd++ = T64[acc_2];
|
|
||||||
acc_1 &= 0x0f;
|
|
||||||
acc_1 <<= 2;
|
|
||||||
acc_2 = *ps++;
|
|
||||||
acc_1 |= acc_2 >> 6; // base64 digit #3
|
|
||||||
*pd++ = T64[acc_1];
|
|
||||||
acc_2 &= 0x3f; // base64 digit #4
|
|
||||||
*pd++ = T64[acc_2];
|
|
||||||
}
|
|
||||||
if ( m == 1 )
|
|
||||||
{
|
|
||||||
acc_1 = *ps++;
|
|
||||||
acc_2 = (acc_1 << 4) & 0x3f; // base64 digit #2
|
|
||||||
acc_1 >>= 2; // base64 digit #1
|
|
||||||
*pd++ = T64[acc_1];
|
|
||||||
*pd++ = T64[acc_2];
|
|
||||||
*pd++ = P64;
|
|
||||||
*pd++ = P64;
|
|
||||||
|
|
||||||
}
|
|
||||||
else if ( m == 2 )
|
|
||||||
{
|
|
||||||
acc_1 = *ps++;
|
|
||||||
acc_2 = (acc_1 << 4) & 0x3f;
|
|
||||||
acc_1 >>= 2; // base64 digit #1
|
|
||||||
*pd++ = T64[acc_1];
|
|
||||||
acc_1 = *ps++;
|
|
||||||
acc_2 |= acc_1 >> 4; // base64 digit #2
|
|
||||||
*pd++ = T64[acc_2];
|
|
||||||
acc_1 &= 0x0f;
|
|
||||||
acc_1 <<= 2; // base64 digit #3
|
|
||||||
*pd++ = T64[acc_1];
|
|
||||||
*pd++ = P64;
|
|
||||||
}
|
|
||||||
|
|
||||||
return outCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ByteStreamToBase64 (// base64 encoded string
|
std::string ByteStreamToBase64 (// base64 encoded string
|
||||||
const uint8_t * InBuffer, // Input buffer, binary data
|
const uint8_t * InBuffer, // Input buffer, binary data
|
||||||
size_t InCount // Number of bytes in the input buffer
|
size_t InCount // Number of bytes in the input buffer
|
||||||
|
|
|
@ -18,7 +18,6 @@ namespace i2p
|
||||||
{
|
{
|
||||||
namespace data
|
namespace data
|
||||||
{
|
{
|
||||||
size_t ByteStreamToBase64 (const uint8_t * InBuffer, size_t InCount, char * OutBuffer, size_t len); // called from SAM TODO: rewrite
|
|
||||||
std::string ByteStreamToBase64 (const uint8_t * InBuffer, size_t InCount);
|
std::string ByteStreamToBase64 (const uint8_t * InBuffer, size_t InCount);
|
||||||
size_t Base64ToByteStream (std::string_view base64Str, uint8_t * OutBuffer, size_t len);
|
size_t Base64ToByteStream (std::string_view base64Str, uint8_t * OutBuffer, size_t len);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue