Migrated remaining classes in openssl plugin to INIT/METHOD macros

This commit is contained in:
Martin Willi
2010-08-10 18:46:30 +02:00
parent 646babd354
commit 57202484e4
15 changed files with 257 additions and 358 deletions
@@ -90,27 +90,20 @@ static char* lookup_algorithm(openssl_algorithm_t *openssl_algo,
return NULL;
}
/**
* Implementation of hasher_t.get_hash_size.
*/
static size_t get_hash_size(private_openssl_hasher_t *this)
METHOD(hasher_t, get_hash_size, size_t,
private_openssl_hasher_t *this)
{
return this->hasher->md_size;
}
/**
* Implementation of hasher_t.reset.
*/
static void reset(private_openssl_hasher_t *this)
METHOD(hasher_t, reset, void,
private_openssl_hasher_t *this)
{
EVP_DigestInit_ex(this->ctx, this->hasher, NULL);
}
/**
* Implementation of hasher_t.get_hash.
*/
static void get_hash(private_openssl_hasher_t *this, chunk_t chunk,
u_int8_t *hash)
METHOD(hasher_t, get_hash, void,
private_openssl_hasher_t *this, chunk_t chunk, u_int8_t *hash)
{
EVP_DigestUpdate(this->ctx, chunk.ptr, chunk.len);
if (hash)
@@ -120,11 +113,8 @@ static void get_hash(private_openssl_hasher_t *this, chunk_t chunk,
}
}
/**
* Implementation of hasher_t.allocate_hash.
*/
static void allocate_hash(private_openssl_hasher_t *this, chunk_t chunk,
chunk_t *hash)
METHOD(hasher_t, allocate_hash, void,
private_openssl_hasher_t *this, chunk_t chunk, chunk_t *hash)
{
if (hash)
{
@@ -137,10 +127,8 @@ static void allocate_hash(private_openssl_hasher_t *this, chunk_t chunk,
}
}
/**
* Implementation of hasher_t.destroy.
*/
static void destroy (private_openssl_hasher_t *this)
METHOD(hasher_t, destroy, void,
private_openssl_hasher_t *this)
{
EVP_MD_CTX_destroy(this->ctx);
free(this);
@@ -160,7 +148,15 @@ openssl_hasher_t *openssl_hasher_create(hash_algorithm_t algo)
return NULL;
}
this = malloc_thing(private_openssl_hasher_t);
INIT(this,
.public.hasher = {
.get_hash = _get_hash,
.allocate_hash = _allocate_hash,
.get_hash_size = _get_hash_size,
.reset = _reset,
.destroy = _destroy,
},
);
this->hasher = EVP_get_digestbyname(name);
if (!this->hasher)
@@ -170,12 +166,6 @@ openssl_hasher_t *openssl_hasher_create(hash_algorithm_t algo)
return NULL;
}
this->public.hasher_interface.get_hash = (void (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
this->public.hasher_interface.allocate_hash = (void (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
this->public.hasher_interface.get_hash_size = (size_t (*) (hasher_t*))get_hash_size;
this->public.hasher_interface.reset = (void (*) (hasher_t*))reset;
this->public.hasher_interface.destroy = (void (*) (hasher_t*))destroy;
this->ctx = EVP_MD_CTX_create();
/* initialization */