diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/openssl/holders | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/openssl/holders')
-rw-r--r-- | library/cpp/openssl/holders/bio.cpp | 29 | ||||
-rw-r--r-- | library/cpp/openssl/holders/bio.h | 25 | ||||
-rw-r--r-- | library/cpp/openssl/holders/bn.h | 13 | ||||
-rw-r--r-- | library/cpp/openssl/holders/evp.h | 13 | ||||
-rw-r--r-- | library/cpp/openssl/holders/hmac.h | 10 | ||||
-rw-r--r-- | library/cpp/openssl/holders/holder.h | 32 | ||||
-rw-r--r-- | library/cpp/openssl/holders/ut/evp_ut.cpp | 15 | ||||
-rw-r--r-- | library/cpp/openssl/holders/ut/hmac_ut.cpp | 10 | ||||
-rw-r--r-- | library/cpp/openssl/holders/ut/ya.make | 10 | ||||
-rw-r--r-- | library/cpp/openssl/holders/x509_vfy.cpp | 30 | ||||
-rw-r--r-- | library/cpp/openssl/holders/x509_vfy.h | 25 | ||||
-rw-r--r-- | library/cpp/openssl/holders/ya.make | 16 |
12 files changed, 228 insertions, 0 deletions
diff --git a/library/cpp/openssl/holders/bio.cpp b/library/cpp/openssl/holders/bio.cpp new file mode 100644 index 0000000000..42cc5fc1ef --- /dev/null +++ b/library/cpp/openssl/holders/bio.cpp @@ -0,0 +1,29 @@ +#include "bio.h" + +namespace NOpenSSL { + + TBioMethod::TBioMethod( + int type, + const char* name, + int (*write)(BIO*, const char*, int), + int (*read)(BIO*, char*, int), + int (*puts)(BIO*, const char*), + int (*gets)(BIO*, char*, int), + long (*ctrl)(BIO*, int, long, void*), + int (*create)(BIO*), + int (*destroy)(BIO*), + long (*callbackCtrl)(BIO*, int, bio_info_cb*) + ) + : THolder(type, name) + { + BIO_meth_set_write(*this, write); + BIO_meth_set_read(*this, read); + BIO_meth_set_puts(*this, puts); + BIO_meth_set_gets(*this, gets); + BIO_meth_set_ctrl(*this, ctrl); + BIO_meth_set_create(*this, create); + BIO_meth_set_destroy(*this, destroy); + BIO_meth_set_callback_ctrl(*this, callbackCtrl); + } + +} // namespace NOpenSSL diff --git a/library/cpp/openssl/holders/bio.h b/library/cpp/openssl/holders/bio.h new file mode 100644 index 0000000000..bcd6a7a9d6 --- /dev/null +++ b/library/cpp/openssl/holders/bio.h @@ -0,0 +1,25 @@ +#pragma once + +#include <contrib/libs/openssl/include/openssl/bio.h> + +#include <library/cpp/openssl/holders/holder.h> + +namespace NOpenSSL { + +class TBioMethod : public THolder<BIO_METHOD, BIO_meth_new, BIO_meth_free, int, const char*> { +public: + TBioMethod( + int type, + const char* name, + int (*write)(BIO*, const char*, int), + int (*read)(BIO*, char*, int), + int (*puts)(BIO*, const char*), + int (*gets)(BIO*, char*, int), + long (*ctrl)(BIO*, int, long, void*), + int (*create)(BIO*), + int (*destroy)(BIO*), + long (*callbackCtrl)(BIO*, int, bio_info_cb*) + ); +}; + +} // namespace NOpenSSL diff --git a/library/cpp/openssl/holders/bn.h b/library/cpp/openssl/holders/bn.h new file mode 100644 index 0000000000..9d133d4bdd --- /dev/null +++ b/library/cpp/openssl/holders/bn.h @@ -0,0 +1,13 @@ +#pragma once + +#include "holder.h" + +#include <contrib/libs/openssl/include/openssl/bn.h> + +namespace NOpenSSL { + class TBignum : public THolder<BIGNUM, BN_new, BN_clear_free> { + }; + + class TBnCtx : public THolder<BN_CTX, BN_CTX_new, BN_CTX_free> { + }; +} diff --git a/library/cpp/openssl/holders/evp.h b/library/cpp/openssl/holders/evp.h new file mode 100644 index 0000000000..df3cc4c2fa --- /dev/null +++ b/library/cpp/openssl/holders/evp.h @@ -0,0 +1,13 @@ +#pragma once + +#include "holder.h" + +#include <contrib/libs/openssl/include/openssl/evp.h> + +namespace NOpenSSL { + class TEvpCipherCtx : public THolder<EVP_CIPHER_CTX, EVP_CIPHER_CTX_new, EVP_CIPHER_CTX_free> { + }; + + class TEvpMdCtx : public THolder<EVP_MD_CTX, EVP_MD_CTX_new, EVP_MD_CTX_free> { + }; +} diff --git a/library/cpp/openssl/holders/hmac.h b/library/cpp/openssl/holders/hmac.h new file mode 100644 index 0000000000..4110e06f00 --- /dev/null +++ b/library/cpp/openssl/holders/hmac.h @@ -0,0 +1,10 @@ +#pragma once + +#include "holder.h" + +#include <contrib/libs/openssl/include/openssl/hmac.h> + +namespace NOpenSSL { + class THmacCtx : public THolder<HMAC_CTX, HMAC_CTX_new, HMAC_CTX_free> { + }; +} diff --git a/library/cpp/openssl/holders/holder.h b/library/cpp/openssl/holders/holder.h new file mode 100644 index 0000000000..c2a26ce431 --- /dev/null +++ b/library/cpp/openssl/holders/holder.h @@ -0,0 +1,32 @@ +#pragma once + +#include <util/generic/yexception.h> + +namespace NOpenSSL { + +template <typename TType, auto Create, auto Destroy, class... Args> +class THolder { +public: + inline THolder(Args... args) { + Ptr = Create(args...); + if (!Ptr) { + throw std::bad_alloc(); + } + } + + THolder(const THolder&) = delete; + THolder& operator=(const THolder&) = delete; + + inline ~THolder() noexcept { + Destroy(Ptr); + } + + inline operator TType* () noexcept { + return Ptr; + } + +private: + TType* Ptr; +}; + +} diff --git a/library/cpp/openssl/holders/ut/evp_ut.cpp b/library/cpp/openssl/holders/ut/evp_ut.cpp new file mode 100644 index 0000000000..0f8c0aed01 --- /dev/null +++ b/library/cpp/openssl/holders/ut/evp_ut.cpp @@ -0,0 +1,15 @@ +#include "evp.h" + +#include <library/cpp/testing/unittest/registar.h> + +Y_UNIT_TEST_SUITE(Evp) { + Y_UNIT_TEST(Cipher) { + NOpenSSL::TEvpCipherCtx ctx; + UNIT_ASSERT(ctx); + } + + Y_UNIT_TEST(Md) { + NOpenSSL::TEvpMdCtx ctx; + UNIT_ASSERT(ctx); + } +} diff --git a/library/cpp/openssl/holders/ut/hmac_ut.cpp b/library/cpp/openssl/holders/ut/hmac_ut.cpp new file mode 100644 index 0000000000..60f561c337 --- /dev/null +++ b/library/cpp/openssl/holders/ut/hmac_ut.cpp @@ -0,0 +1,10 @@ +#include "hmac.h" + +#include <library/cpp/testing/unittest/registar.h> + +Y_UNIT_TEST_SUITE(Hmac) { + Y_UNIT_TEST(Ctx) { + NOpenSSL::THmacCtx ctx; + UNIT_ASSERT(ctx); + } +} diff --git a/library/cpp/openssl/holders/ut/ya.make b/library/cpp/openssl/holders/ut/ya.make new file mode 100644 index 0000000000..045cdc3566 --- /dev/null +++ b/library/cpp/openssl/holders/ut/ya.make @@ -0,0 +1,10 @@ +UNITTEST_FOR(library/cpp/openssl/holders) + +OWNER(somov deshevoy) + +SRCS( + evp_ut.cpp + hmac_ut.cpp +) + +END() diff --git a/library/cpp/openssl/holders/x509_vfy.cpp b/library/cpp/openssl/holders/x509_vfy.cpp new file mode 100644 index 0000000000..731baa9055 --- /dev/null +++ b/library/cpp/openssl/holders/x509_vfy.cpp @@ -0,0 +1,30 @@ +#include "x509_vfy.h" + +namespace NOpenSSL { + + TX509LookupMethod::TX509LookupMethod( + const char* name, + int (*newItem) (X509_LOOKUP *ctx), + void (*free) (X509_LOOKUP *ctx), + int (*init) (X509_LOOKUP *ctx), + int (*shutdown) (X509_LOOKUP *ctx), + X509_LOOKUP_ctrl_fn ctrl, + X509_LOOKUP_get_by_subject_fn getBySubject, + X509_LOOKUP_get_by_issuer_serial_fn getByIssuerSerial, + X509_LOOKUP_get_by_fingerprint_fn getByFingerprint, + X509_LOOKUP_get_by_alias_fn getByAlias + ) + : THolder(name) + { + X509_LOOKUP_meth_set_new_item(*this, newItem); + X509_LOOKUP_meth_set_free(*this, free); + X509_LOOKUP_meth_set_init(*this, init); + X509_LOOKUP_meth_set_shutdown(*this, shutdown); + X509_LOOKUP_meth_set_ctrl(*this, ctrl); + X509_LOOKUP_meth_set_get_by_subject(*this, getBySubject); + X509_LOOKUP_meth_set_get_by_issuer_serial(*this, getByIssuerSerial); + X509_LOOKUP_meth_set_get_by_fingerprint(*this, getByFingerprint); + X509_LOOKUP_meth_set_get_by_alias(*this, getByAlias); + } + +} // namespace NOpenSSL diff --git a/library/cpp/openssl/holders/x509_vfy.h b/library/cpp/openssl/holders/x509_vfy.h new file mode 100644 index 0000000000..b735d8a042 --- /dev/null +++ b/library/cpp/openssl/holders/x509_vfy.h @@ -0,0 +1,25 @@ +#pragma once + +#include <contrib/libs/openssl/include/openssl/x509_vfy.h> + +#include <library/cpp/openssl/holders/holder.h> + +namespace NOpenSSL { + +class TX509LookupMethod : public THolder<X509_LOOKUP_METHOD, X509_LOOKUP_meth_new, X509_LOOKUP_meth_free, const char*> { +public: + TX509LookupMethod( + const char* name, + int (*newItem) (X509_LOOKUP *ctx), + void (*free) (X509_LOOKUP *ctx), + int (*init) (X509_LOOKUP *ctx), + int (*shutdown) (X509_LOOKUP *ctx), + X509_LOOKUP_ctrl_fn ctrl, + X509_LOOKUP_get_by_subject_fn getBySubject, + X509_LOOKUP_get_by_issuer_serial_fn getByIssuerSerial, + X509_LOOKUP_get_by_fingerprint_fn getByFingerprint, + X509_LOOKUP_get_by_alias_fn getByAlias + ); +}; + +} // namespace NOpenSSL diff --git a/library/cpp/openssl/holders/ya.make b/library/cpp/openssl/holders/ya.make new file mode 100644 index 0000000000..3a2fbf3ba5 --- /dev/null +++ b/library/cpp/openssl/holders/ya.make @@ -0,0 +1,16 @@ +LIBRARY() + +OWNER(somov deshevoy) + +PEERDIR( + contrib/libs/openssl +) + +SRCS( + bio.cpp + x509_vfy.cpp +) + +END() + +NEED_CHECK() |