Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to zbus 3 #50

Merged
merged 7 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
rust:
- stable
# MSRV, influenced by zbus.
- 1.58.0
- 1.60.0

steps:
- uses: actions/checkout@v2
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
Unreleased
- Updated dependencies where reasonable
- Bumped MSRV to 1.58
- BREAKING: Updated to `zbus` 2.0. This changes error types and public path fields.
- Bumped MSRV to 1.60
- BREAKING: Updated to `zbus` 3.0. This changes error types and public path fields.
- BREAKING: The types exported from the crate root are now entirely async. Blocking functions have been moved into the `blocking` module.
- BREAKING: `Error::Crypto` now contains a `&'static str` instead of a `String`.
- BREAKING: `SecretService::search_items` now takes a `HashMap<&str, &str>` instead of `Vec<(&str, &str)>` for the attributes.
- BREAKING: The `SecretService::new()` method was renamed to `SecretService::connect()` to be more accurate.

[2.0.2]
- Increased minimum `zbus` version to 1.9.2, in order to increase the minimum version of the transitive dependency `nix` to at least 0.20.2, which is the first `nix` release to contain the fix for the security vulnerability described at https://rustsec.org/advisories/RUSTSEC-2021-0119 . A known issue with this version of `nix` is that it places an upper bound on the version of the `bitflags` dependency; if you are depending on `bitflags`, you may need to downgrade your `bitflags` version in order to upgrade to this version of `secret-service`, which you are encouraged to do in order to ensure that you are not exposed to the aforementioned `nix` vulnerability. In the long term, this will be fixed by upgrading `secret-service` to use a newer version of `zbus`, which itself depends on versions of `nix` which no longer have this restriction on `bitflags`.
Expand Down
19 changes: 15 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@ keywords = ["secret-service", "password", "linux", "keychain"]
license = "MIT OR Apache-2.0"
name = "secret-service"
repository = "https://github.com/hwchen/secret-service-rs.git"
edition = "2018"
edition = "2021"
version = "2.0.1"
rust-version = "1.58.0"
rust-version = "1.60.0"

# The async runtime features mirror those of `zbus` for compatibility.
[features]
default = ["async-io"]
async-io = ["zbus/async-io"]
tokio = ["zbus/tokio"]

[dependencies]
# TODO: Update these when Rust 1.56 isn't so new.
aes = "0.7.0"
block-modes = "0.8.0"
hkdf = "0.12.0"
lazy_static = "1.4.0"
once_cell = "1"
futures-util = "0.3"
num = "0.4.0"
rand = "0.8.1"
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.10.0"
zbus = "2"
zbus = { version = "3", default-features = false }


[dev-dependencies]
tokio = { version = "1", features = ["rt", "macros"] }
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ If you have `cargo-extras` installed, can replace above step with the command at
$ cargo add secret-service
```

In source code (below example is for --bin, not --lib)
In source code (below example is for --bin, not --lib). This example uses `tokio` as
the async runtime.

```rust
use secret_service::SecretService;
use secret_service::EncryptionType;
use std::collections::HashMap;
use std::error::Error;
use std::{collections::HashMap, error::Error};

fn main() -> Result<(), Box<dyn Error>> {
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// initialize secret service (dbus connection and encryption session)
let ss = SecretService::new(EncryptionType::Dh)?;
let ss = SecretService::connect(EncryptionType::Dh).await?;

// get default collection
let collection = ss.get_default_collection()?;
let collection = ss.get_default_collection().await?;

// create new item
collection.create_item(
Expand All @@ -53,22 +54,21 @@ fn main() -> Result<(), Box<dyn Error>> {
b"test_secret", // secret
false, // replace item with same attributes
"text/plain" // secret content type
)?;
).await?;

// search items by properties
let search_items = ss.search_items(
vec![("test", "test_value")]
)?;
HashMap::from([("test", "test_value")])
).await?;

let item = search_items.get(0).ok_or("Not found!")?;

// retrieve secret from item
let secret = item.get_secret()?;
let secret = item.get_secret().await?;
assert_eq!(secret, b"test_secret");

// delete item (deletes the dbus object, not the struct instance)
item.delete()?;

item.delete().await?;
Ok(())
}
```
Expand Down
21 changes: 12 additions & 9 deletions examples/example.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
//Copyright 2016 secret-service-rs Developers
//Copyright 2022 secret-service-rs Developers
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

extern crate secret_service;

use secret_service::{EncryptionType, SecretService};
use std::{collections::HashMap, str};

fn main() {
#[tokio::main(flavor = "current_thread")]
async fn main() {
// Initialize secret service
let ss = SecretService::new(EncryptionType::Plain).unwrap();
let ss = SecretService::connect(EncryptionType::Plain).await.unwrap();

// navigate to default collection
let collection = ss.get_default_collection().unwrap();
let collection = ss.get_default_collection().await.unwrap();

let mut properties = HashMap::new();
properties.insert("test", "test_value");
Expand All @@ -29,20 +28,24 @@ fn main() {
false, // replace item with same attributes
"text/plain", // secret content type
)
.await
.unwrap();

//println!("New Item: {:?}", new_item);

// search items by properties
let search_items = ss.search_items(vec![("test", "test_value")]).unwrap();
let mut search_properties = HashMap::new();
search_properties.insert("test", "test_value");

let search_items = ss.search_items(search_properties).await.unwrap();

//println!("Searched Item: {:?}", search_items);

let item = search_items.get(0).unwrap();

// retrieve secret from item
let secret = item.get_secret().unwrap();
let secret = item.get_secret().await.unwrap();
println!("Retrieved secret: {:?}", str::from_utf8(&secret).unwrap());
assert_eq!(secret, b"test_secret");
item.delete().unwrap();
item.delete().await.unwrap();
}
Loading