-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathhmacauth.h
42 lines (33 loc) · 1.04 KB
/
hmacauth.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef HMACAUTH_H
#define HMACAUTH_H
#include <vector>
#include <memory>
#include <QDebug>
#include <QObject>
#include <QtCore/QMutex>
#include <openssl/opensslv.h>
#include <openssl/hmac.h>
#include <QUuid>
#include <cassert>
class HMACAuth {
public:
enum AuthMethod { MD5, SHA1, SHA224, SHA256, RIPEMD160 };
using HMACHash = std::vector<unsigned char>;
explicit HMACAuth(AuthMethod auth_method = MD5);
~HMACAuth();
bool SetKey(const char* keyValue, int keyLen);
bool SetKey(const QUuid& uidKey);
// Calculate complete hash in one.
bool CalculateHash(HMACHash& hashResult, const char* data, int dataLen);
// Append to data to be hashed.
bool AddData(const char* data, int dataLen);
// Get the resulting hash from calls to addData().
// Note that only one hash may be calculated at a time for each
// HMACAuth instance if this interface is used.
HMACHash Result();
private:
QMutex _lock { QMutex::Recursive };
struct hmac_ctx_st* hmac_context;
AuthMethod auth_method;
};
#endif // HMACAUTH_H