methods for init. and free credential structures
authorMarcel Poul <marcel.poul@cern.ch>
Tue, 17 Jan 2012 15:31:47 +0000 (15:31 +0000)
committerMarcel Poul <marcel.poul@cern.ch>
Tue, 17 Jan 2012 15:31:47 +0000 (15:31 +0000)
emi.canl.canl-c/src/canl_cred.c
emi.canl.canl-c/src/canl_cred.h

index d0a6c59..a9d4a07 100644 (file)
@@ -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
index aa1ecdb..fd13052 100644 (file)
@@ -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;