Skip to content

Commit

Permalink
Delete default copy constructor for Botan/OpenSSL wrappers.
Browse files Browse the repository at this point in the history
  • Loading branch information
ni4 committed Dec 5, 2024
1 parent bd9aa80 commit 8549a5c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/lib/crypto/botan_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class bn {

bn(const pgp::mpi &val) : bn(val.mpi, val.len){};

bn(const &bn) = delete;

~bn()
{
botan_mp_destroy(bn_);
Expand Down Expand Up @@ -106,6 +108,9 @@ class Pubkey {

public:
Pubkey() : key_(NULL){};

Pubkey(const &Pubkey) = delete;

~Pubkey()
{
botan_pubkey_destroy(key_);
Expand All @@ -123,10 +128,14 @@ class Privkey {

public:
Privkey() : key_(NULL){};

Privkey(const &Privkey) = delete;

~Privkey()
{
botan_privkey_destroy(key_);
}

botan_privkey_t &
get() noexcept
{
Expand All @@ -146,10 +155,14 @@ class Encrypt {

public:
Encrypt() : op_(NULL){};

Encrypt(const &Encrypt) = delete;

~Encrypt()
{
botan_pk_op_encrypt_destroy(op_);
}

botan_pk_op_encrypt_t &
get() noexcept
{
Expand All @@ -162,10 +175,14 @@ class Decrypt {

public:
Decrypt() : op_(NULL){};

Decrypt(const &Decrypt) = delete;

~Decrypt()
{
botan_pk_op_decrypt_destroy(op_);
}

botan_pk_op_decrypt_t &
get() noexcept
{
Expand All @@ -178,10 +195,14 @@ class Verify {

public:
Verify() : op_(NULL){};

Verify(const &Decrypt) = delete;

~Verify()
{
botan_pk_op_verify_destroy(op_);
}

botan_pk_op_verify_t &
get() noexcept
{
Expand All @@ -194,10 +215,14 @@ class Sign {

public:
Sign() : op_(NULL){};

Sign(const &Sign) = delete;

~Sign()
{
botan_pk_op_sign_destroy(op_);
}

botan_pk_op_sign_t &
get() noexcept
{
Expand All @@ -210,10 +235,14 @@ class KeyAgreement {

public:
KeyAgreement() : op_(NULL){};

KeyAgreement(const &KeyAgreement) = delete;

~KeyAgreement()
{
botan_pk_op_key_agreement_destroy(op_);
}

botan_pk_op_ka_t &
get() noexcept
{
Expand Down
20 changes: 20 additions & 0 deletions src/lib/crypto/ossl_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ class BNCtx {
}
}

BNCtx(const BNCtx &) = delete;

~BNCtx()
{
BN_CTX_free(ctx_);
Expand All @@ -208,6 +210,8 @@ class BNRecpCtx {
public:
BNRecpCtx() : ctx_(BN_RECP_CTX_new()){};

BNRecpCtx(const BNRecpCtx &) = delete;

~BNRecpCtx()
{
BN_RECP_CTX_free(ctx_);
Expand All @@ -226,6 +230,8 @@ class BNMontCtx {
public:
BNMontCtx() : ctx_(BN_MONT_CTX_new()){};

BNMontCtx(const BNMontCtx &) = delete;

~BNMontCtx()
{
BN_MONT_CTX_free(ctx_);
Expand Down Expand Up @@ -381,6 +387,8 @@ class MDCtx {
public:
MDCtx() : ctx_(EVP_MD_CTX_new()){};

MDCtx(const MDCtx &) = delete;

~MDCtx()
{
EVP_MD_CTX_free(ctx_);
Expand Down Expand Up @@ -409,6 +417,8 @@ class RSA {
rsa_ = RSA_new();
}

RSA(const RSA &) = delete;

~RSA()
{
RSA_free(rsa_);
Expand All @@ -430,6 +440,8 @@ class DSA {
dsa_ = DSA_new();
}

DSA(const DSA &) = delete;

~DSA()
{
DSA_free(dsa_);
Expand All @@ -455,6 +467,8 @@ class DH {
{
}

DH(const DH &) = delete;

~DH()
{
DH_free(dh_);
Expand All @@ -481,6 +495,8 @@ class ECKey {
{
}

ECKey(const ECKey &) = delete;

~ECKey()
{
EC_KEY_free(key_);
Expand All @@ -501,6 +517,8 @@ class ECPoint {
{
}

ECPoint(const ECPoint &) = delete;

~ECPoint()
{
EC_POINT_free(pt_);
Expand Down Expand Up @@ -554,6 +572,8 @@ class ParamBld {
bld_ = OSSL_PARAM_BLD_new();
}

ParamBld(const ParamBld &) = delete;

~ParamBld()
{
OSSL_PARAM_BLD_free(bld_);
Expand Down

0 comments on commit 8549a5c

Please sign in to comment.