File: t-dnparser.c

package info (click to toggle)
libksba 0.9.9-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,588 kB
  • ctags: 1,114
  • sloc: ansic: 15,742; sh: 8,833; yacc: 859; makefile: 146; awk: 28
file content (105 lines) | stat: -rw-r--r-- 2,574 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* t-dnparser.c - basic test for the DN parser
 *      Copyright (C) 2002 g10 Code GmbH
 *
 * This file is part of KSBA.
 *
 * KSBA is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * KSBA is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <errno.h>

#include "../src/ksba.h"
#include "../src/convert.h"
#include "t-common.h"



static void
test_1 (void)
{
  static char *empty_elements[] = {
    "C=de,O=foo,OU=,CN=joe",
    "C=de,O=foo,OU= ,CN=joe",
    "C=de,O=foo,OU=\"\" ,CN=joe",
    "C=de,O=foo,OU=",
    "C=de,O=foo,OU= ",
    "C=,O=foo,OU=bar ",
    "C = ,O=foo,OU=bar ",
    "C=",
    NULL
  };
  gpg_error_t err;
  int i;
  char *buf;
  size_t len;

  for (i=0; empty_elements[i]; i++)
    {
      err = _ksba_dn_from_str (empty_elements[i], &buf, &len);
      if (gpg_err_code (err) != GPG_ERR_SYNTAX)
        fail ("empty element not detected");
      xfree (buf);
    }

}



int 
main (int argc, char **argv)
{
  char inputbuf[4096];
  int inputlen;
  char *buf;
  size_t len;
  gpg_error_t err;
  
  if (argc == 2 && !strcmp (argv[1], "--to-str") )
    { /* Read the DER encoed DN from stdin write the string to stdout */
      inputlen = fread (inputbuf, 1, sizeof inputbuf, stdin);
      if (!feof (stdin))
        fail ("read error or input too large");
      
      fail ("no yet implemented");

    }
  else if (argc == 2 && !strcmp (argv[1], "--to-der") )
    { /* Read the String from stdin write the DER encoding to stdout */
      inputlen = fread (inputbuf, 1, sizeof inputbuf, stdin);
      if (!feof (stdin))
        fail ("read error or input too large");
      
      err = _ksba_dn_from_str (inputbuf, &buf, &len);
      fail_if_err (err);
      fwrite (buf, len, 1, stdout);
    }
  else if (argc == 1)
    {
      test_1 ();
    }
  else
    {
      fprintf (stderr, "usage: t-dnparser [--to-str|--to-der]\n");
      return 1;
    }

  return 0;
}