~ubuntu-branches/ubuntu/hardy/gnutls13/hardy-updates

« back to all changes in this revision

Viewing changes to libextra/openpgp/privkey.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2007-09-29 11:29:22 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070929112922-abqj0gl08kstu27v
Tags: 2.0.1-1
* New upstream version.
* Remove doc/*.info* on clean to allow building thrice in a row.
  (Closes: #441740)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
 
2
 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation
3
3
 *
4
4
 * Author: Nikos Mavroyanopoulos
5
5
 *
35
35
#include <gnutls_cert.h>
36
36
 
37
37
/**
38
 
  * gnutls_openpgp_privkey_init - This function initializes a gnutls_openpgp_privkey_t structure
39
 
  * @key: The structure to be initialized
40
 
  *
41
 
  * This function will initialize an OpenPGP key structure. 
42
 
  *
43
 
  * Returns 0 on success.
44
 
  *
45
 
  **/
 
38
 * gnutls_openpgp_privkey_init - This function initializes a gnutls_openpgp_privkey_t structure
 
39
 * @key: The structure to be initialized
 
40
 *
 
41
 * This function will initialize an OpenPGP key structure. 
 
42
 *
 
43
 * Returns 0 on success.
 
44
 *
 
45
 **/
46
46
int
47
47
gnutls_openpgp_privkey_init (gnutls_openpgp_privkey_t * key)
48
48
{
49
49
  *key = gnutls_calloc (1, sizeof (gnutls_openpgp_privkey_int));
50
50
 
51
51
  if (*key)
52
 
    {
53
 
      return 0;                 /* success */
54
 
    }
 
52
    return 0; /* success */
55
53
  return GNUTLS_E_MEMORY_ERROR;
56
54
}
57
55
 
58
56
/**
59
 
  * gnutls_openpgp_privkey_deinit - This function deinitializes memory used by a gnutls_openpgp_privkey_t structure
60
 
  * @key: The structure to be initialized
61
 
  *
62
 
  * This function will deinitialize a key structure. 
63
 
  *
64
 
  **/
 
57
 * gnutls_openpgp_privkey_deinit - This function deinitializes memory used by a gnutls_openpgp_privkey_t structure
 
58
 * @key: The structure to be initialized
 
59
 *
 
60
 * This function will deinitialize a key structure. 
 
61
 *
 
62
 **/
65
63
void
66
64
gnutls_openpgp_privkey_deinit (gnutls_openpgp_privkey_t key)
67
65
{
73
71
}
74
72
 
75
73
/**
76
 
  * gnutls_openpgp_privkey_import - This function will import a RAW or BASE64 encoded key
77
 
  * @key: The structure to store the parsed key.
78
 
  * @data: The RAW or BASE64 encoded key.
79
 
  * @format: One of gnutls_openpgp_key_fmt_t elements.
80
 
  * @pass: Unused for now
81
 
  * @flags: should be zero
82
 
  *
83
 
  * This function will convert the given RAW or Base64 encoded key
84
 
  * to the native gnutls_openpgp_privkey_t format. The output will be stored in 'key'.
85
 
  *
86
 
  * Returns 0 on success.
87
 
  *
88
 
  **/
 
74
 * gnutls_openpgp_privkey_import - This function will import a RAW or BASE64 encoded key
 
75
 * @key: The structure to store the parsed key.
 
76
 * @data: The RAW or BASE64 encoded key.
 
77
 * @format: One of gnutls_openpgp_key_fmt_t elements.
 
78
 * @pass: Unused for now
 
79
 * @flags: should be zero
 
80
 *
 
81
 * This function will convert the given RAW or Base64 encoded key
 
82
 * to the native gnutls_openpgp_privkey_t format. The output will be stored in 'key'.
 
83
 *
 
84
 * Returns 0 on success.
 
85
 *
 
86
 **/
89
87
int
90
88
gnutls_openpgp_privkey_import (gnutls_openpgp_privkey_t key,
91
89
                               const gnutls_datum_t * data,
94
92
{
95
93
  int rc;
96
94
 
97
 
  rc = _gnutls_openpgp_raw_privkey_to_gkey (&key->pkey, data);
 
95
  rc = _gnutls_openpgp_raw_privkey_to_gkey (&key->pkey, data, format);
98
96
  if (rc)
99
97
    {
100
98
      gnutls_assert ();
104
102
  return 0;
105
103
}
106
104
 
 
105
 
107
106
/**
108
 
  * gnutls_openpgp_privkey_get_pk_algorithm - This function returns the key's PublicKey algorithm
109
 
  * @key: is an OpenPGP key
110
 
  * @bits: if bits is non null it will hold the size of the parameters' in bits
111
 
  *
112
 
  * This function will return the public key algorithm of an OpenPGP
113
 
  * certificate.
114
 
  *
115
 
  * If bits is non null, it should have enough size to hold the parameters
116
 
  * size in bits. For RSA the bits returned is the modulus. 
117
 
  * For DSA the bits returned are of the public exponent.
118
 
  *
119
 
  * Returns a member of the GNUTLS_PKAlgorithm enumeration on success,
120
 
  * or a negative value on error.
121
 
  *
122
 
  **/
 
107
 * gnutls_openpgp_privkey_get_pk_algorithm - This function returns the key's PublicKey algorithm
 
108
 * @key: is an OpenPGP key
 
109
 * @bits: if bits is non null it will hold the size of the parameters' in bits
 
110
 *
 
111
 * This function will return the public key algorithm of an OpenPGP
 
112
 * certificate.
 
113
 *
 
114
 * If bits is non null, it should have enough size to hold the parameters
 
115
 * size in bits. For RSA the bits returned is the modulus. 
 
116
 * For DSA the bits returned are of the public exponent.
 
117
 *
 
118
 * Returns a member of the GNUTLS_PKAlgorithm enumeration on success,
 
119
 * or a negative value on error.
 
120
 *
 
121
 **/
123
122
gnutls_pk_algorithm_t
124
123
gnutls_openpgp_privkey_get_pk_algorithm (gnutls_openpgp_privkey_t key,
125
124
                                         unsigned int *bits)
134
133
      if (pk == GNUTLS_PK_DSA)
135
134
        *bits = _gnutls_mpi_get_nbits (key->pkey.params[3]);
136
135
    }
 
136
  
137
137
  return pk;
138
138
}