Use common crypt64::encode in server
This commit is contained in:
parent
b753b33239
commit
9932ed0999
1 changed files with 2 additions and 30 deletions
|
@ -15,6 +15,7 @@
|
|||
#include "server/user_handler.hpp"
|
||||
#include "config.hpp"
|
||||
#include "random.hpp"
|
||||
#include "serialization/base64.hpp"
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#include <array>
|
||||
|
@ -52,36 +53,7 @@ std::string user_handler::create_unsecure_nonce(int length) {
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
// TODO - This really should be a common function.
|
||||
// This is duplicated in two or three other places.
|
||||
// Some are virtual member functions.
|
||||
namespace {
|
||||
const std::string itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ;
|
||||
|
||||
template<size_t len>
|
||||
std::string encode_hash(const std::array<unsigned char, len>& input) {
|
||||
std::string encoded_hash;
|
||||
|
||||
unsigned int i = 0;
|
||||
do {
|
||||
unsigned value = input[i++];
|
||||
encoded_hash.append(itoa64.substr(value & 0x3f,1));
|
||||
if(i < len)
|
||||
value |= static_cast<int>(input[i]) << 8;
|
||||
encoded_hash.append(itoa64.substr((value >> 6) & 0x3f,1));
|
||||
if(i++ >= len)
|
||||
break;
|
||||
if(i < len)
|
||||
value |= static_cast<int>(input[i]) << 16;
|
||||
encoded_hash.append(itoa64.substr((value >> 12) & 0x3f,1));
|
||||
if(i++ >= len)
|
||||
break;
|
||||
encoded_hash.append(itoa64.substr((value >> 18) & 0x3f,1));
|
||||
} while (i < len);
|
||||
|
||||
return encoded_hash;
|
||||
}
|
||||
|
||||
class RAND_bytes_exception: public std::exception
|
||||
{
|
||||
};
|
||||
|
@ -96,6 +68,6 @@ std::string user_handler::create_secure_nonce()
|
|||
throw RAND_bytes_exception();
|
||||
}
|
||||
|
||||
return encode_hash(buf);
|
||||
return crypt64::encode({buf.data(), buf.size()});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue