Fix Format

This commit is contained in:
Elia Zammuto 2021-05-29 22:29:10 +02:00
commit ffb80c5fc3
11 changed files with 298 additions and 360 deletions

View file

@ -6,7 +6,7 @@
#include <iostream>
#include <openssl/pem.h>
namespace crypto {
using big_num_t = util::safe_ptr<BIGNUM, BN_free>;
using big_num_t = util::safe_ptr<BIGNUM, BN_free>;
//using rsa_t = util::safe_ptr<RSA, RSA_free>;
using asn1_string_t = util::safe_ptr<ASN1_STRING, ASN1_STRING_free>;
@ -340,23 +340,21 @@ void md_ctx_destroy(EVP_MD_CTX *ctx) {
EVP_MD_CTX_destroy(ctx);
}
std::string rand_string(std::size_t bytes)
{
std::string rand_string(std::size_t bytes) {
std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!%&()=-";
std::string value = rand(bytes);
for (std::size_t i = 0; i != value.size(); ++i) {
std::string value = rand(bytes);
for(std::size_t i = 0; i != value.size(); ++i) {
value[i] = alphabet[value[i] % alphabet.length()];
}
return value;
}
std::string hash_hexstr(const std::string_view &plaintext)
{
std::string hash_hexstr(const std::string_view &plaintext) {
sha256_t hashBytes = crypto::hash(plaintext);
std::ostringstream hashStream;
hashStream << std::hex << std::setfill( '0' );
std::for_each( hashBytes.cbegin(), hashBytes.cend(), [&]( int c ) { hashStream << std::setw( 2 ) << c; } );
hashStream << std::hex << std::setfill('0');
std::for_each(hashBytes.cbegin(), hashBytes.cend(), [&](int c) { hashStream << std::setw(2) << c; });
std::string hashString = hashStream.str();
return hashString;
}
}
} // namespace crypto