]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-oauth2: Reformat oauth2-key-cache.c.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Fri, 5 Jun 2020 18:50:55 +0000 (20:50 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 7 Dec 2020 08:59:28 +0000 (08:59 +0000)
src/lib-oauth2/oauth2-key-cache.c

index 825d8b030179f704654277745fcd8ae52c9057eb..e85c210842eccca8c02d2d7d08f07ff4b690fbcb 100644 (file)
@@ -16,7 +16,8 @@ struct oauth2_key_cache_entry {
        struct oauth2_key_cache_entry *prev, *next;
 };
 
-HASH_TABLE_DEFINE_TYPE(oauth2_key_cache, const char*, struct oauth2_key_cache_entry*);
+HASH_TABLE_DEFINE_TYPE(oauth2_key_cache, const char *,
+                      struct oauth2_key_cache_entry *);
 
 struct oauth2_validation_key_cache {
        pool_t pool;
@@ -26,15 +27,18 @@ struct oauth2_validation_key_cache {
 
 struct oauth2_validation_key_cache *oauth2_validation_key_cache_init(void)
 {
-       pool_t pool = pool_alloconly_create(MEMPOOL_GROWING"oauth2 key cache", 128);
+       pool_t pool = pool_alloconly_create(
+               MEMPOOL_GROWING"oauth2 key cache", 128);
        struct oauth2_validation_key_cache *cache =
                p_new(pool, struct oauth2_validation_key_cache, 1);
+
        cache->pool = pool;
        hash_table_create(&cache->keys, pool, 8, str_hash, strcmp);
        return cache;
 }
 
-void oauth2_validation_key_cache_deinit(struct oauth2_validation_key_cache **_cache)
+void oauth2_validation_key_cache_deinit(
+       struct oauth2_validation_key_cache **_cache)
 {
        struct oauth2_validation_key_cache *cache = *_cache;
        *_cache = NULL;
@@ -52,13 +56,15 @@ void oauth2_validation_key_cache_deinit(struct oauth2_validation_key_cache **_ca
        pool_unref(&cache->pool);
 }
 
-int oauth2_validation_key_cache_lookup_pubkey(struct oauth2_validation_key_cache *cache,
-                                             const char *key_id,
-                                             struct dcrypt_public_key **pubkey_r)
+int oauth2_validation_key_cache_lookup_pubkey(
+       struct oauth2_validation_key_cache *cache, const char *key_id,
+       struct dcrypt_public_key **pubkey_r)
 {
        if (cache == NULL)
                return -1;
-       struct oauth2_key_cache_entry *entry = hash_table_lookup(cache->keys, key_id);
+
+       struct oauth2_key_cache_entry *entry =
+               hash_table_lookup(cache->keys, key_id);
        if (entry == NULL || entry->pubkey == NULL)
                return -1;
 
@@ -66,13 +72,15 @@ int oauth2_validation_key_cache_lookup_pubkey(struct oauth2_validation_key_cache
        return 0;
 }
 
-int oauth2_validation_key_cache_lookup_hmac_key(struct oauth2_validation_key_cache *cache,
-                                               const char *key_id,
-                                               const buffer_t **hmac_key_r)
+int oauth2_validation_key_cache_lookup_hmac_key(
+       struct oauth2_validation_key_cache *cache, const char *key_id,
+       const buffer_t **hmac_key_r)
 {
        if (cache == NULL)
                return -1;
-       struct oauth2_key_cache_entry *entry = hash_table_lookup(cache->keys, key_id);
+
+       struct oauth2_key_cache_entry *entry =
+               hash_table_lookup(cache->keys, key_id);
        if (entry == NULL || entry->hmac_key == NULL ||
            entry->hmac_key->used == 0)
                return -1;
@@ -81,13 +89,15 @@ int oauth2_validation_key_cache_lookup_hmac_key(struct oauth2_validation_key_cac
        return 0;
 }
 
-void oauth2_validation_key_cache_insert_pubkey(struct oauth2_validation_key_cache *cache,
-                                              const char *key_id,
-                                              struct dcrypt_public_key *pubkey)
+void oauth2_validation_key_cache_insert_pubkey(
+       struct oauth2_validation_key_cache *cache, const char *key_id,
+       struct dcrypt_public_key *pubkey)
 {
        if (cache == NULL)
                return;
-       struct oauth2_key_cache_entry *entry = hash_table_lookup(cache->keys, key_id);
+
+       struct oauth2_key_cache_entry *entry =
+               hash_table_lookup(cache->keys, key_id);
        if (entry != NULL) {
                dcrypt_key_unref_public(&entry->pubkey);
                entry->pubkey = pubkey;
@@ -102,19 +112,23 @@ void oauth2_validation_key_cache_insert_pubkey(struct oauth2_validation_key_cach
        hash_table_insert(cache->keys, entry->key_id, entry);
 }
 
-void oauth2_validation_key_cache_insert_hmac_key(struct oauth2_validation_key_cache *cache,
-                                                const char *key_id,
-                                                const buffer_t *hmac_key)
+void oauth2_validation_key_cache_insert_hmac_key(
+       struct oauth2_validation_key_cache *cache, const char *key_id,
+       const buffer_t *hmac_key)
 {
        if (cache == NULL)
                return;
-       struct oauth2_key_cache_entry *entry = hash_table_lookup(cache->keys, key_id);
+
+       struct oauth2_key_cache_entry *entry =
+               hash_table_lookup(cache->keys, key_id);
        if (entry != NULL) {
                dcrypt_key_unref_public(&entry->pubkey);
-               if (entry->hmac_key == NULL)
-                       entry->hmac_key = buffer_create_dynamic(cache->pool, hmac_key->used);
-               else
+               if (entry->hmac_key == NULL) {
+                       entry->hmac_key = buffer_create_dynamic(
+                               cache->pool, hmac_key->used);
+               } else {
                        buffer_set_used_size(entry->hmac_key, 0);
+               }
                buffer_append(entry->hmac_key, hmac_key->data, hmac_key->used);
                return;
        }
@@ -131,7 +145,9 @@ int oauth2_validation_key_cache_evict(struct oauth2_validation_key_cache *cache,
 {
        if (cache == NULL)
                return -1;
-       struct oauth2_key_cache_entry *entry = hash_table_lookup(cache->keys, key_id);
+
+       struct oauth2_key_cache_entry *entry =
+               hash_table_lookup(cache->keys, key_id);
        if (entry == NULL)
                return -1;
        if (entry->pubkey != NULL)