Browse Source

Move base64 to util/

pull/239/head
EinMByte 9 years ago
parent
commit
89d3d17b28
  1. 4
      AddressBook.cpp
  2. 2
      AddressBook.h
  3. 1
      Daemon.cpp
  4. 2
      HTTPServer.cpp
  5. 1
      I2NPProtocol.cpp
  6. 1
      I2PTunnel.cpp
  7. 10
      Identity.cpp
  8. 10
      Identity.h
  9. 10
      NetDb.cpp
  10. 4
      Profiling.cpp
  11. 10
      RouterInfo.cpp
  12. 6
      SAM.cpp
  13. 4
      filelist.mk
  14. 4
      transport/NTCPSession.cpp
  15. 2
      transport/SSU.cpp
  16. 2
      transport/SSUData.cpp
  17. 2
      transport/SSUSession.cpp
  18. 2
      util/base64.cpp
  19. 2
      util/base64.h

4
AddressBook.cpp

@ -8,7 +8,7 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <cryptopp/osrng.h> #include <cryptopp/osrng.h>
#include "base64.h" #include "util/base64.h"
#include "util/util.h" #include "util/util.h"
#include "Identity.h" #include "Identity.h"
#include "Log.h" #include "Log.h"
@ -215,7 +215,7 @@ namespace client
auto pos = address.find(".b32.i2p"); auto pos = address.find(".b32.i2p");
if (pos != std::string::npos) if (pos != std::string::npos)
{ {
Base32ToByteStream (address.c_str(), pos, ident, 32); i2p::util::Base32ToByteStream (address.c_str(), pos, ident, 32);
return true; return true;
} }
else else

2
AddressBook.h

@ -8,7 +8,7 @@
#include <iostream> #include <iostream>
#include <mutex> #include <mutex>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "base64.h" #include "util/base64.h"
#include "util/util.h" #include "util/util.h"
#include "Identity.h" #include "Identity.h"
#include "Log.h" #include "Log.h"

1
Daemon.cpp

@ -3,7 +3,6 @@
#include "Daemon.h" #include "Daemon.h"
#include "Log.h" #include "Log.h"
#include "base64.h"
#include "version.h" #include "version.h"
#include "transport/Transports.h" #include "transport/Transports.h"
#include "transport/NTCPSession.h" #include "transport/NTCPSession.h"

2
HTTPServer.cpp

@ -1,7 +1,7 @@
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include "base64.h" #include "util/base64.h"
#include "Log.h" #include "Log.h"
#include "Tunnel.h" #include "Tunnel.h"
#include "TransitTunnel.h" #include "TransitTunnel.h"

1
I2NPProtocol.cpp

@ -7,7 +7,6 @@
#include "RouterContext.h" #include "RouterContext.h"
#include "NetDb.h" #include "NetDb.h"
#include "Tunnel.h" #include "Tunnel.h"
#include "base64.h"
#include "transport/Transports.h" #include "transport/Transports.h"
#include "Garlic.h" #include "Garlic.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"

1
I2PTunnel.cpp

@ -1,5 +1,4 @@
#include <cassert> #include <cassert>
#include "base64.h"
#include "Log.h" #include "Log.h"
#include "Destination.h" #include "Destination.h"
#include "ClientContext.h" #include "ClientContext.h"

10
Identity.cpp

