-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpensslTraits.h
79 lines (71 loc) · 1.97 KB
/
OpensslTraits.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#include <openssl/bio.h>
#include <openssl/ec.h>
#include <openssl/evp.h>
#include <openssl/types.h>
// BIO_new_file()/BIO_free()
struct BioTrait
{
static constexpr BIO *default_value = nullptr;
static void Cleanup(BIO *h) noexcept
{
BIO_free(h);
}
};
using BioHandle = UniqueResource<BioTrait, BIO *>;
// EVP_CIPHER_CTX_new()/EVP_CIPHER_CTX_free()
struct EvpCipherCtxTrait
{
static constexpr EVP_CIPHER_CTX *default_value = nullptr;
static void Cleanup(EVP_CIPHER_CTX *ctx) noexcept
{
EVP_CIPHER_CTX_free(ctx);
}
};
using EvpCipherCtx = UniqueResource<EvpCipherCtxTrait, EVP_CIPHER_CTX *>;
// EVP_PKEY_new()/EVP_PKEY_free()
struct EvpPkeyTrait
{
static constexpr EVP_PKEY *default_value = nullptr;
static void Cleanup(EVP_PKEY *pkey) noexcept
{
EVP_PKEY_free(pkey);
}
};
using EvpPkey = UniqueResource<EvpPkeyTrait, EVP_PKEY *>;
// EVP_MD_CTX_new()/EVP_MD_CTX_free()
struct EvpMdCtxTrait
{
static constexpr EVP_MD_CTX *default_value = nullptr;
static void Cleanup(EVP_MD_CTX *ctx) noexcept
{
EVP_MD_CTX_free(ctx);
}
};
using EvpMdCtx = UniqueResource<EvpMdCtxTrait, EVP_MD_CTX *>;
// EVP_PKEY_CTX_new()/EVP_PKEY_CTX_free()
struct EvpPkeyCtxTrait
{
static constexpr EVP_PKEY_CTX *default_value = nullptr;
static void Cleanup(EVP_PKEY_CTX *ctx) noexcept
{
EVP_PKEY_CTX_free(ctx);
}
};
using EvpPkeyCtx = UniqueResource<EvpPkeyCtxTrait, EVP_PKEY_CTX *>;
// EC_KEY_new_by_curve_name()/EC_KEY_free()
// struct EcKeyTrait {
// static constexpr EC_KEY* default_value = nullptr;
// static void Cleanup(EC_KEY* key) noexcept { EC_KEY_free(key); }
//};
// using EcKey = UniqueResource<EcKeyTrait, EC_KEY*>;
// EC_GROUP_new_by_curve_name()/EC_GROUP_free()
struct EcGroupTrait
{
static constexpr EC_GROUP *default_value = nullptr;
static void Cleanup(EC_GROUP *g) noexcept
{
EC_GROUP_free(g);
}
};
using EcGroup = UniqueResource<EcGroupTrait, EC_GROUP *>;