From cd2fc3625d09f2f3f062648ff9963414e0140e2a Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 25 Jul 2018 01:22:05 -0400 Subject: ... --- include/salticidae/crypto.h | 11 +++++------ include/salticidae/stream.h | 4 ++-- include/salticidae/type.h | 3 --- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/include/salticidae/crypto.h b/include/salticidae/crypto.h index c329c63..79e9377 100644 --- a/include/salticidae/crypto.h +++ b/include/salticidae/crypto.h @@ -31,14 +31,13 @@ namespace salticidae { class SHA256 { - SHA256_CTX *ctx; + SHA256_CTX ctx; public: - SHA256(): ctx(new SHA256_CTX()) { reset(); } - ~SHA256() { delete ctx; } + SHA256() { reset(); } void reset() { - if (!SHA256_Init(ctx)) + if (!SHA256_Init(&ctx)) throw std::runtime_error("openssl SHA256 init error"); } @@ -52,12 +51,12 @@ class SHA256 { } void update(const uint8_t *ptr, size_t length) { - if (!SHA256_Update(ctx, ptr, length)) + if (!SHA256_Update(&ctx, ptr, length)) throw std::runtime_error("openssl SHA256 update error"); } void _digest(bytearray_t &md) { - if (!SHA256_Final(&*md.begin(), ctx)) + if (!SHA256_Final(&*md.begin(), &ctx)) throw std::runtime_error("openssl SHA256 error"); } diff --git a/include/salticidae/stream.h b/include/salticidae/stream.h index 03b9d13..267d294 100644 --- a/include/salticidae/stream.h +++ b/include/salticidae/stream.h @@ -109,11 +109,11 @@ class DataStream { const uint8_t *get_data_inplace(size_t len) { auto res = (uint8_t *)&*(buffer.begin() + offset); + offset += len; #ifndef SALTICIDAE_NOCHECK - if (offset + len > buffer.size()) + if (offset > buffer.size()) throw std::ios_base::failure("insufficient buffer"); #endif - offset += len; return res; } diff --git a/include/salticidae/type.h b/include/salticidae/type.h index 13975a5..13d3071 100644 --- a/include/salticidae/type.h +++ b/include/salticidae/type.h @@ -33,7 +33,6 @@ #include #include #include -#include namespace salticidae { @@ -41,8 +40,6 @@ const auto _1 = std::placeholders::_1; const auto _2 = std::placeholders::_2; using bytearray_t = std::vector; -using mutex_lg_t = std::lock_guard; -using mutex_ul_t = std::unique_lock; template T htole(T) = delete; template<> inline uint16_t htole(uint16_t x) { return htole16(x); } -- cgit v1.2.3