Skip to main content

resolve

Function resolve 

Source
pub fn resolve(
    path: impl AsRef<Path>,
    store: Option<&dyn KeyStore>,
    command_timeout: Duration,
) -> Result<Resolution>
Expand description

Find the secret for the brain at path (the keys note, section 6).

It reads the file’s KDF parameters first, with no key: raw-key parameters make it a key file, anything else a passphrase file. It takes the first present source of that kind: MNEMO_KEY, MNEMO_KEY_FILE, MNEMO_KEY_COMMAND, the key store, for a key; MNEMO_PASSPHRASE, a passphrase entry in the key store, for a passphrase. A present source of the other kind is named in Resolved::notes as skipped. With no source of the file’s kind, the first present source of the other kind is used, once (for a key file, only a passphrase source). Nothing is tried: the caller opens with what comes back.

The key store is looked up last, and only when it’s needed (step 2): when no earlier source of the file’s kind is present, or for the one try of the other kind. So a keychain that would ask the user something, or can’t be reached at all, is never touched when MNEMO_KEY answers. A store error is a note when another source answers, and the error only when the store was the one left.

When page 0 doesn’t parse, the salts and the kind come from the header frames in the file’s write-ahead log (newest first), and the store is looked up under each in turn; the open that follows heals the header. With neither, the kind is unknown: the first environment source present is used.