@ -3,7 +3,7 @@
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include <cryptopp/osrng.h> #include <cryptopp/osrng.h>
#include <cryptopp/dsa.h> #include <cryptopp/dsa.h>
#include "base64.h" #include "util/base64.h"
#include "CryptoConst.h" #include "CryptoConst.h"
#include "ElGamal.h" #include "ElGamal.h"
#include "RouterContext.h" #include "RouterContext.h"
@ -237,7 +237,7 @@ namespace data
size_t IdentityEx::FromBase64(const std::string& s) size_t IdentityEx::FromBase64(const std::string& s)
{ {
uint8_t buf[1024]; uint8_t buf[1024];
auto len = Base64ToByteStream (s.c_str(), s.length(), buf, 1024); auto len = i2p::util::Base64ToByteStream (s.c_str(), s.length(), buf, 1024);
return FromBuffer (buf, len); return FromBuffer (buf, len);
} }
@ -246,7 +246,7 @@ namespace data
uint8_t buf[1024]; uint8_t buf[1024];
char str[1536]; char str[1536];
size_t l = ToBuffer (buf, 1024); size_t l = ToBuffer (buf, 1024);
size_t l1 = i2p::data::ByteStreamToBase64 (buf, l, str, 1536); size_t l1 = i2p::util::ByteStreamToBase64 (buf, l, str, 1536);
str[l1] = 0; str[l1] = 0;
return std::string (str); return std::string (str);
} }
@ -420,7 +420,7 @@ namespace data
size_t PrivateKeys::FromBase64(const std::string& s) size_t PrivateKeys::FromBase64(const std::string& s)
{ {
uint8_t * buf = new uint8_t[s.length ()]; uint8_t * buf = new uint8_t[s.length ()];
size_t l = i2p::data::Base64ToByteStream (s.c_str (), s.length (), buf, s.length ()); size_t l = i2p::util::Base64ToByteStream (s.c_str (), s.length (), buf, s.length ());
size_t ret = FromBuffer (buf, l); size_t ret = FromBuffer (buf, l);
delete[] buf; delete[] buf;
return ret; return ret;
@ -431,7 +431,7 @@ namespace data
uint8_t * buf = new uint8_t[GetFullLen ()]; uint8_t * buf = new uint8_t[GetFullLen ()];
char * str = new char[GetFullLen ()*2]; char * str = new char[GetFullLen ()*2];
size_t l = ToBuffer (buf, GetFullLen ()); size_t l = ToBuffer (buf, GetFullLen ());
size_t l1 = i2p::data::ByteStreamToBase64 (buf, l, str, GetFullLen ()*2); size_t l1 = i2p::util::ByteStreamToBase64 (buf, l, str, GetFullLen ()*2);
str[l1] = 0; str[l1] = 0;
delete[] buf; delete[] buf;
std::string ret(str); std::string ret(str);

10
Identity.h

@ -5,7 +5,7 @@
#include <string.h> #include <string.h>
#include <string> #include <string>
#include <memory> #include <memory>
#include "base64.h" #include "util/base64.h"
#include "ElGamal.h" #include "ElGamal.h"
#include "Signature.h" #include "Signature.h"
@ -51,7 +51,7 @@ namespace data
std::string ToBase64 () const std::string ToBase64 () const
{ {
char str[sz*2]; char str[sz*2];
int l = i2p::data::ByteStreamToBase64 (m_Buf, sz, str, sz*2); int l = i2p::util::ByteStreamToBase64 (m_Buf, sz, str, sz*2);
str[l] = 0; str[l] = 0;
return std::string (str); return std::string (str);
} }
@ -59,19 +59,19 @@ namespace data
std::string ToBase32 () const std::string ToBase32 () const
{ {
char str[sz*2]; char str[sz*2];
int l = i2p::data::ByteStreamToBase32 (m_Buf, sz, str, sz*2); int l = i2p::util::ByteStreamToBase32 (m_Buf, sz, str, sz*2);
str[l] = 0; str[l] = 0;
return std::string (str); return std::string (str);
} }
void FromBase32 (const std::string& s) void FromBase32 (const std::string& s)
{ {
i2p::data::Base32ToByteStream (s.c_str (), s.length (), m_Buf, sz); i2p::util::Base32ToByteStream (s.c_str (), s.length (), m_Buf, sz);
} }
void FromBase64 (const std::string& s) void FromBase64 (const std::string& s)
{ {
i2p::data::Base64ToByteStream (s.c_str (), s.length (), m_Buf, sz); i2p::util::Base64ToByteStream (s.c_str (), s.length (), m_Buf, sz);
} }
private: private:

10
NetDb.cpp

@ -4,7 +4,7 @@
#include <vector> #include <vector>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <cryptopp/gzip.h> #include <cryptopp/gzip.h>
#include "base64.h" #include "util/base64.h"
#include "Log.h" #include "Log.h"
#include "util/Timestamp.h" #include "util/Timestamp.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
@ -263,7 +263,7 @@ namespace data
} }
// list of chars might appear in base64 string // list of chars might appear in base64 string
const char * chars = GetBase64SubstitutionTable (); // 64 bytes const char * chars = i2p::util::GetBase64SubstitutionTable (); // 64 bytes
boost::filesystem::path suffix; boost::filesystem::path suffix;
for (int i = 0; i < 64; i++) for (int i = 0; i < 64; i++)
{ {
@ -544,7 +544,7 @@ namespace data
{ {
const uint8_t * buf = msg->GetPayload (); const uint8_t * buf = msg->GetPayload ();
char key[48]; char key[48];
int l = i2p::data::ByteStreamToBase64 (buf, 32, key, 48); int l = i2p::util::ByteStreamToBase64 (buf, 32, key, 48);
key[l] = 0; key[l] = 0;
int num = buf[32]; // num int num = buf[32]; // num
LogPrint ("DatabaseSearchReply for ", key, " num=", num); LogPrint ("DatabaseSearchReply for ", key, " num=", num);
@ -613,7 +613,7 @@ namespace data
{ {
const uint8_t * router = buf + 33 + i*32; const uint8_t * router = buf + 33 + i*32;
char peerHash[48]; char peerHash[48];
int l1 = i2p::data::ByteStreamToBase64 (router, 32, peerHash, 48); int l1 = i2p::util::ByteStreamToBase64 (router, 32, peerHash, 48);
peerHash[l1] = 0; peerHash[l1] = 0;
LogPrint (i,": ", peerHash); LogPrint (i,": ", peerHash);
@ -639,7 +639,7 @@ namespace data
return; return;
} }
char key[48]; char key[48];
int l = i2p::data::ByteStreamToBase64 (buf, 32, key, 48); int l = i2p::util::ByteStreamToBase64 (buf, 32, key, 48);
key[l] = 0; key[l] = 0;
uint8_t flag = buf[64]; uint8_t flag = buf[64];
LogPrint ("DatabaseLookup for ", key, " recieved flags=", (int)flag); LogPrint ("DatabaseLookup for ", key, " recieved flags=", (int)flag);

4
Profiling.cpp

@ -1,7 +1,7 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp> #include <boost/property_tree/ini_parser.hpp>
#include "base64.h" #include "util/base64.h"
#include "util/util.h" #include "util/util.h"
#include "Profiling.h" #include "Profiling.h"
@ -52,7 +52,7 @@ namespace data
LogPrint (eLogError, "Failed to create directory ", path); LogPrint (eLogError, "Failed to create directory ", path);
return; return;
} }
const char * chars = GetBase64SubstitutionTable (); // 64 bytes const char * chars = i2p::util::GetBase64SubstitutionTable (); // 64 bytes
for (int i = 0; i < 64; i++) for (int i = 0; i < 64; i++)
{ {
auto path1 = path / (std::string ("p") + chars[i]); auto path1 = path / (std::string ("p") + chars[i]);

10
RouterInfo.cpp

@ -6,7 +6,7 @@
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include <cryptopp/dsa.h> #include <cryptopp/dsa.h>
#include "CryptoConst.h" #include "CryptoConst.h"
#include "base64.h" #include "util/base64.h"
#include "util/Timestamp.h" #include "util/Timestamp.h"
#include "Log.h" #include "Log.h"
#include "RouterInfo.h" #include "RouterInfo.h"
@ -176,7 +176,7 @@ namespace data
else if (!strcmp (key, "mtu")) else if (!strcmp (key, "mtu"))
address.mtu = boost::lexical_cast<int>(value); address.mtu = boost::lexical_cast<int>(value);
else if (!strcmp (key, "key")) else if (!strcmp (key, "key"))
Base64ToByteStream (value, strlen (value), address.key, 32); i2p::util::Base64ToByteStream (value, strlen (value), address.key, 32);
else if (!strcmp (key, "caps")) else if (!strcmp (key, "caps"))
ExtractCaps (value); ExtractCaps (value);
else if (key[0] == 'i') else if (key[0] == 'i')
@ -199,7 +199,7 @@ namespace data
else if (!strcmp (key, "itag")) else if (!strcmp (key, "itag"))
introducer.iTag = boost::lexical_cast<uint32_t>(value); introducer.iTag = boost::lexical_cast<uint32_t>(value);
else if (!strcmp (key, "ikey")) else if (!strcmp (key, "ikey"))
Base64ToByteStream (value, strlen (value), introducer.iKey, 32); i2p::util::Base64ToByteStream (value, strlen (value), introducer.iKey, 32);
} }
} }
if (isValidAddress) if (isValidAddress)
@ -344,7 +344,7 @@ namespace data
WriteString ("ikey" + boost::lexical_cast<std::string>(i), properties); WriteString ("ikey" + boost::lexical_cast<std::string>(i), properties);
properties << '='; properties << '=';
char value[64]; char value[64];
size_t l = ByteStreamToBase64 (introducer.iKey, 32, value, 64); size_t l = i2p::util::ByteStreamToBase64 (introducer.iKey, 32, value, 64);
value[l] = 0; value[l] = 0;
WriteString (value, properties); WriteString (value, properties);
properties << ';'; properties << ';';
@ -373,7 +373,7 @@ namespace data
WriteString ("key", properties); WriteString ("key", properties);
properties << '='; properties << '=';
char value[64]; char value[64];
size_t l = ByteStreamToBase64 (address.key, 32, value, 64); size_t l = i2p::util::ByteStreamToBase64 (address.key, 32, value, 64);
value[l] = 0; value[l] = 0;
WriteString (value, properties); WriteString (value, properties);
properties << ';'; properties << ';';

