Remove unused base36
This commit is contained in:
parent
579914c84d
commit
d2b7354c24
4 changed files with 0 additions and 120 deletions
|
|
@ -254,7 +254,6 @@ set( fc_sources
|
|||
src/crypto/aes.cpp
|
||||
src/crypto/crc.cpp
|
||||
src/crypto/city.cpp
|
||||
src/crypto/base36.cpp
|
||||
src/crypto/base58.cpp
|
||||
src/crypto/base64.cpp
|
||||
src/crypto/bigint.cpp
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
std::vector<char> from_base36( const std::string& b36 );
|
||||
std::string to_base36( const std::vector<char>& vec );
|
||||
std::string to_base36( const char* data, size_t len );
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
#include <fc/crypto/bigint.hpp>
|
||||
#include <fc/io/sstream.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
std::string to_base36( const char* data, size_t len )
|
||||
{
|
||||
if( len == 0 ) return std::string();
|
||||
|
||||
const char* src = data;
|
||||
int src_len = len;
|
||||
std::unique_ptr<char[]> buffer(new char[len+1]);
|
||||
if (*data & 0x80) {
|
||||
buffer[0] = 0;
|
||||
memcpy( buffer.get() + 1, data, len );
|
||||
src = buffer.get();
|
||||
src_len++;
|
||||
}
|
||||
fc::bigint value( src, src_len );
|
||||
|
||||
auto base36 = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
std::vector<char> out( static_cast<size_t>(len * 1.6) + 2 );
|
||||
int pos = out.size() - 1;
|
||||
out[pos] = '\0';
|
||||
fc::bigint _36(36);
|
||||
do {
|
||||
if( value ) {
|
||||
--pos;
|
||||
out[pos] = base36[(value % _36).to_int64()];
|
||||
}
|
||||
} while (value /= _36);
|
||||
while (len-- > 0 && *data++ == 0) {
|
||||
out[--pos] = '0';
|
||||
}
|
||||
return &out[pos]; //std::string( &out[pos], out.size() - pos);
|
||||
}
|
||||
|
||||
std::string to_base36( const std::vector<char>& vec )
|
||||
{
|
||||
return to_base36( (const char*)vec.data(), vec.size() );
|
||||
}
|
||||
|
||||
std::vector<char> from_base36( const std::string& b36 )
|
||||
{
|
||||
if ( b36.empty() ) {
|
||||
std::vector<char> empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
fc::bigint value;
|
||||
|
||||
fc::bigint pos = 0;
|
||||
fc::bigint _36(36);
|
||||
for( auto itr = b36.rbegin(); itr != b36.rend(); ++itr )
|
||||
{
|
||||
if( *itr >= '0' && *itr <= '9' )
|
||||
value = value + _36.exp(pos) * fc::bigint(*itr - '0');
|
||||
else if( *itr >= 'a' && *itr <= 'z' )
|
||||
value = value + (_36.exp(pos) * fc::bigint(10+*itr - 'a'));
|
||||
else if( *itr >= 'A' && *itr <= 'Z' )
|
||||
value = value + (_36.exp(pos) * fc::bigint(10+*itr - 'A'));
|
||||
else
|
||||
{
|
||||
wlog("unknown '${char}'", ("char",std::string(&*itr,1)) );
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
|
||||
std::vector<char> bytes = value;
|
||||
int leading_zeros = 0, len = bytes.size();
|
||||
const char *in = b36.c_str();
|
||||
while (*in++ == '0') { leading_zeros++; }
|
||||
char* first = bytes.data();
|
||||
while (len > 0 && *first == 0) { first++; len--; }
|
||||
std::vector<char> result;
|
||||
result.resize(leading_zeros + len, 0);
|
||||
if (len)
|
||||
{
|
||||
memcpy( result.data() + leading_zeros, first, len );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <fc/crypto/hex.hpp>
|
||||
#include <fc/crypto/base36.hpp>
|
||||
#include <fc/crypto/base58.hpp>
|
||||
#include <fc/crypto/base64.hpp>
|
||||
#include <fc/exception/exception.hpp>
|
||||
|
|
@ -43,29 +42,6 @@ BOOST_AUTO_TEST_CASE(hex_test)
|
|||
}
|
||||
|
||||
|
||||
static void test_36( const std::string& test, const std::string& expected )
|
||||
{
|
||||
std::vector<char> vec( test.begin(), test.end() );
|
||||
std::string enc1 = fc::to_base36( vec );
|
||||
std::string enc2 = fc::to_base36( test.c_str(), test.size() );
|
||||
BOOST_CHECK_EQUAL( enc1, enc2 );
|
||||
BOOST_CHECK_EQUAL( expected, enc2 );
|
||||
|
||||
std::vector<char> dec = fc::from_base36( enc1 );
|
||||
BOOST_CHECK_EQUAL( vec.size(), dec.size() );
|
||||
BOOST_CHECK( vec == dec );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(base36_test)
|
||||
{
|
||||
test_36( TEST1, "" );
|
||||
test_36( TEST2, "01o35" );
|
||||
test_36( TEST3, "l4ksdleyi5pnl0un5raue268ptj43dwjwmz15ie2" );
|
||||
test_36( TEST4, "2rrrvpb7y4" );
|
||||
test_36( TEST5, "000" );
|
||||
}
|
||||
|
||||
|
||||
static void test_58( const std::string& test, const std::string& expected )
|
||||
{
|
||||
std::vector<char> vec( test.begin(), test.end() );
|
||||
|
|
|
|||
Loading…
Reference in a new issue