[DEV] continue removing stl

This commit is contained in:
Edouard DUPIN 2017-08-28 00:02:51 +02:00
parent 56fba43bd5
commit 4a5c53a221
8 changed files with 40 additions and 40 deletions

View File

@ -6,10 +6,10 @@
#include <etk/types.hpp>
#include <algue/base64.hpp>
static const std::string base64Elements = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const etk::String base64Elements = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const std::vector<uint8_t>& getReverseTable() {
static std::vector<uint8_t> table;
const etk::Vector<uint8_t>& getReverseTable() {
static etk::Vector<uint8_t> table;
if (table.size() == 0) {
table.resize(256,0);
for (size_t iii=0; iii<base64Elements.size(); ++iii) {
@ -27,8 +27,8 @@ static bool isBase64(char _ccc) {
|| _ccc == '/';
}
std::string algue::base64::encode(const uint8_t* _data, int32_t _len) {
std::string out;
etk::String algue::base64::encode(const uint8_t* _data, int32_t _len) {
etk::String out;
int32_t iii = 0;
int32_t jjj = 0;
uint8_t bit3[3];
@ -66,14 +66,14 @@ std::string algue::base64::encode(const uint8_t* _data, int32_t _len) {
return out;
}
std::vector<uint8_t> algue::base64::decode(const std::string& _data) {
etk::Vector<uint8_t> algue::base64::decode(const etk::String& _data) {
int32_t len = _data.size();
int32_t iii = 0;
int32_t id = 0;
uint8_t bit4[4];
uint8_t bit3[3];
std::vector<uint8_t> out;
const std::vector<uint8_t>& base64ElementsReverse = getReverseTable();
etk::Vector<uint8_t> out;
const etk::Vector<uint8_t>& base64ElementsReverse = getReverseTable();
while ( len--
&& _data[id] != '='
&& isBase64(_data[id]) == true) {
@ -88,7 +88,7 @@ std::vector<uint8_t> algue::base64::decode(const std::string& _data) {
bit3[1] = ((bit4[1] & 0xf) << 4) + ((bit4[2] & 0x3c) >> 2);
bit3[2] = ((bit4[2] & 0x3) << 6) + bit4[3];
for (int32_t jjj=0; jjj<3; ++jjj) {
out.push_back(bit3[jjj]);
out.pushBack(bit3[jjj]);
}
}
}
@ -103,7 +103,7 @@ std::vector<uint8_t> algue::base64::decode(const std::string& _data) {
bit3[1] = ((bit4[1] & 0xf) << 4) + ((bit4[2] & 0x3c) >> 2);
bit3[2] = ((bit4[2] & 0x3) << 6) + bit4[3];
for (int32_t jjj=0; jjj<iii-1; ++jjj) {
out.push_back(bit3[jjj]);
out.pushBack(bit3[jjj]);
}
}
return out;

View File

@ -9,13 +9,13 @@
namespace algue {
namespace base64 {
std::string encode(const uint8_t* _data, int32_t _len);
inline std::string encode(const std::vector<uint8_t>& _data) {
etk::String encode(const uint8_t* _data, int32_t _len);
inline etk::String encode(const etk::Vector<uint8_t>& _data) {
return algue::base64::encode(&_data[0], _data.size());
}
inline std::string encode(const std::string& _data) {
inline etk::String encode(const etk::String& _data) {
return algue::base64::encode(reinterpret_cast<const uint8_t*>(&_data[0]), _data.size());
}
std::vector<uint8_t> decode(const std::string& _data);
etk::Vector<uint8_t> decode(const etk::String& _data);
}
}

View File

@ -7,8 +7,8 @@
#include <algue/md5.hpp>
#include <openssl/md5.h>
std::vector<uint8_t> algue::md5::encode(const uint8_t* _data, int32_t _len) {
std::vector<uint8_t> out;
etk::Vector<uint8_t> algue::md5::encode(const uint8_t* _data, int32_t _len) {
etk::Vector<uint8_t> out;
out.resize(MD5_DIGEST_LENGTH);
MD5(_data, _len, &out[0]);
return out;

View File

@ -12,11 +12,11 @@
*/
namespace algue {
namespace md5 {
std::vector<uint8_t> encode(const uint8_t* _data, int32_t _len);
inline std::vector<uint8_t> encode(const std::vector<uint8_t>& _data) {
etk::Vector<uint8_t> encode(const uint8_t* _data, int32_t _len);
inline etk::Vector<uint8_t> encode(const etk::Vector<uint8_t>& _data) {
return algue::md5::encode(&_data[0], _data.size());
}
inline std::vector<uint8_t> encode(const std::string& _data) {
inline etk::Vector<uint8_t> encode(const etk::String& _data) {
return algue::md5::encode(reinterpret_cast<const uint8_t*>(&_data[0]), _data.size());
}
}

View File

@ -7,8 +7,8 @@
#include <algue/sha1.hpp>
#include <openssl/sha.h>
std::vector<uint8_t> algue::sha1::encode(const uint8_t* _data, int32_t _len) {
std::vector<uint8_t> out;
etk::Vector<uint8_t> algue::sha1::encode(const uint8_t* _data, int32_t _len) {
etk::Vector<uint8_t> out;
out.resize(SHA_DIGEST_LENGTH);
SHA1(_data, _len, &out[0]);
return out;

View File

@ -9,11 +9,11 @@
namespace algue {
namespace sha1 {
std::vector<uint8_t> encode(const uint8_t* _data, int32_t _len);
inline std::vector<uint8_t> encode(const std::vector<uint8_t>& _data) {
etk::Vector<uint8_t> encode(const uint8_t* _data, int32_t _len);
inline etk::Vector<uint8_t> encode(const etk::Vector<uint8_t>& _data) {
return algue::sha1::encode(&_data[0], _data.size());
}
inline std::vector<uint8_t> encode(const std::string& _data) {
inline etk::Vector<uint8_t> encode(const etk::String& _data) {
return algue::sha1::encode(reinterpret_cast<const uint8_t*>(&_data[0]), _data.size());
}
}

View File

@ -203,12 +203,12 @@ void algue::Sha512::update(const uint8_t *_data, uint32_t _length) {
m_totLen += (block_nb + 1) << 7;
}
std::vector<uint8_t> algue::Sha512::finalize() {
etk::Vector<uint8_t> algue::Sha512::finalize() {
uint32_t block_nb;
uint32_t pm_len;
uint32_t len_b;
int i;
std::vector<uint8_t> out;
etk::Vector<uint8_t> out;
out.resize(ALGUE_DIGEST_SIZE, 0);
block_nb = 1 + ((ALGUE_SHA384_512_BLOCK_SIZE - 17) < (m_len % ALGUE_SHA384_512_BLOCK_SIZE));
len_b = (m_totLen + m_len) << 3;
@ -222,36 +222,36 @@ std::vector<uint8_t> algue::Sha512::finalize() {
}
return out;
}
std::vector<uint8_t> algue::sha512::encode(const uint8_t* _data, int32_t _len) {
etk::Vector<uint8_t> algue::sha512::encode(const uint8_t* _data, int32_t _len) {
algue::Sha512 ctx;
ctx.update(_data, _len);
return ctx.finalize();
}
std::string algue::stringConvert(std::vector<uint8_t> _data) {
etk::String algue::stringConvert(etk::Vector<uint8_t> _data) {
char buf[2*_data.size()+1];
buf[2*_data.size()] = 0;
for (size_t iii=0; iii<_data.size(); ++iii) {
sprintf(buf+iii*2, "%02x", _data[iii]);
}
return std::string(buf);
return etk::String(buf);
}
std::vector<uint8_t> algue::sha512::encodeFromFile(const std::string& _filename) {
etk::Vector<uint8_t> algue::sha512::encodeFromFile(const etk::String& _filename) {
algue::Sha512 ctx;
etk::FSNode node(_filename);
if (node.exist() == 0) {
std::vector<uint8_t> out;
etk::Vector<uint8_t> out;
out.resize(ALGUE_DIGEST_SIZE, 0);
return out;
}
if (node.fileSize() == 0) {
std::vector<uint8_t> out;
etk::Vector<uint8_t> out;
out.resize(ALGUE_DIGEST_SIZE, 0);
return out;
}
if (node.fileOpenRead() == false) {
std::vector<uint8_t> out;
etk::Vector<uint8_t> out;
out.resize(ALGUE_DIGEST_SIZE, 0);
return out;
}

View File

@ -21,23 +21,23 @@ namespace algue {
* @brief get digest value
* @return the digest sha512 value
*/
std::vector<uint8_t> finalize();
etk::Vector<uint8_t> finalize();
protected:
void transform(const uint8_t* _data, uint32_t _blockNb);
uint32_t m_totLen;
uint32_t m_len;
std::vector<uint8_t> m_block;
etk::Vector<uint8_t> m_block;
uint64_t m_h[8];
};
namespace sha512 {
std::vector<uint8_t> encode(const uint8_t* _data, int32_t _len);
inline std::vector<uint8_t> encode(const std::vector<uint8_t>& _data) {
etk::Vector<uint8_t> encode(const uint8_t* _data, int32_t _len);
inline etk::Vector<uint8_t> encode(const etk::Vector<uint8_t>& _data) {
return algue::sha512::encode(&_data[0], _data.size());
}
inline std::vector<uint8_t> encode(const std::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());
}
std::vector<uint8_t> encodeFromFile(const std::string& _filename);
etk::Vector<uint8_t> encodeFromFile(const etk::String& _filename);
}
std::string stringConvert(std::vector<uint8_t> _data);
etk::String stringConvert(etk::Vector<uint8_t> _data);
}