Skip to content
Snippets Groups Projects
Commit e073c5ed authored by Adrien Béraud's avatar Adrien Béraud
Browse files

fileutils: remove sha3File, sha3sum

Change-Id: I7ffb6657cfdc3556d8292b2c087fd0aa732adc26
parent 4822fa09
Branches
No related tags found
No related merge requests found
......@@ -132,9 +132,6 @@ std::ofstream ofstream(const std::string& path, std::ios_base::openmode mode = s
int64_t size(const std::string& path);
std::string sha3File(const std::string& path);
std::string sha3sum(const std::vector<uint8_t>& buffer);
/**
* Windows compatibility wrapper for checking read-only attribute
*/
......
......@@ -56,8 +56,6 @@
#include <wordexp.h>
#endif
#include <nettle/sha3.h>
#include <sstream>
#include <fstream>
#include <iostream>
......@@ -786,59 +784,6 @@ size(const std::string& path)
return size;
}
std::string
sha3File(const std::string& path)
{
sha3_512_ctx ctx;
sha3_512_init(&ctx);
std::ifstream file;
try {
if (!fileutils::isFile(path))
return {};
openStream(file, path, std::ios::binary | std::ios::in);
if (!file)
return {};
std::vector<char> buffer(8192, 0);
while (!file.eof()) {
file.read(buffer.data(), buffer.size());
std::streamsize readSize = file.gcount();
sha3_512_update(&ctx, readSize, (const uint8_t*) buffer.data());
}
file.close();
} catch (...) {
return {};
}
unsigned char digest[SHA3_512_DIGEST_SIZE];
sha3_512_digest(&ctx, SHA3_512_DIGEST_SIZE, digest);
char hash[SHA3_512_DIGEST_SIZE * 2];
for (int i = 0; i < SHA3_512_DIGEST_SIZE; ++i)
pj_val_to_hex_digit(digest[i], &hash[2 * i]);
return {hash, SHA3_512_DIGEST_SIZE * 2};
}
std::string
sha3sum(const std::vector<uint8_t>& buffer)
{
sha3_512_ctx ctx;
sha3_512_init(&ctx);
sha3_512_update(&ctx, buffer.size(), (const uint8_t*) buffer.data());
unsigned char digest[SHA3_512_DIGEST_SIZE];
sha3_512_digest(&ctx, SHA3_512_DIGEST_SIZE, digest);
char hash[SHA3_512_DIGEST_SIZE * 2];
for (int i = 0; i < SHA3_512_DIGEST_SIZE; ++i)
pj_val_to_hex_digit(digest[i], &hash[2 * i]);
return {hash, SHA3_512_DIGEST_SIZE * 2};
}
int
accessFile(const std::string& file, int mode)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment