aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/salticidae/crypto.h11
-rw-r--r--include/salticidae/stream.h4
-rw-r--r--include/salticidae/type.h3
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 <cstdio>
#include <ios>
#include <functional>
-#include <mutex>
namespace salticidae {
@@ -41,8 +40,6 @@ const auto _1 = std::placeholders::_1;
const auto _2 = std::placeholders::_2;
using bytearray_t = std::vector<uint8_t>;
-using mutex_lg_t = std::lock_guard<std::mutex>;
-using mutex_ul_t = std::unique_lock<std::mutex>;
template<typename T> T htole(T) = delete;
template<> inline uint16_t htole<uint16_t>(uint16_t x) { return htole16(x); }