Skip to content

Commit 93a8c68

Browse files
committedJul 26, 2020
clean up copy feature
1 parent ae20c7c commit 93a8c68

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed
 

‎README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ cargo install otpcli
1313
```
1414

1515
## Features
16-
- **[DEFAULT]** `copy`: build with copy to [clipboard](https://crates.io/crates/clipboard) support. Adds a `--copy` option
17-
- **[DEFAULT]** `keychain`: build with secure secret storage support using [`keyring`](https://crates.io/crates/keyring)
16+
- **[DEFAULT]** `copy`: build with copy to [clipboard](https://crates.io/crates/clipboard) support. Adds a `--copy` cli option.
17+
- **[DEFAULT]** `keychain`: build with secure secret storage support using [`keyring`](https://crates.io/crates/keyring).
18+
- `rsa_stoken`: add in `stoken` support using the stoken crate.
1819

1920
The `copy` feature uses [clipboard](https://crates.io/crates/clipboard)
2021
and that requires a X11 on linux to access the clipboard
@@ -42,7 +43,7 @@ SUBCOMMANDS:
4243
delete Add/Update a new TOTP secret
4344
generate Generate a token
4445
help Prints this message or the help of the given subcommand(s)
45-
import Import an RSAToken into otpcli
46+
import Import an RSAToken into otpcli (if built with the stoken flag)
4647
list Add/Update a new TOTP secret
4748
migrate-to-keychain Migrate secrets stored in the config to be stored in the keychain
4849
```

‎src/otpcli/cli.rs

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ pub struct Options {
2727
pub copy_to_clipboard: bool,
2828
}
2929

30+
impl Options {
31+
#[cfg(feature = "copy")]
32+
pub fn copy_to_clipboard(&self) -> bool {
33+
self.copy_to_clipboard
34+
}
35+
}
36+
3037
#[derive(StructOpt, Clone)]
3138
pub enum Command {
3239
/// Add/Update a new TOTP secret

‎src/otpcli/main.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ fn copy_to_clipboard(code: &str) -> TotpResult<()> {
5757
Ok(())
5858
}
5959

60-
#[cfg(not(feature = "copy"))]
61-
fn copy_to_clipboard(_code: &str) -> TotpResult<()> {
62-
Ok(())
63-
}
64-
6560
fn generate_token(opts: Options, config: Config, name: String) -> TotpResult<()> {
6661
let code = match otp::token(&name, config) {
6762
Ok(token) => token,
@@ -76,10 +71,9 @@ fn generate_token(opts: Options, config: Config, name: String) -> TotpResult<()>
7671
}
7772
};
7873

79-
if cfg!(feature = "copy") {
80-
if opts.copy_to_clipboard {
81-
copy_to_clipboard(&code)?;
82-
}
74+
#[cfg(feature = "copy")]
75+
if opts.copy_to_clipboard() {
76+
copy_to_clipboard(&code)?;
8377
}
8478

8579
if opts.end_with_newline {

‎src/totp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ pub enum TokenAlgorithm {
3030
impl Copy for TokenAlgorithm {}
3131

3232
trait AsDigest {
33-
fn new(&self) -> Box<dyn Digest>;
33+
fn as_digest(&self) -> Box<dyn Digest>;
3434
}
3535

3636
impl AsDigest for TokenAlgorithm {
37-
fn new(&self) -> Box<dyn Digest> {
37+
fn as_digest(&self) -> Box<dyn Digest> {
3838
Box::new(match self {
3939
TokenAlgorithm::TotpSha1 => Sha1::new(),
4040
#[cfg(feature = "rsa_stoken")]

0 commit comments

Comments
 (0)
Please sign in to comment.