aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/pkcs1/pkcs1_builder.c
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 /src/libstrongswan/plugins/pkcs1/pkcs1_builder.c
parent43224e9527eda958214196693901dc111f29c0e8 (diff)
downloadstrongswan-872176d350d16d6c6785f11ec366de3b13efcf74.tar.bz2
strongswan-872176d350d16d6c6785f11ec366de3b13efcf74.tar.xz
Updated pkcs1 plugin to the new builder API
Diffstat (limited to 'src/libstrongswan/plugins/pkcs1/pkcs1_builder.c')
-rw-r--r--src/libstrongswan/plugins/pkcs1/pkcs1_builder.c148
1 files changed, 34 insertions, 114 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);
}