Fix build error and set version 2.7.1
[platform/upstream/nettle.git] / dsa2sexp.c
1 /* dsa2sexp.c
2  *
3  */
4
5 /* nettle, low-level cryptographics library
6  *
7  * Copyright (C) 2002, 2009 Niels Möller, Magnus Holmgren
8  *  
9  * The nettle library is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or (at your
12  * option) any later version.
13  * 
14  * The nettle library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17  * License for more details.
18  * 
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with the nettle library; see the file COPYING.LIB.  If not, write to
21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22  * MA 02111-1301, USA.
23  */
24
25 #if HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include "dsa.h"
30
31 #include "sexp.h"
32
33 int
34 dsa_keypair_to_sexp(struct nettle_buffer *buffer,
35                     const char *algorithm_name,
36                     const struct dsa_public_key *pub,
37                     const struct dsa_private_key *priv)
38 {
39   if (!algorithm_name)
40     algorithm_name = "dsa";
41   
42   if (priv)
43     return sexp_format(buffer,
44                        "(private-key(%0s(p%b)(q%b)"
45                        "(g%b)(y%b)(x%b)))",
46                        algorithm_name, pub->p, pub->q,
47                        pub->g, pub->y, priv->x);
48   else
49     return sexp_format(buffer,
50                        "(public-key(%0s(p%b)(q%b)"
51                        "(g%b)(y%b)))",
52                        algorithm_name, pub->p, pub->q,
53                        pub->g, pub->y);
54 }