6
SAM.cpp

@ -4,7 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include "base64.h" #include "util/base64.h"
#include "Identity.h" #include "Identity.h"
#include "Log.h" #include "Log.h"
#include "Destination.h" #include "Destination.h"
@ -319,7 +319,7 @@ namespace client
uint8_t buf[1024]; uint8_t buf[1024];
char priv[1024]; char priv[1024];
size_t l = m_Session->localDestination->GetPrivateKeys ().ToBuffer (buf, 1024); size_t l = m_Session->localDestination->GetPrivateKeys ().ToBuffer (buf, 1024);
size_t l1 = i2p::data::ByteStreamToBase64 (buf, l, priv, 1024); size_t l1 = i2p::util::ByteStreamToBase64 (buf, l, priv, 1024);
priv[l1] = 0; priv[l1] = 0;
#ifdef _MSC_VER #ifdef _MSC_VER
size_t l2 = sprintf_s (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_SESSION_CREATE_REPLY_OK, priv); size_t l2 = sprintf_s (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_SESSION_CREATE_REPLY_OK, priv);
@ -632,7 +632,7 @@ namespace client
// send remote peer address // send remote peer address
uint8_t ident[1024]; uint8_t ident[1024];
size_t l = stream->GetRemoteIdentity ().ToBuffer (ident, 1024); size_t l = stream->GetRemoteIdentity ().ToBuffer (ident, 1024);
size_t l1 = i2p::data::ByteStreamToBase64 (ident, l, (char *)m_StreamBuffer, SAM_SOCKET_BUFFER_SIZE); size_t l1 = i2p::util::ByteStreamToBase64 (ident, l, (char *)m_StreamBuffer, SAM_SOCKET_BUFFER_SIZE);
m_StreamBuffer[l1] = '\n'; m_StreamBuffer[l1] = '\n';
HandleI2PReceive (boost::system::error_code (), l1 +1); // we send identity like it has been received from stream HandleI2PReceive (boost::system::error_code (), l1 +1); // we send identity like it has been received from stream
} }

