~noskcaj/ubuntu/vivid/gnome-keyring/3.15.90

« back to all changes in this revision

Viewing changes to pkcs11/gkm/tests/unit-test-data-asn1.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-14 22:13:02 UTC
  • mfrom: (1.3.1)
  • mto: (80.2.8 experimental) (1.1.77)
  • mto: This revision was merged to the branch mainline in revision 148.
  • Revision ID: package-import@ubuntu.com-20120514221302-0l3gjmqpe6xopond
ImportĀ upstreamĀ versionĀ 3.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
 
/* unit-test-data-asn1.c: Test ASN.1 routines
3
 
 
4
 
   Copyright (C) 2007 Stefan Walter
5
 
 
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.
10
 
 
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.
15
 
 
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.
20
 
 
21
 
   Author: Stef Walter <stef@memberwebs.com>
22
 
*/
23
 
 
24
 
#include "config.h"
25
 
 
26
 
#include "test-suite.h"
27
 
 
28
 
#include "gkm/gkm-data-asn1.h"
29
 
 
30
 
#include <glib.h>
31
 
#include <gcrypt.h>
32
 
 
33
 
#include <stdlib.h>
34
 
#include <stdio.h>
35
 
#include <string.h>
36
 
 
37
 
#include "egg/egg-asn1x.h"
38
 
#include "egg/egg-asn1-defs.h"
39
 
 
40
 
#include "asn1-def-test.h"
41
 
 
42
 
static GNode *asn1_cert = NULL;
43
 
static guchar *data_cert = NULL;
44
 
static gsize n_data_cert = 0;
45
 
 
46
 
TESTING_SETUP(asn1_tree)
47
 
{
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);
50
 
        g_assert (asn1_cert);
51
 
}
52
 
 
53
 
TESTING_TEARDOWN(asn1_tree)
54
 
{
55
 
        egg_asn1x_destroy (asn1_cert);
56
 
        g_free (data_cert);
57
 
        data_cert = NULL;
58
 
}
59
 
 
60
 
TESTING_TEST(asn1_integers)
61
 
{
62
 
        GNode *asn;
63
 
        gcry_mpi_t mpi, mpt;
64
 
        guchar *data;
65
 
        gsize n_data;
66
 
        gboolean ret;
67
 
 
68
 
        asn = egg_asn1x_create (test_asn1_tab, "TestIntegers");
69
 
        g_assert ("asn test structure is null" && asn != NULL);
70
 
 
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);
75
 
 
76
 
        /* Write the mpi out */
77
 
        ret = gkm_data_asn1_write_mpi (egg_asn1x_node (asn, "mpi", NULL), mpi);
78
 
 
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);
82
 
 
83
 
        egg_asn1x_destroy (asn);
84
 
 
85
 
        /* Now decode it all nicely */
86
 
        asn = egg_asn1x_create_and_decode (test_asn1_tab, "TestIntegers", data, n_data);
87
 
        g_assert (asn);
88
 
 
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);
93
 
 
94
 
        g_free (data);
95
 
}