(primaryKeyFpr, message)
| 143 | * @return {Promise<Object>} - password of key, if available unlocked key |
| 144 | */ |
| 145 | export async function get(primaryKeyFpr, message) { |
| 146 | if (!await cache.has(primaryKeyFpr)) { |
| 147 | return; |
| 148 | } |
| 149 | const entry = await cache.get(primaryKeyFpr); |
| 150 | let operations = 1; |
| 151 | if (message) { |
| 152 | operations += getReservedOperations({key: entry.key, message}); |
| 153 | } |
| 154 | entry.operations -= operations; |
| 155 | entry.tlOperations -= operations; |
| 156 | await cache.set(primaryKeyFpr, entry); |
| 157 | if (!Math.max(0, entry.tlOperations)) { |
| 158 | return; |
| 159 | } |
| 160 | if (Math.max(0, entry.operations)) { |
| 161 | return { |
| 162 | password: entry.password, |
| 163 | key: entry.key |
| 164 | }; |
| 165 | } else { |
| 166 | // number of allowed operations exhausted |
| 167 | deleteEntry(primaryKeyFpr); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Return true if key is cached |
nothing calls this directly
no test coverage detected