Skip to content

Commit 0d7a3e0

Browse files
committed
libhashkit/aes: keep API compatible
1 parent b7f446e commit 0d7a3e0

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

include/libhashkit-1.0/hashkit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct hashkit_st {
4949
bool is_allocated : 1;
5050
} options;
5151

52-
void *_cryptographic_context;
52+
void *_key;
5353
};
5454

5555
#ifdef __cplusplus

src/libhashkit/encrypt.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,44 @@
2121

2222
hashkit_string_st *hashkit_encrypt(hashkit_st *kit, const char *source, size_t source_length) {
2323
#ifdef HAVE_OPENSSL_CRYPTO
24-
return aes_encrypt((encryption_context_t *) kit->_cryptographic_context,
24+
return aes_encrypt((encryption_context_t *) kit->_key,
2525
(const unsigned char *) source, source_length);
2626
#else
27-
return aes_encrypt((aes_key_t *) kit->_cryptographic_context, source,
27+
return aes_encrypt((aes_key_t *) kit->_key, source,
2828
source_length);
2929
#endif
3030
}
3131

3232
hashkit_string_st *hashkit_decrypt(hashkit_st *kit, const char *source, size_t source_length) {
3333
#ifdef HAVE_OPENSSL_CRYPTO
34-
return aes_decrypt((encryption_context_t *) kit->_cryptographic_context,
34+
return aes_decrypt((encryption_context_t *) kit->_key,
3535
(const unsigned char *) source, source_length);
3636
#else
37-
return aes_decrypt((aes_key_t *)kit->_cryptographic_context, source, source_length);
37+
return aes_decrypt((aes_key_t *)kit->_key, source, source_length);
3838
#endif
3939
}
4040

4141
#ifdef HAVE_OPENSSL_CRYPTO
4242
bool hashkit_key(hashkit_st *kit, const char *key, const size_t key_length) {
43-
kit->_cryptographic_context = (encryption_context_t *) malloc(sizeof(encryption_context_t));
44-
((encryption_context_t *) kit->_cryptographic_context)->encryption_context = EVP_CIPHER_CTX_new();
45-
((encryption_context_t *) kit->_cryptographic_context)->decryption_context = EVP_CIPHER_CTX_new();
46-
if (((encryption_context_t *) kit->_cryptographic_context)->encryption_context == NULL
47-
|| ((encryption_context_t *) kit->_cryptographic_context)->decryption_context == NULL)
43+
kit->_key = (encryption_context_t *) malloc(sizeof(encryption_context_t));
44+
((encryption_context_t *) kit->_key)->encryption_context = EVP_CIPHER_CTX_new();
45+
((encryption_context_t *) kit->_key)->decryption_context = EVP_CIPHER_CTX_new();
46+
if (((encryption_context_t *) kit->_key)->encryption_context == NULL
47+
|| ((encryption_context_t *) kit->_key)->decryption_context == NULL)
4848
{
4949
return false;
5050
}
5151
return aes_initialize((const unsigned char *) key, key_length,
52-
(encryption_context_t *) kit->_cryptographic_context);
52+
(encryption_context_t *) kit->_key);
5353
}
5454
#else
5555
bool hashkit_key(hashkit_st *kit, const char *key, const size_t key_length) {
56-
if (kit->_cryptographic_context) {
57-
free(kit->_cryptographic_context);
56+
if (kit->_key) {
57+
free(kit->_key);
5858
}
5959

60-
kit->_cryptographic_context = aes_create_key(key, key_length);
60+
kit->_key = aes_create_key(key, key_length);
6161

62-
return bool(kit->_cryptographic_context);
62+
return bool(kit->_key);
6363
}
6464
#endif

src/libhashkit/hashkit.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static inline void _hashkit_init(hashkit_st *self) {
2727
self->distribution_hash.context = NULL;
2828

2929
self->flags.is_base_same_distributed = true;
30-
self->_cryptographic_context = NULL;
30+
self->_key = NULL;
3131
}
3232

3333
static inline hashkit_st *_hashkit_create(hashkit_st *self) {
@@ -66,14 +66,14 @@ static void cryptographic_context_free(encryption_context_t *context) {
6666

6767
void hashkit_free(hashkit_st *self) {
6868
#ifdef HAVE_OPENSSL_CRYPTO
69-
if (self and self->_cryptographic_context) {
70-
cryptographic_context_free((encryption_context_t *)self->_cryptographic_context);
71-
self->_cryptographic_context = NULL;
69+
if (self and self->_key) {
70+
cryptographic_context_free((encryption_context_t *)self->_key);
71+
self->_key = NULL;
7272
}
7373
#else
74-
if (self and self->_cryptographic_context) {
75-
free(self->_cryptographic_context);
76-
self->_cryptographic_context = NULL;
74+
if (self and self->_key) {
75+
free(self->_key);
76+
self->_key = NULL;
7777
}
7878
#endif
7979

@@ -99,19 +99,19 @@ hashkit_st *hashkit_clone(hashkit_st *destination, const hashkit_st *source) {
9999
destination->distribution_hash = source->distribution_hash;
100100
destination->flags = source->flags;
101101
#ifdef HAVE_OPENSSL_CRYPTO
102-
if (destination->_cryptographic_context) {
103-
cryptographic_context_free((encryption_context_t *)destination->_cryptographic_context);
104-
destination->_cryptographic_context = NULL;
102+
if (destination->_key) {
103+
cryptographic_context_free((encryption_context_t *)destination->_key);
104+
destination->_key = NULL;
105105
}
106-
if (source->_cryptographic_context) {
107-
destination->_cryptographic_context =
108-
aes_clone_cryptographic_context(((encryption_context_t *) source->_cryptographic_context));
109-
if (destination->_cryptographic_context) {
106+
if (source->_key) {
107+
destination->_key =
108+
aes_clone_cryptographic_context(((encryption_context_t *) source->_key));
109+
if (destination->_key) {
110110

111111
}
112112
}
113113
#else
114-
destination->_cryptographic_context = aes_clone_key(static_cast<aes_key_t *>(source->_cryptographic_context));
114+
destination->_key = aes_clone_key(static_cast<aes_key_t *>(source->_key));
115115
#endif
116116

117117
return destination;

src/libmemcached/is.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/* These are private */
1919
#define memcached_is_allocated(__object) ((__object)->options.is_allocated)
20-
#define memcached_is_encrypted(__object) (!!(__object)->hashkit._cryptographic_context)
20+
#define memcached_is_encrypted(__object) (!!(__object)->hashkit._key)
2121
#define memcached_is_initialized(__object) ((__object)->options.is_initialized)
2222
#define memcached_is_purging(__object) ((__object)->state.is_purging)
2323
#define memcached_is_processing_input(__object) ((__object)->state.is_processing_input)

0 commit comments

Comments
 (0)