This source file includes following definitions.
- CryptoRandomInt
- GenerateSupportHostSecret
#include "remoting/host/host_secret.h"
#include <string>
#include "base/logging.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
namespace remoting {
namespace {
const int kHostSecretLength = 5;
const char kHostSecretAlphabet[] = "0123456789";
int CryptoRandomInt(int max) {
uint32 random_int32;
base::RandBytes(&random_int32, sizeof(random_int32));
return random_int32 % max;
}
}
std::string GenerateSupportHostSecret() {
std::string result;
int alphabet_size = strlen(kHostSecretAlphabet);
result.resize(kHostSecretLength);
for (int i = 0; i < kHostSecretLength; ++i) {
result[i] = kHostSecretAlphabet[CryptoRandomInt(alphabet_size)];
}
return result;
}
}