summaryrefslogtreecommitdiff
path: root/tests/crq_key_id.c
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2008-12-12 12:33:14 +0100
committerSimon Josefsson <simon@josefsson.org>2008-12-12 12:33:14 +0100
commit9db63e16969328657413f40cc4a17a1cfd707558 (patch)
tree44ae0d33f5a5cf4ca2611c19e06042ce9c1d670f /tests/crq_key_id.c
parent238db797344872de583af75a103de0de88f0289f (diff)
downloadgnutls-9db63e16969328657413f40cc4a17a1cfd707558.tar.gz
Indent.
Diffstat (limited to 'tests/crq_key_id.c')
-rw-r--r--tests/crq_key_id.c240
1 files changed, 134 insertions, 106 deletions
diff --git a/tests/crq_key_id.c b/tests/crq_key_id.c
index d8661b6728..65926b5630 100644
--- a/tests/crq_key_id.c
+++ b/tests/crq_key_id.c
@@ -29,116 +29,144 @@
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
-void doit (void)
+void
+doit (void)
{
- gnutls_x509_privkey_t pkey;
- gnutls_x509_crq_t crq;
-
- size_t pkey_key_id_len;
- unsigned char *pkey_key_id = NULL;
-
- size_t crq_key_id_len;
- unsigned char *crq_key_id = NULL;
-
- gnutls_pk_algorithm_t algorithm;
-
- int ret;
-
- ret = gnutls_global_init ();
- if (ret < 0)
- fail ("gnutls_global_init: %d\n", ret);
-
-
- for (algorithm = GNUTLS_PK_RSA; algorithm <= GNUTLS_PK_DSA; algorithm ++) {
-
- ret = gnutls_x509_crq_init (&crq);
- if (ret < 0)
- fail ("gnutls_x509_crq_init: %d\n", ret);
-
- ret = gnutls_x509_privkey_init (&pkey);
- if (ret < 0) {
- fail ("gnutls_x509_privkey_init: %d\n", ret);
- }
-
- ret = gnutls_x509_privkey_generate (pkey, algorithm, 1024, 0);
- if (ret < 0) {
- fail ("gnutls_x509_privkey_generate (rsa): %d\n", ret);
- } else {
- success ("Key[%s] generation ok: %d\n", gnutls_pk_algorithm_get_name(algorithm), ret);
- }
-
- pkey_key_id_len = 0;
- ret = gnutls_x509_privkey_get_key_id (pkey, 0, pkey_key_id, &pkey_key_id_len);
- if (ret != GNUTLS_E_SHORT_MEMORY_BUFFER) {
- fail ("gnutls_x509_privkey_get_key_id incorrectly returns %d\n", ret);
- }
-
- pkey_key_id = malloc(sizeof(unsigned char) * pkey_key_id_len);
- ret = gnutls_x509_privkey_get_key_id (pkey, 0, pkey_key_id, &pkey_key_id_len);
- if (ret != GNUTLS_E_SUCCESS) {
- fail ("gnutls_x509_privkey_get_key_id incorrectly returns %d\n", ret);
- }
-
- ret = gnutls_x509_crq_set_version (crq, 1);
- if (ret < 0){
- fail ("gnutls_x509_crq_set_version: %d\n",ret);
- }
-
- ret = gnutls_x509_crq_set_key (crq, pkey);
- if (ret < 0){
- fail ("gnutls_x509_crq_set_key: %d\n",ret);
- }
-
- ret = gnutls_x509_crq_set_dn_by_oid (crq, GNUTLS_OID_X520_COMMON_NAME,
- 0, "CN-Test", 7);
- if (ret < 0){
- fail ("gnutls_x509_crq_set_dn_by_oid: %d\n",ret);
- }
-
- ret = gnutls_x509_crq_sign(crq, pkey);
- if (ret) {
- fail ("gnutls_x509_crq_sign: %d\n",ret);
- }
-
- crq_key_id_len = 0;
- ret = gnutls_x509_crq_get_key_id (crq, 0, crq_key_id, &crq_key_id_len);
- if (ret != GNUTLS_E_SHORT_MEMORY_BUFFER) {
- fail ("gnutls_x509_crq_get_key_id incorrectly returns %d\n", ret);
- }
-
- crq_key_id = malloc(sizeof(unsigned char) * crq_key_id_len);
- ret = gnutls_x509_crq_get_key_id (crq, 0, crq_key_id, &crq_key_id_len);
- if (ret != GNUTLS_E_SUCCESS) {
- fail ("gnutls_x509_crq_get_key_id incorrectly returns %d\n", ret);
- }
-
- if (crq_key_id_len == pkey_key_id_len) {
- ret = memcmp (crq_key_id, pkey_key_id, crq_key_id_len);
- if (ret == 0) {
- success ("Key ids are identical. OK.\n");
- } else {
- fail ("Key ids differ incorrectly: %d\n", ret);
- }
- } else {
- fail ("Key_id lengths differ incorrectly: %d - %d\n", crq_key_id_len, pkey_key_id_len);
- }
-
-
- if (pkey_key_id) {
- free (pkey_key_id);
- pkey_key_id = NULL;
- }
-
- if (crq_key_id) {
- free (crq_key_id);
- crq_key_id = NULL;
- }
-
- gnutls_x509_crq_deinit (crq);
- gnutls_x509_privkey_deinit (pkey);
+ gnutls_x509_privkey_t pkey;
+ gnutls_x509_crq_t crq;
+ size_t pkey_key_id_len;
+ unsigned char *pkey_key_id = NULL;
+
+ size_t crq_key_id_len;
+ unsigned char *crq_key_id = NULL;
+
+ gnutls_pk_algorithm_t algorithm;
+
+ int ret;
+
+ ret = gnutls_global_init ();
+ if (ret < 0)
+ fail ("gnutls_global_init: %d\n", ret);
+
+
+ for (algorithm = GNUTLS_PK_RSA; algorithm <= GNUTLS_PK_DSA; algorithm++)
+ {
+
+ ret = gnutls_x509_crq_init (&crq);
+ if (ret < 0)
+ fail ("gnutls_x509_crq_init: %d\n", ret);
+
+ ret = gnutls_x509_privkey_init (&pkey);
+ if (ret < 0)
+ {
+ fail ("gnutls_x509_privkey_init: %d\n", ret);
+ }
+
+ ret = gnutls_x509_privkey_generate (pkey, algorithm, 1024, 0);
+ if (ret < 0)
+ {
+ fail ("gnutls_x509_privkey_generate (rsa): %d\n", ret);
+ }
+ else
+ {
+ success ("Key[%s] generation ok: %d\n",
+ gnutls_pk_algorithm_get_name (algorithm), ret);
+ }
+
+ pkey_key_id_len = 0;
+ ret = gnutls_x509_privkey_get_key_id (pkey, 0, pkey_key_id,
+ &pkey_key_id_len);
+ if (ret != GNUTLS_E_SHORT_MEMORY_BUFFER)
+ {
+ fail ("gnutls_x509_privkey_get_key_id incorrectly returns %d\n",
+ ret);
+ }
+
+ pkey_key_id = malloc (sizeof (unsigned char) * pkey_key_id_len);
+ ret = gnutls_x509_privkey_get_key_id (pkey, 0, pkey_key_id,
+ &pkey_key_id_len);
+ if (ret != GNUTLS_E_SUCCESS)
+ {
+ fail ("gnutls_x509_privkey_get_key_id incorrectly returns %d\n",
+ ret);
+ }
+
+ ret = gnutls_x509_crq_set_version (crq, 1);
+ if (ret < 0)
+ {
+ fail ("gnutls_x509_crq_set_version: %d\n", ret);
+ }
+
+ ret = gnutls_x509_crq_set_key (crq, pkey);
+ if (ret < 0)
+ {
+ fail ("gnutls_x509_crq_set_key: %d\n", ret);
}
+ ret = gnutls_x509_crq_set_dn_by_oid (crq, GNUTLS_OID_X520_COMMON_NAME,
+ 0, "CN-Test", 7);
+ if (ret < 0)
+ {
+ fail ("gnutls_x509_crq_set_dn_by_oid: %d\n", ret);
+ }
+
+ ret = gnutls_x509_crq_sign (crq, pkey);
+ if (ret)
+ {
+ fail ("gnutls_x509_crq_sign: %d\n", ret);
+ }
+
+ crq_key_id_len = 0;
+ ret = gnutls_x509_crq_get_key_id (crq, 0, crq_key_id, &crq_key_id_len);
+ if (ret != GNUTLS_E_SHORT_MEMORY_BUFFER)
+ {
+ fail ("gnutls_x509_crq_get_key_id incorrectly returns %d\n", ret);
+ }
+
+ crq_key_id = malloc (sizeof (unsigned char) * crq_key_id_len);
+ ret = gnutls_x509_crq_get_key_id (crq, 0, crq_key_id, &crq_key_id_len);
+ if (ret != GNUTLS_E_SUCCESS)
+ {
+ fail ("gnutls_x509_crq_get_key_id incorrectly returns %d\n", ret);
+ }
+
+ if (crq_key_id_len == pkey_key_id_len)
+ {
+ ret = memcmp (crq_key_id, pkey_key_id, crq_key_id_len);
+ if (ret == 0)
+ {
+ success ("Key ids are identical. OK.\n");
+ }
+ else
+ {
+ fail ("Key ids differ incorrectly: %d\n", ret);
+ }
+ }
+ else
+ {
+ fail ("Key_id lengths differ incorrectly: %d - %d\n",
+ crq_key_id_len, pkey_key_id_len);
+ }
+
+
+ if (pkey_key_id)
+ {
+ free (pkey_key_id);
+ pkey_key_id = NULL;
+ }
+
+ if (crq_key_id)
+ {
+ free (crq_key_id);
+ crq_key_id = NULL;
+ }
+
+ gnutls_x509_crq_deinit (crq);
+ gnutls_x509_privkey_deinit (pkey);
+
+ }
+
gnutls_global_deinit ();
}