Archived
1
0

clang format

This commit is contained in:
Jeff Becker
2017-10-17 10:29:56 -04:00
parent 85248787fc
commit 841c5c6afe
69 changed files with 2381 additions and 2448 deletions

View File

@@ -3,21 +3,18 @@
#include <cassert>
#include <cstring>
#include <string>
#include <iostream>
#include <sodium.h>
#include <string>
static void print_help(const std::string & exename)
static void print_help(const std::string &exename)
{
std::cout << "usage: " << exename << " [help|gen|check]" << std::endl;
}
static void print_long_help()
{
static void print_long_help() {}
}
static void gen_passwd(const std::string & username, const std::string & passwd)
static void gen_passwd(const std::string &username, const std::string &passwd)
{
std::array<uint8_t, 8> random;
randombytes_buf(random.data(), random.size());
@@ -29,57 +26,69 @@ static void gen_passwd(const std::string & username, const std::string & passwd)
std::cout << username << ":" << hash << ":" << salt << std::endl;
}
static bool check_cred(const std::string & cred, const std::string & passwd)
static bool check_cred(const std::string &cred, const std::string &passwd)
{
auto idx = cred.find(":");
if(idx == std::string::npos || idx == 0) return false;
std::string part = cred.substr(idx+1);
if (idx == std::string::npos || idx == 0)
return false;
std::string part = cred.substr(idx + 1);
idx = part.find(":");
if(idx == std::string::npos || idx == 0) return false;
std::string salt = part.substr(idx+1);
if (idx == std::string::npos || idx == 0)
return false;
std::string salt = part.substr(idx + 1);
std::string hash = part.substr(0, idx);
std::vector<uint8_t> h;
if(!nntpchan::B64Decode(hash, h)) return false;
if (!nntpchan::B64Decode(hash, h))
return false;
nntpchan::SHA512Digest d;
std::string l = passwd + salt;
nntpchan::SHA512((const uint8_t*)l.data(), l.size(), d);
nntpchan::SHA512((const uint8_t *)l.data(), l.size(), d);
return std::memcmp(h.data(), d.data(), d.size()) == 0;
}
int main(int argc, char * argv[])
int main(int argc, char *argv[])
{
assert(sodium_init() == 0);
if(argc == 1) {
if (argc == 1)
{
print_help(argv[0]);
return 1;
}
std::string cmd(argv[1]);
if (cmd == "help") {
if (cmd == "help")
{
print_long_help();
return 0;
}
if (cmd == "gen") {
if(argc == 4) {
if (cmd == "gen")
{
if (argc == 4)
{
gen_passwd(argv[2], argv[3]);
return 0;
} else {
}
else
{
std::cout << "usage: " << argv[0] << " gen username password" << std::endl;
return 1;
}
}
if(cmd == "check" ) {
if (cmd == "check")
{
std::string cred;
std::cout << "credential: " ;
if(!std::getline(std::cin, cred)) {
std::cout << "credential: ";
if (!std::getline(std::cin, cred))
{
return 1;
}
std::string passwd;
std::cout << "password: ";
if(!std::getline(std::cin, passwd)) {
if (!std::getline(std::cin, passwd))
{
return 1;
}
if(check_cred(cred, passwd)) {
if (check_cred(cred, passwd))
{
std::cout << "okay" << std::endl;
return 0;
}

View File

@@ -1,11 +1,9 @@
#include <nntpchan/exec_frontend.hpp>
#include <nntpchan/sanitize.hpp>
#include <cassert>
#include <iostream>
#include <nntpchan/exec_frontend.hpp>
#include <nntpchan/sanitize.hpp>
int main(int , char * [])
int main(int, char *[])
{
nntpchan::Frontend_ptr f(new nntpchan::ExecFrontend("./contrib/nntpchan.sh"));
assert(nntpchan::IsValidMessageID("<a28a71493831188@web.oniichan.onion>"));