diff options
Diffstat (limited to 'src/libstrongswan/plugins/pgp/pgp_builder.c')
-rw-r--r-- | src/libstrongswan/plugins/pgp/pgp_builder.c | 156 |
1 files changed, 37 insertions, 119 deletions
diff --git a/src/libstrongswan/plugins/pgp/pgp_builder.c b/src/libstrongswan/plugins/pgp/pgp_builder.c index fad8fe10f..5147237c7 100644 --- a/src/libstrongswan/plugins/pgp/pgp_builder.c +++ b/src/libstrongswan/plugins/pgp/pgp_builder.c @@ -357,149 +357,67 @@ static private_key_t *parse_private_key(chunk_t blob) } } -typedef struct private_builder_t private_builder_t; - -/** - * Builder implementation for private/public key loading - */ -struct private_builder_t { - /** implements the builder interface */ - builder_t public; - /** PGP packet 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 *key = NULL; - - switch (this->type) - { - 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 + * See header. */ -static void add_public(private_builder_t *this, builder_part_t part, ...) +public_key_t *pgp_public_key_load(key_type_t type, va_list args) { - va_list args; + chunk_t blob = chunk_empty; - switch (part) + while (TRUE) { - case BUILD_BLOB_PGP: + 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_PGP: + 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 *pgp_public_key_builder(key_type_t type) -{ - private_builder_t *this; - - if (type != KEY_ANY && 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_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 = NULL; - - switch (this->type) + switch (type) { case KEY_ANY: - key = parse_private_key(this->blob); - break; + return parse_public_key(blob); case KEY_RSA: - key = parse_rsa_private_key(this->blob); - break; + return parse_rsa_public_key(blob); default: - break; + return NULL; } - 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 *pgp_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_PGP: + 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_PGP: + 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 *pgp_private_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_private_key(blob); + case KEY_RSA: + return parse_rsa_private_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_private; - this->public.build = (void*(*)(builder_t *this))build_private; - - return &this->public; } |