#include <openssl/engine.h>
#include <string.h>
#include <assert.h>
#include <openssl/ec_key.h>
#include <openssl/err.h>
#include <openssl/mem.h>
#include <openssl/rsa.h>
#include <openssl/thread.h>
#include "../internal.h"
struct engine_st {
RSA_METHOD *rsa_method;
ECDSA_METHOD *ecdsa_method;
};
ENGINE *ENGINE_new(void) {
ENGINE *engine = OPENSSL_malloc(sizeof(ENGINE));
if (engine == NULL) {
return NULL;
}
OPENSSL_memset(engine, 0, sizeof(ENGINE));
return engine;
}
int ENGINE_free(ENGINE *engine) {
OPENSSL_free(engine);
return 1;
}
static int set_method(void **out_member, const void *method, size_t method_size,
size_t compiled_size) {
const struct openssl_method_common_st *common = method;
if (method_size != compiled_size || !common->is_static) {
return 0;
}
*out_member = (void*) method;
return 1;
}
int ENGINE_set_RSA_method(ENGINE *engine, const RSA_METHOD *method,
size_t method_size) {
return set_method((void **)&engine->rsa_method, method, method_size,
sizeof(RSA_METHOD));
}
RSA_METHOD *ENGINE_get_RSA_method(const ENGINE *engine) {
return engine->rsa_method;
}
int ENGINE_set_ECDSA_method(ENGINE *engine, const ECDSA_METHOD *method,
size_t method_size) {
return set_method((void **)&engine->ecdsa_method, method, method_size,
sizeof(ECDSA_METHOD));
}
ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine) {
return engine->ecdsa_method;
}
void METHOD_ref(void *method_in) {
assert(((struct openssl_method_common_st*) method_in)->is_static);
}
void METHOD_unref(void *method_in) {
struct openssl_method_common_st *method = method_in;
if (method == NULL) {
return;
}
assert(method->is_static);
}
OPENSSL_DECLARE_ERROR_REASON(ENGINE, OPERATION_NOT_SUPPORTED)