diff --git a/algue/sha512.cpp b/algue/sha512.cpp index 93fec76..7d286cf 100644 --- a/algue/sha512.cpp +++ b/algue/sha512.cpp @@ -44,7 +44,8 @@ #include #include #include -#include +#include +#include static const uint32_t ALGUE_SHA384_512_BLOCK_SIZE = (1024/8); static const uint32_t ALGUE_DIGEST_SIZE = ( 512 / 8); @@ -237,33 +238,29 @@ etk::String algue::stringConvert(etk::Vector _data) { return etk::String(buf); } -etk::Vector algue::sha512::encodeFromFile(const etk::String& _filename) { +etk::Vector algue::sha512::encodeFromFile(const etk::Uri& _uri) { algue::Sha512 ctx; - etk::FSNode node(_filename); - if (node.exist() == 0) { + auto fileIo = etk::uri::get(_uri); + if (fileIo == null) { + ALGUE_ERROR("File Does not exist : " << _uri); etk::Vector out; 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 out; out.resize(ALGUE_DIGEST_SIZE, 0); - return out; - } - if (node.fileOpenRead() == false) { - etk::Vector out; - out.resize(ALGUE_DIGEST_SIZE, 0); - return out; } + uint32_t bufferSize = 4096; uint8_t buffer[bufferSize]; while (bufferSize == 4096) { - bufferSize = node.fileRead(buffer, 1, bufferSize); + bufferSize = fileIo->read(buffer, 1, bufferSize); if (bufferSize != 0) { ctx.update(buffer, bufferSize); } } - node.fileClose(); + fileIo->close(); return ctx.finalize(); } diff --git a/algue/sha512.hpp b/algue/sha512.hpp index 2253858..1a0ea31 100644 --- a/algue/sha512.hpp +++ b/algue/sha512.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace algue { class Sha512 { @@ -39,7 +40,7 @@ namespace algue { inline etk::Vector encode(const etk::String& _data) { return algue::sha512::encode(reinterpret_cast(&_data[0]), _data.size()); } - etk::Vector encodeFromFile(const etk::String& _filename); + etk::Vector encodeFromFile(const etk::Uri& _uri); } etk::String stringConvert(etk::Vector _data); }