Make sha256's factory method return a ref<> instead of a raw pointer.

This commit is contained in:
Relintai 2022-01-09 15:29:03 +01:00
parent 8e903f2695
commit 7323c38776
5 changed files with 7 additions and 9 deletions

View File

@ -49,6 +49,6 @@ HashLibSHA256::HashLibSHA256() {
HashLibSHA256::~HashLibSHA256() {
}
SHA256 *HashLibSHA256::_creation_func() {
Ref<SHA256> HashLibSHA256::_creation_func() {
return new HashLibSHA256();
}

View File

@ -23,7 +23,7 @@ public:
~HashLibSHA256();
protected:
static SHA256 *_creation_func();
static Ref<SHA256> _creation_func();
_SHA256 hasher;
};

View File

@ -8,7 +8,7 @@ SHA256::~SHA256() {
}
SHA256 *SHA256::get() {
Ref<SHA256> SHA256::get() {
if (_sha_256_creation_func == nullptr) {
printf("Error: static SHA256 *get(): creation_func == nullptr\n");
return nullptr;
@ -17,4 +17,4 @@ SHA256 *SHA256::get() {
return _sha_256_creation_func();
}
SHA256 *(*SHA256::_sha_256_creation_func)(void) = nullptr;
Ref<SHA256> (*SHA256::_sha_256_creation_func)(void) = nullptr;

View File

@ -18,13 +18,13 @@ public:
virtual void reset() = 0;
static SHA256 *get();
static Ref<SHA256> get();
SHA256();
virtual ~SHA256();
protected:
static SHA256 *(*_sha_256_creation_func)(void);
static Ref<SHA256> (*_sha_256_creation_func)(void);
};
#endif

View File

@ -216,7 +216,7 @@ void SessionManager::clear() {
String SessionManager::generate_session_id(const String &base) {
// todo make something simpler / better
SHA256 *h = SHA256::get();
Ref<SHA256> h = SHA256::get();
String sid = base;
sid += rand();
@ -225,8 +225,6 @@ String SessionManager::generate_session_id(const String &base) {
sid = h->get_hash();
sid.resize(20);
delete h;
return sid;
}