[DEV] update new insterface IO of etk
This commit is contained in:
parent
be0d380308
commit
4005d9bf56
@ -44,7 +44,8 @@
|
|||||||
#include <etk/types.hpp>
|
#include <etk/types.hpp>
|
||||||
#include <algue/sha512.hpp>
|
#include <algue/sha512.hpp>
|
||||||
#include <algue/debug.hpp>
|
#include <algue/debug.hpp>
|
||||||
#include <etk/os/FSNode.hpp>
|
#include <etk/path/Path.hpp>
|
||||||
|
#include <etk/uri/provider/provider.hpp>
|
||||||
|
|
||||||
static const uint32_t ALGUE_SHA384_512_BLOCK_SIZE = (1024/8);
|
static const uint32_t ALGUE_SHA384_512_BLOCK_SIZE = (1024/8);
|
||||||
static const uint32_t ALGUE_DIGEST_SIZE = ( 512 / 8);
|
static const uint32_t ALGUE_DIGEST_SIZE = ( 512 / 8);
|
||||||
@ -237,33 +238,29 @@ etk::String algue::stringConvert(etk::Vector<uint8_t> _data) {
|
|||||||
return etk::String(buf);
|
return etk::String(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
etk::Vector<uint8_t> algue::sha512::encodeFromFile(const etk::String& _filename) {
|
etk::Vector<uint8_t> algue::sha512::encodeFromFile(const etk::Uri& _uri) {
|
||||||
algue::Sha512 ctx;
|
algue::Sha512 ctx;
|
||||||
etk::FSNode node(_filename);
|
auto fileIo = etk::uri::get(_uri);
|
||||||
if (node.exist() == 0) {
|
if (fileIo == null) {
|
||||||
|
ALGUE_ERROR("File Does not exist : " << _uri);
|
||||||
etk::Vector<uint8_t> out;
|
etk::Vector<uint8_t> out;
|
||||||
out.resize(ALGUE_DIGEST_SIZE, 0);
|
out.resize(ALGUE_DIGEST_SIZE, 0);
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
if (node.fileSize() == 0) {
|
if (fileIo->open(etk::io::OpenMode::Read) == false) {
|
||||||
|
ALGUE_ERROR("Can not open (r) the file : " << _uri);
|
||||||
etk::Vector<uint8_t> out;
|
etk::Vector<uint8_t> out;
|
||||||
out.resize(ALGUE_DIGEST_SIZE, 0);
|
out.resize(ALGUE_DIGEST_SIZE, 0);
|
||||||
return out;
|
|
||||||
}
|
|
||||||
if (node.fileOpenRead() == false) {
|
|
||||||
etk::Vector<uint8_t> out;
|
|
||||||
out.resize(ALGUE_DIGEST_SIZE, 0);
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t bufferSize = 4096;
|
uint32_t bufferSize = 4096;
|
||||||
uint8_t buffer[bufferSize];
|
uint8_t buffer[bufferSize];
|
||||||
while (bufferSize == 4096) {
|
while (bufferSize == 4096) {
|
||||||
bufferSize = node.fileRead(buffer, 1, bufferSize);
|
bufferSize = fileIo->read(buffer, 1, bufferSize);
|
||||||
if (bufferSize != 0) {
|
if (bufferSize != 0) {
|
||||||
ctx.update(buffer, bufferSize);
|
ctx.update(buffer, bufferSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.fileClose();
|
fileIo->close();
|
||||||
return ctx.finalize();
|
return ctx.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <etk/types.hpp>
|
#include <etk/types.hpp>
|
||||||
#include <etk/Vector.hpp>
|
#include <etk/Vector.hpp>
|
||||||
#include <etk/String.hpp>
|
#include <etk/String.hpp>
|
||||||
|
#include <etk/uri/Uri.hpp>
|
||||||
|
|
||||||
namespace algue {
|
namespace algue {
|
||||||
class Sha512 {
|
class Sha512 {
|
||||||
@ -39,7 +40,7 @@ namespace algue {
|
|||||||
inline etk::Vector<uint8_t> encode(const etk::String& _data) {
|
inline etk::Vector<uint8_t> encode(const etk::String& _data) {
|
||||||
return algue::sha512::encode(reinterpret_cast<const uint8_t*>(&_data[0]), _data.size());
|
return algue::sha512::encode(reinterpret_cast<const uint8_t*>(&_data[0]), _data.size());
|
||||||
}
|
}
|
||||||
etk::Vector<uint8_t> encodeFromFile(const etk::String& _filename);
|
etk::Vector<uint8_t> encodeFromFile(const etk::Uri& _uri);
|
||||||
}
|
}
|
||||||
etk::String stringConvert(etk::Vector<uint8_t> _data);
|
etk::String stringConvert(etk::Vector<uint8_t> _data);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user