gcrypt uses component builder to build public- from private-key

This commit is contained in:
Martin Willi 2009-08-18 09:47:41 +02:00
parent b457e08fca
commit 8380503168
2 changed files with 12 additions and 37 deletions

View File

@ -55,11 +55,6 @@ struct private_gcrypt_rsa_private_key_t {
refcount_t ref;
};
/**
* Implemented in gcrypt_rsa_public_key.c
*/
public_key_t *gcrypt_rsa_public_key_create_from_sexp(gcry_sexp_t key);
/**
* find a token in a S-expression. If a key is given, its length is used to
* pad the output to a given length.
@ -320,7 +315,18 @@ static identification_t* get_id(private_gcrypt_rsa_private_key_t *this,
*/
static public_key_t* get_public_key(private_gcrypt_rsa_private_key_t *this)
{
return gcrypt_rsa_public_key_create_from_sexp(this->key);
chunk_t n, e;
public_key_t *public;
n = gcrypt_rsa_find_token(this->key, "n", NULL);
e = gcrypt_rsa_find_token(this->key, "e", NULL);
public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
BUILD_RSA_MODULUS, n, BUILD_RSA_PUB_EXP, e, BUILD_END);
chunk_free(&n);
chunk_free(&e);
return public;
}
/**

View File

@ -343,37 +343,6 @@ static private_gcrypt_rsa_public_key_t *gcrypt_rsa_public_key_create_empty()
return this;
}
/**
* Create a public key from a S-expression, used in gcrypt_rsa_private_key
*/
public_key_t *gcrypt_rsa_public_key_create_from_sexp(gcry_sexp_t key)
{
private_gcrypt_rsa_public_key_t *this;
gcry_error_t err;
chunk_t n, e;
this = gcrypt_rsa_public_key_create_empty();
n = gcrypt_rsa_find_token(key, "n", NULL);
e = gcrypt_rsa_find_token(key, "e", NULL);
err = gcry_sexp_build(&this->key, NULL, "(public-key(rsa(n %b)(e %b)))",
n.len, n.ptr, e.len, e.ptr);
chunk_free(&n);
chunk_free(&e);
if (err)
{
DBG1("loading public key failed: %s", gpg_strerror(err));
free(this);
return NULL;
}
if (!gcrypt_rsa_build_keyids(this->key, &this->keyid, &this->keyid_info))
{
destroy(this);
return NULL;
}
return &this->public.interface;
}
/**
* Load a public key from components
*/