1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include "strv.h"
5 #include "user-record.h"
6 
7 typedef struct PasswordCache {
8         /* Passwords acquired from the kernel keyring */
9         char **keyring_passswords;
10 
11         /* Decoding passwords from security tokens is expensive and typically requires user interaction,
12          * hence cache any we already figured out. */
13         char **pkcs11_passwords;
14         char **fido2_passwords;
15 } PasswordCache;
16 
17 void password_cache_free(PasswordCache *cache);
18 
password_cache_contains(const PasswordCache * cache,const char * p)19 static inline bool password_cache_contains(const PasswordCache *cache, const char *p) {
20         if (!cache)
21                 return false;
22 
23         return strv_contains(cache->pkcs11_passwords, p) ||
24                 strv_contains(cache->fido2_passwords, p) ||
25                 strv_contains(cache->keyring_passswords, p);
26 }
27 
28 void password_cache_load_keyring(UserRecord *h, PasswordCache *cache);
29