Annotation of embedaddon/strongswan/src/libstrongswan/credentials/credential_factory.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2008 Martin Willi
                      3:  * HSR Hochschule fuer Technik Rapperswil
                      4:  *
                      5:  * This program is free software; you can redistribute it and/or modify it
                      6:  * under the terms of the GNU General Public License as published by the
                      7:  * Free Software Foundation; either version 2 of the License, or (at your
                      8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                      9:  *
                     10:  * This program is distributed in the hope that it will be useful, but
                     11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     13:  * for more details.
                     14:  */
                     15: 
                     16: /**
                     17:  * @defgroup credential_factory credential_factory
                     18:  * @{ @ingroup credentials
                     19:  */
                     20: 
                     21: #ifndef CREDENTIAL_FACTORY_H_
                     22: #define CREDENTIAL_FACTORY_H_
                     23: 
                     24: typedef struct credential_factory_t credential_factory_t;
                     25: typedef enum credential_type_t credential_type_t;
                     26: 
                     27: #include <credentials/builder.h>
                     28: 
                     29: /**
                     30:  * Kind of credential.
                     31:  *
                     32:  * While crypto containers are not really credentials, we still use the
                     33:  * credential factory and builders create them.
                     34:  */
                     35: enum credential_type_t {
                     36:        /** private key, implemented in private_key_t */
                     37:        CRED_PRIVATE_KEY,
                     38:        /** public key, implemented in public_key_t */
                     39:        CRED_PUBLIC_KEY,
                     40:        /** certificates, implemented in certificate_t */
                     41:        CRED_CERTIFICATE,
                     42:        /** crypto container, implemented in container_t */
                     43:        CRED_CONTAINER,
                     44: };
                     45: 
                     46: /**
                     47:  * enum names for credential_type_t
                     48:  */
                     49: extern enum_name_t *credential_type_names;
                     50: 
                     51: /**
                     52:  * Manages credential construction functions and creates instances.
                     53:  */
                     54: struct credential_factory_t {
                     55: 
                     56:        /**
                     57:         * Create a credential using a list of builder_part_t's.
                     58:         *
                     59:         * The variable argument list takes builder_part_t types followed
                     60:         * by the type specific value. The list must be terminated using BUILD_END.
                     61:         * All passed parts get cloned/refcounted by the builder functions,
                     62:         * so free up allocated resources after successful and unsuccessful
                     63:         * invocations.
                     64:         *
                     65:         * @param type                  credential type to build
                     66:         * @param subtype               subtype specific for type of the credential
                     67:         * @param ...                   build_part_t arguments, BUILD_END terminated.
                     68:         * @return                              type specific credential, NULL if failed
                     69:         */
                     70:        void* (*create)(credential_factory_t *this, credential_type_t type,
                     71:                                        int subtype, ...);
                     72: 
                     73:        /**
                     74:         * Register a credential builder function.
                     75:         *
                     76:         * The final flag indicates if the registered builder can build such
                     77:         * a credential itself the most common encoding, without the need
                     78:         * for an additional builder.
                     79:         *
                     80:         * @param type                  type of credential the builder creates
                     81:         * @param subtype               subtype of the credential, type specific
                     82:         * @param final                 TRUE if this build does not invoke other builders
                     83:         * @param constructor   builder constructor function to register
                     84:         */
                     85:        void (*add_builder)(credential_factory_t *this,
                     86:                                                credential_type_t type, int subtype, bool final,
                     87:                                                builder_function_t constructor);
                     88:        /**
                     89:         * Unregister a credential builder function.
                     90:         *
                     91:         * @param constructor   constructor function to unregister.
                     92:         */
                     93:        void (*remove_builder)(credential_factory_t *this,
                     94:                                                   builder_function_t constructor);
                     95: 
                     96:        /**
                     97:         * Create an enumerator over registered builder types.
                     98:         *
                     99:         * The enumerator returns only builder types registered with the final
                    100:         * flag set.
                    101:         *
                    102:         * @return                              enumerator (credential_type_t, int subtype)
                    103:         */
                    104:        enumerator_t* (*create_builder_enumerator)(credential_factory_t *this);
                    105: 
                    106:        /**
                    107:         * Destroy a credential_factory instance.
                    108:         */
                    109:        void (*destroy)(credential_factory_t *this);
                    110: };
                    111: 
                    112: /**
                    113:  * Create a credential_factory instance.
                    114:  */
                    115: credential_factory_t *credential_factory_create();
                    116: 
                    117: #endif /** CREDENTIAL_FACTORY_H_ @}*/

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>