-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
52 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# libknox | ||
|
||
`libknox` is the library behing the [knox](https://crates.io/crates/knox) secret manager. | ||
|
||
You can refer to the [repository](https://github.com/apognu/knox) or the [documentation](https://docs.rs/libknox/) for usage information. | ||
|
||
## Example | ||
|
||
``` | ||
use libknox::*; | ||
fn main() { | ||
// Create a new vault with the given GPG identity | ||
let id = vec!["vault-test@apognu.github.com".to_string()]; | ||
let mut vault = VaultContext::create("/tmp/knox-example", &id).expect("FAIL"); | ||
// Create a new entry with three attributes | ||
let mut entry = Entry::new(); | ||
entry.add_attribute("username", "bob"); | ||
entry.add_confidential_attribute("password", "foobar"); | ||
entry.add_confidential_attribute( | ||
"apikey", | ||
"3OJL07P+W5zODH2J1Wv7rXh5i9UpR0mpvPW7ygIMih82J8P95krJZXyERqbi/XS", | ||
); | ||
// Write the entry and the metadata pointing to it | ||
vault | ||
.write_entry("personal/website.com", &entry) | ||
.expect("FAIL"); | ||
// Open the previously created vault and read the written entry | ||
let vault = VaultContext::open("/tmp/knox-example").expect("FAIL"); | ||
let entry = vault.read_entry("personal/website.com").expect("FAIL"); | ||
// Loop over the attributes and print them | ||
for (key, attribute) in entry.get_attributes() { | ||
if attribute.confidential { | ||
println!("{} = {} (CONFIDENTIAL)", key, attribute.value); | ||
} else { | ||
println!("{} = {}", key, attribute.value); | ||
} | ||
} | ||
} | ||
``` |