aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2009-09-09 16:23:26 +0200
committerMartin Willi <martin@strongswan.org>2009-09-10 16:20:20 +0200
commit872176d350d16d6c6785f11ec366de3b13efcf74 (patch)
tree536b661e66f8e626faa89bae46516a80176287f6
parent43224e9527eda958214196693901dc111f29c0e8 (diff)
downloadstrongswan-872176d350d16d6c6785f11ec366de3b13efcf74.tar.bz2
strongswan-872176d350d16d6c6785f11ec366de3b13efcf74.tar.xz
Updated pkcs1 plugin to the new builder API
-rw-r--r--src/libstrongswan/plugins/pkcs1/pkcs1_builder.c148
-rw-r--r--src/libstrongswan/plugins/pkcs1/pkcs1_builder.h17
-rw-r--r--src/libstrongswan/plugins/pkcs1/pkcs1_plugin.c10
3 files changed, 49 insertions, 126 deletions
diff --git a/src/libstrongswan/plugins/pkcs1/pkcs1_builder.c b/src/libstrongswan/plugins/pkcs1/pkcs1_builder.c
index 0213076f9..81730e5ea 100644
--- a/src/libstrongswan/plugins/pkcs1/pkcs1_builder.c
+++ b/src/libstrongswan/plugins/pkcs1/pkcs1_builder.c
@@ -239,139 +239,59 @@ end:
BUILD_RSA_EXP2, exp2, BUILD_RSA_COEFF, coeff, BUILD_END);
}
-typedef struct private_builder_t private_builder_t;
-
/**
- * Builder implementation for private/public key loading
+ * See header.
*/
-struct private_builder_t {
- /** implements the builder interface */
- builder_t public;
- /** asn1 der encoded data */
- chunk_t blob;
- /** type of key to build */
- key_type_t type;
-};
-
-/**
- * Implementation of builder_t.build for public keys
- */
-static public_key_t *build_public(private_builder_t *this)
+public_key_t *pkcs1_public_key_load(key_type_t type, va_list args)
{
- public_key_t *key = NULL;
+ chunk_t blob = chunk_empty;
- switch (this->type)
+ while (TRUE)
{
- case KEY_ANY:
- key = parse_public_key(this->blob);
- break;
- case KEY_RSA:
- key = parse_rsa_public_key(this->blob);
- break;
- default:
- break;
- }
- free(this);
- return key;
-}
-
-/**
- * Implementation of builder_t.add for public keys
- */
-static void add_public(private_builder_t *this, builder_part_t part, ...)
-{
- va_list args;
-
- switch (part)
- {
- case BUILD_BLOB_ASN1_DER:
+ switch (va_arg(args, builder_part_t))
{
- va_start(args, part);
- this->blob = va_arg(args, chunk_t);
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ blob = va_arg(args, chunk_t);
+ continue;
+ case BUILD_END:
+ break;
+ default:
+ return NULL;
}
- default:
- builder_cancel(&this->public);
- break;
+ break;
}
-}
-
-/**
- * Builder construction function for public keys
- */
-builder_t *pkcs1_public_key_builder(key_type_t type)
-{
- private_builder_t *this;
-
- if (type != KEY_ANY && type != KEY_RSA)
+ switch (type)
{
- return NULL;
+ case KEY_ANY:
+ return parse_public_key(blob);
+ case KEY_RSA:
+ return parse_rsa_public_key(blob);
+ default:
+ return NULL;
}
-
- this = malloc_thing(private_builder_t);
-
- this->blob = chunk_empty;
- this->type = type;
- this->public.add = (void(*)(builder_t *this, builder_part_t part, ...))add_public;
- this->public.build = (void*(*)(builder_t *this))build_public;
-
- return &this->public;
-}
-
-/**
- * Implementation of builder_t.build for private keys
- */
-static private_key_t *build_private(private_builder_t *this)
-{
- private_key_t *key;
-
- key = parse_rsa_private_key(this->blob);
- free(this);
- return key;
}
/**
- * Implementation of builder_t.add for private keys
+ * See header.
*/
-static void add_private(private_builder_t *this, builder_part_t part, ...)
+private_key_t *pkcs1_private_key_load(key_type_t type, va_list args)
{
- va_list args;
+ chunk_t blob = chunk_empty;
- switch (part)
+ while (TRUE)
{
- case BUILD_BLOB_ASN1_DER:
+ switch (va_arg(args, builder_part_t))
{
- va_start(args, part);
- this->blob = va_arg(args, chunk_t);
- va_end(args);
- break;
+ case BUILD_BLOB_ASN1_DER:
+ blob = va_arg(args, chunk_t);
+ continue;
+ case BUILD_END:
+ break;
+ default:
+ return NULL;
}
- default:
- builder_cancel(&this->public);
- break;
+ break;
}
-}
-
-/**
- * Builder construction function for private keys
- */
-builder_t *pkcs1_private_key_builder(key_type_t type)
-{
- private_builder_t *this;
-
- if (type != KEY_RSA)
- {
- return NULL;
- }
-
- this = malloc_thing(private_builder_t);
-
- this->blob = chunk_empty;
- this->type = type;
- this->public.add = (void(*)(builder_t *this, builder_part_t part, ...))add_private;
- this->public.build = (void*(*)(builder_t *this))build_private;
-
- return &this->public;
+ return parse_rsa_private_key(blob);
}
diff --git a/src/libstrongswan/plugins/pkcs1/pkcs1_builder.h b/src/libstrongswan/plugins/pkcs1/pkcs1_builder.h
index fdc802587..a4a780b5f 100644
--- a/src/libstrongswan/plugins/pkcs1/pkcs1_builder.h
+++ b/src/libstrongswan/plugins/pkcs1/pkcs1_builder.h
@@ -21,22 +21,25 @@
#ifndef PKCS1_BUILDER_H_
#define PKCS1_BUILDER_H_
-#include <credentials/keys/public_key.h>
+#include <credentials/builder.h>
+#include <credentials/keys/private_key.h>
/**
- * Create the builder for a generic or an RSA public key.
+ * Load a generic or an RSA public key from PKCS#1 data.
*
* @param type type of the key, either KEY_ANY or KEY_RSA
- * @return builder instance
+ * @param args builder_part_t argument list
+ * @return public key, NULL on failure
*/
-builder_t *pkcs1_public_key_builder(key_type_t type);
+public_key_t *pkcs1_public_key_load(key_type_t type, va_list args);
/**
- * Create the builder for a RSA private key.
+ * Load a RSA public key from PKCS#1 data.
*
* @param type type of the key, KEY_RSA
- * @return builder instance
+ * @param args builder_part_t argument list
+ * @return private key, NULL on failure
*/
-builder_t *pkcs1_private_key_builder(key_type_t type);
+private_key_t *pkcs1_private_key_load(key_type_t type, va_list args);
#endif /** PKCS1_BUILDER_H_ @}*/
diff --git a/src/libstrongswan/plugins/pkcs1/pkcs1_plugin.c b/src/libstrongswan/plugins/pkcs1/pkcs1_plugin.c
index d0ca8564b..9d71e1388 100644
--- a/src/libstrongswan/plugins/pkcs1/pkcs1_plugin.c
+++ b/src/libstrongswan/plugins/pkcs1/pkcs1_plugin.c
@@ -38,9 +38,9 @@ struct private_pkcs1_plugin_t {
static void destroy(private_pkcs1_plugin_t *this)
{
lib->creds->remove_builder(lib->creds,
- (builder_constructor_t)pkcs1_public_key_builder);
+ (builder_function_t)pkcs1_public_key_load);
lib->creds->remove_builder(lib->creds,
- (builder_constructor_t)pkcs1_private_key_builder);
+ (builder_function_t)pkcs1_private_key_load);
lib->encoding->remove_encoder(lib->encoding, pkcs1_encoder_encode);
@@ -57,11 +57,11 @@ plugin_t *plugin_create()
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
- (builder_constructor_t)pkcs1_public_key_builder);
+ (builder_function_t)pkcs1_public_key_load);
lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
- (builder_constructor_t)pkcs1_public_key_builder);
+ (builder_function_t)pkcs1_public_key_load);
lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
- (builder_constructor_t)pkcs1_private_key_builder);
+ (builder_function_t)pkcs1_private_key_load);
lib->encoding->add_encoder(lib->encoding, pkcs1_encoder_encode);