From 35ee7e644d3ab2a81202bc6b018a3a40a40a8edf Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Fri, 20 May 2011 15:12:49 -0700 Subject: [PATCH] ceph_crypto: add assert_init Signed-off-by: Colin McCabe --- src/auth/Crypto.cc | 12 ++++++------ src/common/ceph_crypto.cc | 15 ++++++++++++++- src/common/ceph_crypto.h | 11 +++++------ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/auth/Crypto.cc b/src/auth/Crypto.cc index 757ed791563ee..c435366fbbffc 100644 --- a/src/auth/Crypto.cc +++ b/src/auth/Crypto.cc @@ -23,13 +23,14 @@ # include #endif -#include "include/ceph_fs.h" +#include "common/Clock.h" +#include "common/armor.h" +#include "common/ceph_crypto.h" #include "common/config.h" #include "common/debug.h" -#include "common/armor.h" -#include "common/Clock.h" #include "common/hex.h" #include "common/safe_io.h" +#include "include/ceph_fs.h" #include @@ -57,7 +58,7 @@ static int get_random_bytes(int len, bufferlist& bl) class CryptoNone : public CryptoHandler { public: - CryptoNone() {} + CryptoNone() { } ~CryptoNone() {} int create(bufferptr& secret); int validate_secret(bufferptr& secret); @@ -210,7 +211,7 @@ static int nss_aes_operation(CK_ATTRIBUTE_TYPE op, const bufferptr& secret, cons class CryptoAES : public CryptoHandler { public: - CryptoAES() {} + CryptoAES() { } ~CryptoAES() {} int create(bufferptr& secret); int validate_secret(bufferptr& secret); @@ -348,7 +349,6 @@ int CryptoKey::set_secret(int type, bufferptr& s) CryptoHandler *h = ceph_crypto_mgr.get_crypto(type); if (!h) return -EOPNOTSUPP; - int ret = h->validate_secret(s); if (ret < 0) diff --git a/src/common/ceph_crypto.cc b/src/common/ceph_crypto.cc index b6520d7087426..5ec492ed8ef9d 100644 --- a/src/common/ceph_crypto.cc +++ b/src/common/ceph_crypto.cc @@ -16,7 +16,21 @@ #include +static bool crypto_init = false; + +void ceph::crypto::assert_init() { + assert(crypto_init == true); +} + #ifdef USE_CRYPTOPP +void ceph::crypto::init() { + crypto_init = true; +} + +void ceph::crypto::shutdown() { + crypto_init = false; +} + // nothing ceph::crypto::HMACSHA1::~HMACSHA1() { @@ -25,7 +39,6 @@ ceph::crypto::HMACSHA1::~HMACSHA1() #elif USE_NSS static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; -static bool crypto_init = false; void ceph::crypto::init() { pthread_mutex_lock(&lock); diff --git a/src/common/ceph_crypto.h b/src/common/ceph_crypto.h index 48a5f203cc026..23a058997acac 100644 --- a/src/common/ceph_crypto.h +++ b/src/common/ceph_crypto.h @@ -16,12 +16,10 @@ # include namespace ceph { namespace crypto { - static inline void init() { - // nothing - } - static inline void shutdown() { - // nothing - } + void assert_init(); + void init(); + void shutdown(); + using CryptoPP::Weak::MD5; using CryptoPP::SHA1; using CryptoPP::SHA256; @@ -53,6 +51,7 @@ typedef unsigned char byte; namespace ceph { namespace crypto { + void assert_init(); void init(); void shutdown(); class Digest { -- 2.39.5