1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
/* unit-test-data-asn1.c: Test ASN.1 routines
4
Copyright (C) 2007 Stefan Walter
6
The Gnome Keyring Library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public License as
8
published by the Free Software Foundation; either version 2 of the
9
License, or (at your option) any later version.
11
The Gnome Keyring Library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public
17
License along with the Gnome Library; see the file COPYING.LIB. If not,
18
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
21
Author: Stef Walter <stef@memberwebs.com>
26
#include "test-suite.h"
28
#include "gkm/gkm-data-asn1.h"
37
#include "egg/egg-asn1x.h"
38
#include "egg/egg-asn1-defs.h"
40
#include "asn1-def-test.h"
42
static GNode *asn1_cert = NULL;
43
static guchar *data_cert = NULL;
44
static gsize n_data_cert = 0;
46
TESTING_SETUP(asn1_tree)
48
data_cert = testing_data_read ("test-certificate-1.der", &n_data_cert);
49
asn1_cert = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", data_cert, n_data_cert);
53
TESTING_TEARDOWN(asn1_tree)
55
egg_asn1x_destroy (asn1_cert);
60
TESTING_TEST(asn1_integers)
68
asn = egg_asn1x_create (test_asn1_tab, "TestIntegers");
69
g_assert ("asn test structure is null" && asn != NULL);
71
/* Make a random number */
72
mpi = gcry_mpi_new (512);
73
g_return_if_fail (mpi);
74
gcry_mpi_randomize (mpi, 512, GCRY_WEAK_RANDOM);
76
/* Write the mpi out */
77
ret = gkm_data_asn1_write_mpi (egg_asn1x_node (asn, "mpi", NULL), mpi);
79
/* Now encode the whole caboodle */
80
data = egg_asn1x_encode (asn, NULL, &n_data);
81
g_assert ("encoding asn1 didn't work" && data != NULL);
83
egg_asn1x_destroy (asn);
85
/* Now decode it all nicely */
86
asn = egg_asn1x_create_and_decode (test_asn1_tab, "TestIntegers", data, n_data);
89
ret = gkm_data_asn1_read_mpi (egg_asn1x_node (asn, "mpi", NULL), &mpt);
90
g_assert ("couldn't read mpi from asn1" && ret);
91
g_assert ("mpi returned is null" && mpt != NULL);
92
g_assert ("mpi is wrong number" && gcry_mpi_cmp (mpi, mpt) == 0);