From c7a17f9a6374c31f2c68f019673166544ed9f6dc Mon Sep 17 00:00:00 2001 From: Marcel Poul Date: Tue, 17 Jan 2012 15:31:47 +0000 Subject: [PATCH] methods for init. and free credential structures --- emi.canl.canl-c/src/canl_cred.c | 50 +++++++++++++++++++++++++++++++++++++++-- emi.canl.canl-c/src/canl_cred.h | 2 +- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/emi.canl.canl-c/src/canl_cred.c b/emi.canl.canl-c/src/canl_cred.c index d0a6c59..a9d4a07 100644 --- a/emi.canl.canl-c/src/canl_cred.c +++ b/emi.canl.canl-c/src/canl_cred.c @@ -4,13 +4,59 @@ canl_err_code CANL_CALLCONV canl_cred_create(canl_ctx ctx, canl_cred * cred) { - return ENOSYS; + glb_ctx *cc = ctx; + creds *crd = NULL; + + if (!ctx) + return EINVAL; + + if (!cred) + return set_error(cc, EINVAL, posix_error, "Cred. handler" + " not initialized" ); + + /*create new cred. handler*/ + crd = (creds *) calloc(1, sizeof(*crd)); + if (crd) + return set_error(cc, ENOMEM, posix_error, "Not enough memory"); + + return 0; } canl_err_code CANL_CALLCONV canl_cred_free(canl_ctx ctx, canl_cred cred) { - return ENOSYS; + glb_ctx *cc = (glb_ctx*) ctx; + creds *crd = (creds*) cred; + + if (!ctx) + return EINVAL; + + if (!cred) + return set_error(cc, EINVAL, posix_error, "Cred. handler" + " not initialized" ); + + /* Delete contents*/ + if (crd->c_key) { + EVP_PKEY_free(crd->c_key); + crd->c_key = NULL; + } + if (crd->c_cert) { + X509_free(crd->c_cert); + crd->c_cert = NULL; + } + if (crd->c_cert_ext) { + X509_EXTENSION_free(crd->c_cert_ext); + crd->c_cert_ext = NULL; + } + if (crd->c_cert_chain) { + sk_X509_pop_free(crd->c_cert_chain, X509_free); + crd->c_cert_chain = NULL; + } + + free (crd); + crd = NULL; + + return 0; } canl_err_code CANL_CALLCONV diff --git a/emi.canl.canl-c/src/canl_cred.h b/emi.canl.canl-c/src/canl_cred.h index aa1ecdb..fd13052 100644 --- a/emi.canl.canl-c/src/canl_cred.h +++ b/emi.canl.canl-c/src/canl_cred.h @@ -18,7 +18,7 @@ typedef enum canl_cert_type { } canl_cert_type; typedef struct _creds { - EVP_PKEY *key; + EVP_PKEY *c_key; STACK_OF(X509) *c_cert_chain; X509 *c_cert; long c_lifetime; -- 1.8.2.3