RustDbCrypto.sys.mjs
- class RustDbCrypto.sys.AuthenticationCanceled()
authentication has been cancelled.
- class RustDbCrypto.sys.AuthenticationError()
error during authentication (in PrimaryPasswordAuthenticator)
- class RustDbCrypto.sys.DbCryptoApiError()
These are the errors returned by our public API.
- class RustDbCrypto.sys.DecryptionFailed()
decryption failed
- class RustDbCrypto.sys.EncryptionFailed()
encryption failed
- class RustDbCrypto.sys.Interrupted()
An operation was interrupted at the request of the consuming app.
- class RustDbCrypto.sys.InvalidKey()
Encryption key is not valid.
- class RustDbCrypto.sys.MissingKey()
Encryption key is missing.
- class RustDbCrypto.sys.NssAuthenticationError()
NSS error during authentication
- class RustDbCrypto.sys.NssKeyManager()
Use the NSSKeyManager to use NSS for key management.
NSS stores keys in key4.db within the profile and wraps the key with a key derived from the primary password, if set. It defers to the provided PrimaryPasswordAuthenticator implementation to handle user authentication. Note that if no primary password is set, the wrapping key is deterministically derived from an empty string.
Make sure to initialize NSS using ensure_initialized_with_profile_dir before creating a NSSKeyManager.
The key is cached after the first retrieval, since fetching it from NSS costs at least one token round-trip. The cache is dropped whenever the token turns out to be locked again.
# Examples ```no_run use async_trait::async_trait; use db_crypto::KeyManager; use db_crypto::{PrimaryPasswordAuthenticator, DbCryptoApiError, NSSKeyManager}; use std::sync::Arc;
struct MyPrimaryPasswordAuthenticator {}
#[async_trait] impl PrimaryPasswordAuthenticator for MyPrimaryPasswordAuthenticator { async fn get_primary_password(&self) -> Result<String, DbCryptoApiError> { // Most likely, you would want to prompt for a password. // let password = prompt_string(“primary password”).unwrap_or_default(); Ok(“secret”.to_string()) }
async fn on_authentication_success(&self) -> Result<(), DbCryptoApiError> { println!(“success”); Ok(()) }
async fn on_authentication_failure(&self) -> Result<(), DbCryptoApiError> { println!(“this did not work, please try again:”); Ok(()) } } let key_manager = NSSKeyManager::new(String::from(“example”), Arc::new(MyPrimaryPasswordAuthenticator {})); assert_eq!(key_manager.get_key().unwrap().len(), 63); ```
- RustDbCrypto.sys.NssKeyManager.intoDynKeyManager()
intoDynKeyManager
- Returns:
Promise.<KeyManager> – }
- static RustDbCrypto.sys.NssKeyManager.init(keyName, primaryPasswordAuthenticator)
Initialize new NSSKeyManager with a given PrimaryPasswordAuthenticator. There must be a previous initializiation of NSS before initializing NSSKeyManager, otherwise this panics.
- Arguments:
keyName (string)
primaryPasswordAuthenticator (PrimaryPasswordAuthenticator)
- Returns:
Promise.<NssKeyManager> – }
- class RustDbCrypto.sys.NssUninitialized()
NSS not initialized.
- class RustDbCrypto.sys.PrimaryPasswordAuthenticator()
PrimaryPasswordAuthenticator is used in conjunction with NSSKeyManager to provide the primary password and the success or failure actions of the authentication process.
- RustDbCrypto.sys.PrimaryPasswordAuthenticator.getPrimaryPassword()
Get a primary password for authentication, otherwise return the AuthenticationCancelled error to cancel the authentication process.
- Returns:
Promise.<string> – }
- RustDbCrypto.sys.PrimaryPasswordAuthenticator.onAuthenticationFailure()
onAuthenticationFailure
- RustDbCrypto.sys.PrimaryPasswordAuthenticator.onAuthenticationSuccess()
onAuthenticationSuccess
- class RustDbCrypto.sys.UnexpectedDbCryptoApiError()
something internal went wrong which doesn’t have a public error value because the consuming app can not reasonably take any action to resolve it. The underlying error will have been logged and reported. (ideally would just be Unexpected, but that would be a breaking change)
- RustDbCrypto.sys.checkCanary(canary, text, encryptionKey)
Check that key is still valid using the output of create_canary.
- Arguments:
canary (string)
text (string)
encryptionKey (string)
- Returns:
Promise.<boolean> – }
- RustDbCrypto.sys.createCanary(text, encryptionKey)
Create a “canary” string, which can be used to test if the encryption
- Arguments:
text (string)
encryptionKey (string)
- Returns:
Promise.<string> – }
- RustDbCrypto.sys.createKey()
We expose the crypto primitives on the namespace Create a new, random, encryption key.
- Returns:
Promise.<string> – }