[pkg-opensc-commit] [libp11] 02/13: Minor code cleanup
Eric Dorland
eric at moszumanska.debian.org
Mon May 22 03:43:00 UTC 2017
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to annotated tag libp11-0.4.5
in repository libp11.
commit 4244fbde232a3bbda463410de79a9f7e6a577f25
Author: Michał Trojnara <Michal.Trojnara at stunnel.org>
Date: Sun Feb 5 18:29:45 2017 +0100
Minor code cleanup
---
src/p11_cert.c | 33 +++++++++++++++------------------
src/p11_key.c | 29 ++++++++++++++---------------
2 files changed, 29 insertions(+), 33 deletions(-)
diff --git a/src/p11_cert.c b/src/p11_cert.c
index b007a5f..f99c11b 100644
--- a/src/p11_cert.c
+++ b/src/p11_cert.c
@@ -147,34 +147,28 @@ static int pkcs11_init_cert(PKCS11_CTX *ctx, PKCS11_TOKEN *token,
(void)ctx;
(void)session;
- size = sizeof(cert_type);
+ /* Ignore unknown certificate types */
+ size = sizeof(CK_CERTIFICATE_TYPE);
if (pkcs11_getattr_var(token, obj, CKA_CERTIFICATE_TYPE, (CK_BYTE *)&cert_type, &size))
return -1;
-
- /* Ignore any certs we don't understand */
if (cert_type != CKC_X_509)
return 0;
+ /* Allocate memory */
+ cpriv = OPENSSL_malloc(sizeof(PKCS11_CERT_private));
+ if (cpriv == NULL)
+ return -1;
+ memset(cpriv, 0, sizeof(PKCS11_CERT_private));
tpriv = PRIVTOKEN(token);
tmp = OPENSSL_realloc(tpriv->certs,
(tpriv->ncerts + 1) * sizeof(PKCS11_CERT));
- if (tmp == NULL) {
- OPENSSL_free(tpriv->certs);
- tpriv->certs = NULL;
+ if (tmp == NULL)
return -1;
- }
tpriv->certs = tmp;
-
cert = tpriv->certs + tpriv->ncerts++;
- memset(cert, 0, sizeof(*cert));
- cpriv = OPENSSL_malloc(sizeof(PKCS11_CERT_private));
- if (cpriv == NULL)
- return -1;
- memset(cpriv, 0, sizeof(PKCS11_CERT_private));
- cert->_private = cpriv;
- cpriv->object = obj;
- cpriv->parent = token;
+ memset(cert, 0, sizeof(PKCS11_CERT));
+ /* Fill public properties */
pkcs11_getattr_alloc(token, obj, CKA_LABEL, (CK_BYTE **)&cert->label, NULL);
size = 0;
if (!pkcs11_getattr_alloc(token, obj, CKA_VALUE, &data, &size)) {
@@ -186,8 +180,11 @@ static int pkcs11_init_cert(PKCS11_CTX *ctx, PKCS11_TOKEN *token,
cert->id_len = 0;
pkcs11_getattr_alloc(token, obj, CKA_ID, &cert->id, &cert->id_len);
- /* Initialize internal information */
- cpriv->id_len = sizeof(cpriv->id);
+ /* Fill private properties */
+ cert->_private = cpriv;
+ cpriv->object = obj;
+ cpriv->parent = token;
+ cpriv->id_len = sizeof cpriv->id;
if (pkcs11_getattr_var(token, obj, CKA_ID, cpriv->id, &cpriv->id_len))
cpriv->id_len = 0;
diff --git a/src/p11_key.c b/src/p11_key.c
index a6090d7..20c00bc 100644
--- a/src/p11_key.c
+++ b/src/p11_key.c
@@ -481,10 +481,10 @@ static int pkcs11_init_key(PKCS11_CTX *ctx, PKCS11_TOKEN *token,
(void)ctx;
(void)session;
- size = sizeof(key_type);
+ /* Ignore unknown key types */
+ size = sizeof(CK_KEY_TYPE);
if (pkcs11_getattr_var(token, obj, CKA_KEY_TYPE, (CK_BYTE *)&key_type, &size))
return -1;
-
switch (key_type) {
case CKK_RSA:
ops = &pkcs11_rsa_ops;
@@ -499,30 +499,29 @@ static int pkcs11_init_key(PKCS11_CTX *ctx, PKCS11_TOKEN *token,
return 0;
}
+ /* Allocate memory */
+ kpriv = OPENSSL_malloc(sizeof(PKCS11_KEY_private));
+ if (kpriv == NULL)
+ return -1;
+ memset(kpriv, 0, sizeof(PKCS11_KEY_private));
tmp = OPENSSL_realloc(keys->keys, (keys->num + 1) * sizeof(PKCS11_KEY));
- if (tmp == NULL) {
- OPENSSL_free(keys->keys);
- keys->keys = NULL;
+ if (tmp == NULL)
return -1;
- }
keys->keys = tmp;
-
key = keys->keys + keys->num++;
memset(key, 0, sizeof(PKCS11_KEY));
- kpriv = OPENSSL_malloc(sizeof(PKCS11_KEY_private));
- if (kpriv)
- memset(kpriv, 0, sizeof(PKCS11_KEY_private));
- key->_private = kpriv;
- kpriv->object = obj;
- kpriv->parent = token;
+ /* Fill public properties */
pkcs11_getattr_alloc(token, obj, CKA_LABEL, (CK_BYTE **)&key->label, NULL);
key->id_len = 0;
pkcs11_getattr_alloc(token, obj, CKA_ID, &key->id, &key->id_len);
key->isPrivate = (type == CKO_PRIVATE_KEY);
- /* Initialize internal information */
- kpriv->id_len = sizeof(kpriv->id);
+ /* Fill private properties */
+ key->_private = kpriv;
+ kpriv->object = obj;
+ kpriv->parent = token;
+ kpriv->id_len = sizeof kpriv->id;
if (pkcs11_getattr_var(token, obj, CKA_ID, kpriv->id, &kpriv->id_len))
kpriv->id_len = 0;
kpriv->ops = ops;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/libp11.git
More information about the pkg-opensc-commit
mailing list