mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Add I2P BOB support to libretroashare and RetroShare GUI
This commit is contained in:
parent
9ff81b9e93
commit
a3ee85a30d
31 changed files with 4150 additions and 959 deletions
50
libretroshare/src/util/radix32.h
Normal file
50
libretroshare/src/util/radix32.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
#ifndef RADIX32_H
|
||||
#define RADIX32_H
|
||||
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
class Radix32
|
||||
{
|
||||
public:
|
||||
static std::string encode(const std::vector<uint8_t> &in) {
|
||||
return encode(in.data(), in.size());
|
||||
}
|
||||
|
||||
static std::string encode(const uint8_t *data, size_t len) {
|
||||
std::string out = "";
|
||||
|
||||
size_t pos = 1;
|
||||
uint8_t bits = 8, index;
|
||||
uint16_t tmp = data[0]; // need min. 16 bits here
|
||||
while (bits > 0 || pos < len) {
|
||||
if (bits < 5) {
|
||||
if (pos < len) {
|
||||
tmp <<= 8;
|
||||
tmp |= data[pos++] & 0xFF;
|
||||
bits += 8;
|
||||
} else { // last byte
|
||||
tmp <<= (5 - bits);
|
||||
bits = 5;
|
||||
}
|
||||
}
|
||||
|
||||
bits -= 5;
|
||||
index = (tmp >> bits) & 0x1F;
|
||||
out.push_back(bintoasc()[index]);
|
||||
}
|
||||
|
||||
// append padding
|
||||
while(out.length() % 4 != 0)
|
||||
out.push_back('=');
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
private:
|
||||
static const inline char *bintoasc() { static const char bta[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; return bta ; }
|
||||
};
|
||||
|
||||
#endif // RADIX32_H
|
|
@ -126,3 +126,24 @@ std::string RsUtil::HashId(const std::string &id, bool reverse)
|
|||
// out << std::setprecision(15) << getCurrentTS();
|
||||
// return out.str();
|
||||
//}
|
||||
|
||||
std::vector<uint8_t> RsUtil::BinToSha256(const std::vector<uint8_t> &in)
|
||||
{
|
||||
std::vector<uint8_t> out;
|
||||
|
||||
SHA256_CTX *sha_ctx = new SHA256_CTX;
|
||||
uint8_t sha_hash[SHA256_DIGEST_LENGTH] = {0};
|
||||
|
||||
SHA256_Init(sha_ctx);
|
||||
SHA256_Update(sha_ctx, in.data(), in.size());
|
||||
SHA256_Final(sha_hash, sha_ctx);
|
||||
|
||||
for(uint16_t i = 0; i < SHA256_DIGEST_LENGTH; i++)
|
||||
{
|
||||
out.push_back(sha_hash[i]);
|
||||
}
|
||||
|
||||
/* cleanup */
|
||||
delete sha_ctx;
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace RsUtil {
|
||||
|
||||
|
@ -38,6 +39,7 @@ std::string BinToHex(const char *arr, const uint32_t len);
|
|||
std::string BinToHex(const unsigned char *arr, const uint32_t len);
|
||||
std::string NumberToString(uint64_t n, bool hex=false);
|
||||
std::string HashId(const std::string &id, bool reverse = false);
|
||||
std::vector<uint8_t> BinToSha256(const std::vector<uint8_t> &in);
|
||||
|
||||
//std::string AccurateTimeString();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue