8#include <openssl/dsa.h>
9#include <openssl/pem.h>
10#include "wvsslhacks.h"
25WvDSAKey::WvDSAKey(
struct dsa_st *_dsa,
bool priv)
33 seterr(
"Initializing with a NULL key.. are you insane?");
50WvDSAKey::WvDSAKey(
int bits)
52 dsa = DSA_generate_parameters(bits, NULL, 0, NULL, NULL, NULL, NULL);
53 DSA_generate_key(dsa);
68 return dsa && !errstring;
84 seterr(
"DSA key is not a valid hex string");
88 size_t keylen = keybuf.
used();
89 const unsigned char *key = keybuf.
get(keylen);
94 dsa = wv_d2i_DSAPrivateKey(NULL, &key, keylen);
103 dsa = wv_d2i_DSAPublicKey(NULL, &key, keylen);
106 prv = WvString::null;
111 seterr(
"DSA key is invalid");
118 FILE *fp = tmpfile();
119 const EVP_CIPHER *enc;
123 seterr(
"Unable to open temporary file!");
124 return WvString::null;
129 enc = EVP_get_cipherbyname(
"dsa");
130 PEM_write_DSAPrivateKey(fp, dsa, enc,
131 NULL, 0, NULL, NULL);
144 while ((len = fread(b.
alloc(1024), 1, 1024, fp)) > 0)
154WvString WvDSAKey::hexifypub(
struct dsa_st *dsa)
160 size_t size = i2d_DSAPublicKey(dsa, NULL);
161 unsigned char *key = keybuf.
alloc(size);
162 size_t newsize = i2d_DSAPublicKey(dsa, & key);
163 assert(size == newsize);
164 assert(keybuf.
used() == size);
170WvString WvDSAKey::hexifyprv(
struct dsa_st *dsa)
176 size_t size = i2d_DSAPrivateKey(dsa, NULL);
177 unsigned char *key = keybuf.
alloc(size);
178 size_t newsize = i2d_DSAPrivateKey(dsa, & key);
179 assert(size == newsize);
const T * get(size_t count)
Reads exactly the specified number of elements and returns a pointer to a storage location owned by t...
void unalloc(size_t count)
Unallocates exactly the specified number of elements by removing them from the buffer and releasing t...
T * alloc(size_t count)
Allocates exactly the specified number of elements and returns a pointer to an UNINITIALIZED storage ...
size_t used() const
Returns the number of elements in the buffer currently available for reading.
An DSA public key or public/private key pair that can be used for encryption.
WvString public_str() const
Retrieve the public key as a hexified string.
WvString private_str() const
Retrieve the private key as a hexified string returns WvString::null if there is only a public key.
virtual bool isok() const
By default, returns true if geterr() == 0.
WvString getpem(bool privkey)
Retrieve the public or private key in PEM encoded format.
virtual void seterr(int _errnum)
Set the errnum variable – we have an error.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
WvString is an implementation of a simple and efficient printable-string class.