aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2009-09-09 16:21:21 +0200
committerMartin Willi <martin@strongswan.org>2009-09-10 16:20:19 +0200
commit30c06407c6d7319a5c4a02ce4ad510ce5e393084 (patch)
tree7328d2470ec255379badfee4e0d955c30d501f55 /src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c
parent1086d00e41108c7c3287af796d04c3fa0a436e33 (diff)
downloadstrongswan-30c06407c6d7319a5c4a02ce4ad510ce5e393084.tar.bz2
strongswan-30c06407c6d7319a5c4a02ce4ad510ce5e393084.tar.xz
Updated openssl plugin to the new builder API
Diffstat (limited to 'src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c')
-rw-r--r--src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c91
1 files changed, 17 insertions, 74 deletions
diff --git a/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c b/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c
index e30ab858b..67c2e47d4 100644
--- a/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c
+++ b/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c
@@ -298,93 +298,36 @@ static private_openssl_rsa_public_key_t *create_empty()
}
/**
- * Load a public key from an ASN1 encoded blob
+ * See header.
*/
-static openssl_rsa_public_key_t *load(chunk_t blob)
+openssl_rsa_public_key_t *openssl_rsa_public_key_load(key_type_t type,
+ va_list args)
{
- u_char *p = blob.ptr;
- private_openssl_rsa_public_key_t *this = create_empty();
+ private_openssl_rsa_public_key_t *this;
+ chunk_t blob;
- this->rsa = d2i_RSAPublicKey(NULL, (const u_char**)&p, blob.len);
- if (!this->rsa)
- {
- destroy(this);
- return NULL;
- }
-
- return &this->public;
-}
-
-typedef struct private_builder_t private_builder_t;
-
-/**
- * Builder implementation for key loading
- */
-struct private_builder_t {
- /** implements the builder interface */
- builder_t public;
- /** loaded public key */
- openssl_rsa_public_key_t *key;
-};
-
-/**
- * Implementation of builder_t.build
- */
-static openssl_rsa_public_key_t *build(private_builder_t *this)
-{
- openssl_rsa_public_key_t *key = this->key;
-
- free(this);
- return key;
-}
-
-/**
- * Implementation of builder_t.add
- */
-static void add(private_builder_t *this, builder_part_t part, ...)
-{
- if (!this->key)
+ while (TRUE)
{
- va_list args;
-
- switch (part)
+ switch (va_arg(args, builder_part_t))
{
case BUILD_BLOB_ASN1_DER:
- {
- va_start(args, part);
- this->key = load(va_arg(args, chunk_t));
- va_end(args);
- return;
- }
- default:
+ blob = va_arg(args, chunk_t);
+ continue;
+ case BUILD_END:
break;
+ default:
+ return NULL;
}
+ break;
}
- if (this->key)
- {
- destroy((private_openssl_rsa_public_key_t*)this->key);
- }
- builder_cancel(&this->public);
-}
-/**
- * Builder construction function
- */
-builder_t *openssl_rsa_public_key_builder(key_type_t type)
-{
- private_builder_t *this;
-
- if (type != KEY_RSA)
+ this = create_empty();
+ this->rsa = d2i_RSAPublicKey(NULL, (const u_char**)&blob.ptr, blob.len);
+ if (!this->rsa)
{
+ destroy(this);
return NULL;
}
-
- this = malloc_thing(private_builder_t);
-
- this->key = NULL;
- this->public.add = (void(*)(builder_t *this, builder_part_t part, ...))add;
- this->public.build = (void*(*)(builder_t *this))build;
-
return &this->public;
}