Skip to content

Commit 55789e3

Browse files
Merge pull request #209 from brotskydotcom/issue-207
Re-enable access to secret-service items with no target attribute.
2 parents 9cb38f1 + a583eb3 commit 55789e3

File tree

5 files changed

+149
-150
lines changed

5 files changed

+149
-150
lines changed

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords = ["password", "credential", "keychain", "keyring", "cross-platform"]
66
license = "MIT OR Apache-2.0"
77
name = "keyring"
88
repository = "https://github.com/hwchen/keyring-rs.git"
9-
version = "3.2.0"
9+
version = "3.2.1"
1010
rust-version = "1.75"
1111
edition = "2021"
1212
exclude = [".github/"]
@@ -67,3 +67,6 @@ rpassword = "7"
6767
rand = "0.8"
6868
doc-comment = "0.3"
6969
whoami = "1"
70+
71+
[package.metadata.docs.rs]
72+
features = ["apple-native", "windows-native", "sync-secret-service", "crypto-rust"]

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ This crate provides built-in implementations of the following platform-specific
6161
* _macOS_, _iOS_: The local keychain.
6262
* _Windows_: The Windows Credential Manager.
6363

64-
To enable the stores you want, you use features: there is one feature for each possibly-included credential store. If you specify a feature (e.g., `dbus-secret-service`) _and_ your target platform (e.g., `freebsd`) supports that credential store, it will be included as the default credential store in that build. That way you can have a build command that specifies a single credential store for each of your target platforms, and use that same build command for all targets.
64+
To enable the stores you want, you use features: there is one feature for each possibly-included credential store. If you specify a feature (e.g., `dbus-secret-service`) _and_ your target platform (e.g., `freebsd`) supports that credential store, it will be included as the default credential store in that build. That way you can have a build command that specifies a single credential store for each of your target platforms, and use that same build command for all targets. (You cannot enable more than one keystore for a given platform, except when producing docs.)
6565

6666
If you don't enable any credential stores that are supported on a specific target, the _mock_ keystore will be the default on that target. If you enable multiple credential stores for a specific target, you will get a compile error. See the [developer docs](https://docs.rs/keyring/) for details of which features control the inclusion of which credential stores (and which platforms each credential store targets).
6767

@@ -91,7 +91,7 @@ The main API change between v2 and v3 is the addition of support for non-string
9191

9292
Another API change between v2 and v3 is that the notion of a default feature set has gone away: you must now specify explicitly which crate-supported keystores you want included (other than the `mock` keystore, which is always present). So all keyring client developers will need to update their `Cargo.toml` file to use the new features correctly.
9393

94-
All v2 data is fully forward-compatible with v3 data; there have been no changes at all in that respect. _However_, unlike v2, the v3 implementation of the secret service credential store will _not_ read credentials that were written by the v1 keyring. (For details about why this decision was made, see [this issue](https://github.com/hwchen/keyring-rs/issues/204)). Keyring clients who use the secret service and are still using old v1 credentials should replace those credentials with v2/v3 credentials. The CLI has been extended to allow reading and deleting v1 credentials (and thus provides sample code for how to do this).
94+
All v2 data is fully forward-compatible with v3 data; there have been no changes at all in that respect.
9595

9696
The MSRV has been moved to 1.75, and all direct dependencies are at their latest stable versions.
9797

examples/cli.rs

+1-40
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,6 @@ fn main() {
6060
}
6161
}
6262

63-
#[cfg(all(
64-
any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"),
65-
any(feature = "sync-secret-service", feature = "async-secret-service")
66-
))]
67-
mod v1 {
68-
use keyring::{secret_service::SsCredential, Entry, Result};
69-
70-
/// Create a v1-like entry (one with no target attribute)
71-
pub fn new_entry(service: &str, user: &str) -> Result<Entry> {
72-
let cred = SsCredential::new_with_no_target(service, user)?;
73-
Ok(Entry::new_with_credential(Box::new(cred)))
74-
}
75-
}
76-
#[cfg(not(all(
77-
any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"),
78-
any(feature = "sync-secret-service", feature = "async-secret-service")
79-
)))]
80-
mod v1 {
81-
use keyring::Entry;
82-
83-
/// For everything but the secret service, v1 entries are the same as
84-
/// regular entries with the default target.
85-
pub fn new_entry(service: &str, user: &str) -> keyring::Result<Entry> {
86-
Entry::new(service, user)
87-
}
88-
}
89-
9063
#[derive(Debug, Parser)]
9164
#[clap(author = "github.com/hwchen/keyring-rs")]
9265
/// Keyring CLI: A command-line interface to platform secure storage
@@ -108,12 +81,6 @@ pub struct Cli {
10881
/// The user for the entry.
10982
pub user: String,
11083

111-
#[clap(long, action, verbatim_doc_comment)]
112-
/// Whether to look for v1 entries (that have no target).
113-
/// N.B.: v1 entries can only be read or deleted, not set.
114-
/// This may also find v2/v3 entries that have a target.
115-
pub v1: bool,
116-
11784
#[clap(subcommand)]
11885
pub command: Command,
11986
}
@@ -152,13 +119,7 @@ impl Cli {
152119
}
153120

154121
fn entry_for(&self) -> Result<Entry> {
155-
if self.v1 {
156-
if self.target.is_some() {
157-
eprintln!("usage error: You cannot specify both --target and --v1");
158-
std::process::exit(1)
159-
}
160-
v1::new_entry(&self.service, &self.user)
161-
} else if let Some(target) = &self.target {
122+
if let Some(target) = &self.target {
162123
Entry::new_with_target(target, &self.service, &self.user)
163124
} else {
164125
Entry::new(&self.service, &self.user)

src/lib.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,13 @@ pub mod mock;
168168
//
169169
// no duplicate keystores on any platform
170170
//
171-
#[cfg(any(
172-
all(feature = "linux-native", feature = "sync-secret-service"),
173-
all(feature = "linux-native", feature = "async-secret-service"),
174-
all(feature = "sync-secret-service", feature = "async-secret-service")
171+
#[cfg(all(
172+
not(doc),
173+
any(
174+
all(feature = "linux-native", feature = "sync-secret-service"),
175+
all(feature = "linux-native", feature = "async-secret-service"),
176+
all(feature = "sync-secret-service", feature = "async-secret-service")
177+
)
175178
))]
176179
compile_error!("You can enable at most one keystore per target architecture");
177180

@@ -181,7 +184,14 @@ compile_error!("You can enable at most one keystore per target architecture");
181184

182185
#[cfg(all(target_os = "linux", feature = "linux-native"))]
183186
pub mod keyutils;
184-
#[cfg(all(target_os = "linux", feature = "linux-native"))]
187+
#[cfg(all(
188+
target_os = "linux",
189+
feature = "linux-native",
190+
not(all(
191+
doc,
192+
any(feature = "sync-secret-service", feature = "async-secret-service")
193+
))
194+
))]
185195
pub use keyutils as default;
186196

187197
#[cfg(all(

0 commit comments

Comments
 (0)