diff options
author | Graham Leggett <minfrin@apache.org> | 2009-12-15 00:28:46 +0000 |
---|---|---|
committer | Graham Leggett <minfrin@apache.org> | 2009-12-15 00:28:46 +0000 |
commit | 38d37b77afd6a9d4aa6efc3b2a69eac6a09ef5c6 (patch) | |
tree | 9e7382987e253fad0c9feec1e2a38fd24998c708 /crypto/apr_crypto_openssl.c | |
parent | 8ca571e887101acb02429c496ffd7d855951e8dc (diff) | |
download | apr-38d37b77afd6a9d4aa6efc3b2a69eac6a09ef5c6.tar.gz |
Refactor the apr_crypto.h interface so that the apr_crypto_t structure
remains private. Correctly reference the apr_crypto_t context as a context
and not a factory.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@890579 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'crypto/apr_crypto_openssl.c')
-rw-r--r-- | crypto/apr_crypto_openssl.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/crypto/apr_crypto_openssl.c b/crypto/apr_crypto_openssl.c index a9dda907a..6870d965f 100644 --- a/crypto/apr_crypto_openssl.c +++ b/crypto/apr_crypto_openssl.c @@ -36,6 +36,13 @@ #define LOG_PREFIX "apr_crypto_openssl: " +struct apr_crypto_t { + apr_pool_t *pool; + apu_err_t *result; + apr_array_header_t *keys; + apr_crypto_config_t *config; +}; + struct apr_crypto_config_t { ENGINE *engine; }; @@ -49,7 +56,7 @@ struct apr_crypto_key_t { }; struct apr_crypto_block_t { - const apr_crypto_t *factory; + const apr_crypto_t *f; apr_pool_t *pool; EVP_CIPHER_CTX cipherCtx; int initialised; @@ -59,6 +66,14 @@ struct apr_crypto_block_t { }; /** + * Fetch the most recent error from this driver. + */ +static apr_status_t crypto_error(const apr_crypto_t *f, const apu_err_t **result) { + *result = f->result; + return APR_SUCCESS; +} + +/** * Shutdown the crypto library and release resources. */ static apr_status_t crypto_shutdown(apr_pool_t *pool) { @@ -115,10 +130,10 @@ static apr_status_t crypto_block_cleanup_helper(void *data) { } /** - * @brief Clean encryption / decryption factory. - * @note After cleanup, a factory is free to be reused if necessary. + * @brief Clean encryption / decryption context. + * @note After cleanup, a context is free to be reused if necessary. * @param driver - driver to use - * @param f The factory to use. + * @param f The context to use. * @return Returns APR_ENOTIMPL if not supported. */ static apr_status_t crypto_cleanup(apr_crypto_t *f) { @@ -145,12 +160,12 @@ static apr_status_t crypto_cleanup_helper(void *data) { * @param driver - driver to use * @param pool - process pool * @param params - array of key parameters - * @param factory - factory pointer will be written here + * @param context - context pointer will be written here * @return APR_ENOENGINE when the engine specified does not exist. APR_EINITENGINE * if the engine cannot be initialised. */ -static apr_status_t crypto_factory(apr_pool_t *pool, - const apr_array_header_t *params, apr_crypto_t **factory) { +static apr_status_t crypto_make(apr_pool_t *pool, + const apr_array_header_t *params, apr_crypto_t **ff) { apr_crypto_config_t *config = NULL; struct apr_crypto_param_t *ents = params ? (struct apr_crypto_param_t *) params->elts : NULL; @@ -159,7 +174,7 @@ static apr_status_t crypto_factory(apr_pool_t *pool, if (!f) { return APR_ENOMEM; } - *factory = f; + *ff = f; f->pool = pool; config = f->config = apr_pcalloc(pool, sizeof(apr_crypto_config_t)); if (!config) { @@ -318,7 +333,7 @@ static apr_status_t crypto_passphrase(apr_pool_t *p, const apr_crypto_t *f, * @note If *ctx is NULL, a apr_crypto_block_t will be created from a pool. If * *ctx is not NULL, *ctx must point at a previously created structure. * @param p The pool to use. - * @param f The block factory to use. + * @param f The block context to use. * @param type 3DES_192, AES_128, AES_192, AES_256. * @param mode Electronic Code Book / Cipher Block Chaining. * @param key The key @@ -344,7 +359,7 @@ static apr_status_t crypto_block_encrypt_init(apr_pool_t *p, if (!block) { return APR_ENOMEM; } - block->factory = f; + block->f = f; block->pool = p; apr_pool_cleanup_register(p, block, crypto_block_cleanup_helper, @@ -487,7 +502,7 @@ static apr_status_t crypto_block_encrypt_finish(apr_crypto_block_t *ctx, * @note If *ctx is NULL, a apr_crypto_block_t will be created from a pool. If * *ctx is not NULL, *ctx must point at a previously created structure. * @param p The pool to use. - * @param f The block factory to use. + * @param f The block context to use. * @param key The key structure. * @param iv Optional initialisation vector. If the buffer pointed to is NULL, * an IV will be created at random, in space allocated from the pool. @@ -510,7 +525,7 @@ static apr_status_t crypto_block_decrypt_init(apr_pool_t *p, if (!block) { return APR_ENOMEM; } - block->factory = f; + block->f = f; block->pool = p; apr_pool_cleanup_register(p, block, crypto_block_cleanup_helper, @@ -640,7 +655,7 @@ static apr_status_t crypto_block_decrypt_finish(apr_crypto_block_t *ctx, * OpenSSL module. */ APU_MODULE_DECLARE_DATA const apr_crypto_driver_t apr_crypto_openssl_driver = { - "openssl", crypto_init, crypto_factory, crypto_passphrase, + "openssl", crypto_init, crypto_error, crypto_make, crypto_passphrase, crypto_block_encrypt_init, crypto_block_encrypt, crypto_block_encrypt_finish, crypto_block_decrypt_init, crypto_block_decrypt, crypto_block_decrypt_finish, |