Tesseract is an easy way to store encrypted strings for use later on, this can be user-submitted API keys, locally stored keys, and more.
Note: It is recommended that your encryption key is not stored anywhere accessible by a third party.
If the indirect
flag is used, you can unlock/lock tesseract with Tesseract::unlock
and Tesseract::lock
. This is required if you wish to set, retrieve, or export any contents from tesseract.
use warp::tesseract::Tesseract;
let mut store = Tesseract::default();
store.unlock(&b"MY_PASSPHRASE").unwrap();
Note: Once this function is called, you would have to unlock it again. If Tesseract is also dropped out of scope, it will automatically run this function
store.lock();
Storing a key requires unlocking the store and then putting a specific key into it with the store
method.
use warp::tesseract::Tesseract;
let mut store = Tesseract::default();
store.unlock(&b"MY_PASSPHRASE").unwrap();
store.set("MY_KEY", "MY_VALUE").unwrap();
Getting a key from Tesseract requires unlocking the store then retrieving a specific key stored.
let value = store.retrieve("MY_KEY").unwrap();
You can import and export the encrypted contents from and to Tesseract.
use warp::tesseract::Tesseract;
let mut store = Tesseract::default();
store.unlock(&b"MY_PASSPHRASE").unwrap();
store.set("MY_KEY", "MY_VALUE").unwrap();
store.to_file("my_encrypted_data").unwrap();
use warp::tesseract::Tesseract;
let mut store = Tesseract::from_file("my_encrypted_data").unwrap();
store.unlock(&b"MY_PASSPHRASE").unwrap();
let value = store.retrieve("MY_KEY").unwrap();
Tesseract can autosave when data is being sent into the data store.
use warp::tesseract::Tesseract;
let mut store = Tesseract::from_file("my_encrypted_data").unwrap();
store.unlock(&b"MY_PASSPHRASE").unwrap();
store.set_autosave();
store.set("MY_KEY", "MY_VALUE").unwrap(); //the datastore will automatically save
Note: While it will attempt to automatically save, it will not return an error if it has issues saving.