diff options
author | Martin Willi <martin@strongswan.org> | 2009-08-24 11:12:07 +0200 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2009-08-26 11:23:52 +0200 |
commit | 0dd2defc5ad01b0754b1d377779ee298d5b26f3e (patch) | |
tree | 4bf52d8ba06e0900624f0abb60b2e203f26b3cb6 /src | |
parent | 64e77e8fbbfa9885d6fa3757a8f2b809237af63d (diff) | |
download | strongswan-0dd2defc5ad01b0754b1d377779ee298d5b26f3e.tar.bz2 strongswan-0dd2defc5ad01b0754b1d377779ee298d5b26f3e.tar.xz |
added a seperate chache lookup, as encode() requires arguments expensive to build
Diffstat (limited to 'src')
-rw-r--r-- | src/libstrongswan/credentials/keys/key_encoding.c | 23 | ||||
-rw-r--r-- | src/libstrongswan/credentials/keys/key_encoding.h | 11 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/libstrongswan/credentials/keys/key_encoding.c b/src/libstrongswan/credentials/keys/key_encoding.c index 15ddfffcf..1ffb4241b 100644 --- a/src/libstrongswan/credentials/keys/key_encoding.c +++ b/src/libstrongswan/credentials/keys/key_encoding.c @@ -111,6 +111,28 @@ static bool equals(void *key1, void *key2) } /** + * Implementation of key_encoding_t.get_cache + */ +static bool get_cache(private_key_encoding_t *this, key_encoding_type_t type, + void *cache, chunk_t *encoding) +{ + chunk_t *chunk; + + if (type >= KEY_ENCODING_MAX || type < 0) + { + return FALSE; + } + this->lock->read_lock(this->lock); + chunk = this->cache[type]->get(this->cache[type], cache); + if (chunk) + { + *encoding = *chunk; + } + this->lock->unlock(this->lock); + return !!chunk; +} + +/** * Implementation of key_encoding_t.encode */ static bool encode(private_key_encoding_t *this, key_encoding_type_t type, @@ -239,6 +261,7 @@ key_encoding_t *key_encoding_create() key_encoding_type_t type; this->public.encode = (bool(*)(key_encoding_t*, key_encoding_type_t type, void *cache, chunk_t *encoding, ...))encode; + this->public.get_cache = (bool(*)(key_encoding_t*, key_encoding_type_t type, void *cache, chunk_t *encoding))get_cache; this->public.clear_cache = (void(*)(key_encoding_t*, void *cache))clear_cache; this->public.add_encoder = (void(*)(key_encoding_t*, key_encoder_t encoder))add_encoder; this->public.remove_encoder = (void(*)(key_encoding_t*, key_encoder_t encoder))remove_encoder; diff --git a/src/libstrongswan/credentials/keys/key_encoding.h b/src/libstrongswan/credentials/keys/key_encoding.h index 6556a9e80..a8fbfa65a 100644 --- a/src/libstrongswan/credentials/keys/key_encoding.h +++ b/src/libstrongswan/credentials/keys/key_encoding.h @@ -137,6 +137,17 @@ struct key_encoding_t { void (*clear_cache)(key_encoding_t *this, void *cache); /** + * Check for a cached encoding. + * + * @param type format of the key encoding + * @param cache key to use for caching, as given to encode() + * @encoding encoding result, internal data + * @return TRUE if cache entry found + */ + bool (*get_cache)(key_encoding_t *this, key_encoding_type_t type, + void *cache, chunk_t *encoding); + + /** * Register a key encoder function. * * @param encoder key encoder function to add |