4
filelist.mk

@ -1,12 +1,12 @@
COMMON_SRC = \ COMMON_SRC = \
transport/NTCPSession.cpp transport/SSU.cpp transport/SSUSession.cpp \ transport/NTCPSession.cpp transport/SSU.cpp transport/SSUSession.cpp \
transport/SSUData.cpp transport/Transports.cpp \ transport/SSUData.cpp transport/Transports.cpp \
util/util.cpp \ util/util.cpp util/base64.cpp \
CryptoConst.cpp Datagram.cpp Garlic.cpp I2NPProtocol.cpp LeaseSet.cpp \ CryptoConst.cpp Datagram.cpp Garlic.cpp I2NPProtocol.cpp LeaseSet.cpp \
Log.cpp NetDb.cpp NetDbRequests.cpp Profiling.cpp Reseed.cpp \ Log.cpp NetDb.cpp NetDbRequests.cpp Profiling.cpp Reseed.cpp \
RouterContext.cpp RouterInfo.cpp Signature.cpp Streaming.cpp Identity.cpp \ RouterContext.cpp RouterInfo.cpp Signature.cpp Streaming.cpp Identity.cpp \
TransitTunnel.cpp Tunnel.cpp TunnelEndpoint.cpp TunnelPool.cpp \ TransitTunnel.cpp Tunnel.cpp TunnelEndpoint.cpp TunnelPool.cpp \
TunnelGateway.cpp Destination.cpp UPnP.cpp aes.cpp base64.cpp TunnelGateway.cpp Destination.cpp UPnP.cpp aes.cpp
ifeq ($(UNAME),Darwin) ifeq ($(UNAME),Darwin)

4
transport/NTCPSession.cpp

@ -3,9 +3,9 @@
#include "I2PEndian.h" #include "I2PEndian.h"
#include <cryptopp/dh.h> #include <cryptopp/dh.h>
#include <cryptopp/adler32.h> #include <cryptopp/adler32.h>
#include "base64.h" #include "util/base64.h"
#include "Log.h" #include "Log.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "CryptoConst.h" #include "CryptoConst.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "RouterContext.h" #include "RouterContext.h"

2
transport/SSU.cpp

@ -1,7 +1,7 @@
#include <string.h> #include <string.h>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include "Log.h" #include "Log.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "NetDb.h" #include "NetDb.h"
#include "SSU.h" #include "SSU.h"

2
transport/SSUData.cpp

@ -1,7 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include "Log.h" #include "Log.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "NetDb.h" #include "NetDb.h"
#include "SSU.h" #include "SSU.h"
#include "SSUData.h" #include "SSUData.h"

2
transport/SSUSession.cpp

@ -3,7 +3,7 @@
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include "CryptoConst.h" #include "CryptoConst.h"
#include "Log.h" #include "Log.h"
#include "Timestamp.h" #include "util/Timestamp.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Transports.h" #include "Transports.h"
#include "SSU.h" #include "SSU.h"

2
base64.cpp → util/base64.cpp

@ -3,7 +3,7 @@
namespace i2p namespace i2p
{ {
namespace data namespace util
{ {
static void iT64Build(void); static void iT64Build(void);

2
base64.h → util/base64.h

@ -6,7 +6,7 @@
namespace i2p namespace i2p
{ {
namespace data namespace util
{ {
Loading…
Cancel
Save