From 7692bcb4cad3ea9e60b5b1b7cda79964abab7491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Kj=C3=A4ll?= Date: Tue, 3 Oct 2023 17:54:31 +0200 Subject: [PATCH 1/2] replace cli-clipboard with arboard --- Cargo.lock | 153 ++++++++++++++++++++++++++++++++++------- Cargo.toml | 1 + cursive/Cargo.toml | 2 +- cursive/src/helpers.rs | 14 ++-- src/error.rs | 8 +++ 5 files changed, 146 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb944332..c360d02b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,6 +71,26 @@ version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +[[package]] +name = "arboard" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac57f2b058a76363e357c056e4f74f1945bf734d37b8b3ef49066c4787dde0fc" +dependencies = [ + "clipboard-win", + "core-graphics", + "image", + "log", + "objc", + "objc-foundation", + "objc_id", + "parking_lot", + "thiserror", + "winapi", + "wl-clipboard-rs", + "x11rb", +] + [[package]] name = "arrayvec" version = "0.5.2" @@ -211,6 +231,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c" +[[package]] +name = "bytemuck" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" + [[package]] name = "byteorder" version = "1.4.3" @@ -413,20 +439,6 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" -[[package]] -name = "cli-clipboard" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04087c1d4a2aa259784a563932aee09cbb0869d490775e051096174b070f3e3d" -dependencies = [ - "clipboard-win", - "objc", - "objc-foundation", - "objc_id", - "wl-clipboard-rs", - "x11-clipboard", -] - [[package]] name = "clipboard-win" version = "4.5.0" @@ -438,6 +450,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + [[package]] name = "config" version = "0.11.0" @@ -485,6 +503,30 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +[[package]] +name = "core-graphics" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-graphics-types", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "libc", +] + [[package]] name = "cpufeatures" version = "0.2.8" @@ -996,6 +1038,15 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +[[package]] +name = "fdeflate" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d329bdeac514ee06249dabc27877490f17f5d371ec693360768b838e19f3ae10" +dependencies = [ + "simd-adler32", +] + [[package]] name = "field-offset" version = "0.3.6" @@ -1740,6 +1791,21 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "image" +version = "0.24.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f3dfdbdd72063086ff443e297b61695500514b1e41095b6fb9a5ab48a70a711" +dependencies = [ + "bytemuck", + "byteorder", + "color_quant", + "num-rational", + "num-traits 0.2.15", + "png", + "tiff", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -1813,6 +1879,12 @@ dependencies = [ "libc", ] +[[package]] +name = "jpeg-decoder" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" + [[package]] name = "js-sys" version = "0.3.64" @@ -2135,6 +2207,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" dependencies = [ "adler", + "simd-adler32", ] [[package]] @@ -2563,6 +2636,19 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "png" +version = "0.17.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd75bf2d8dd3702b9707cdbc56a5b9ef42cec752eb8b3bafc01234558442aa64" +dependencies = [ + "bitflags 1.3.2", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide 0.7.1", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2815,6 +2901,7 @@ name = "ripasso" version = "0.7.0-alpha" dependencies = [ "anyhow", + "arboard", "base64", "chrono", "config", @@ -2842,8 +2929,8 @@ dependencies = [ name = "ripasso-cursive" version = "0.7.0-alpha" dependencies = [ + "arboard", "chrono", - "cli-clipboard", "config", "cursive", "gettext", @@ -3196,6 +3283,12 @@ dependencies = [ "libc", ] +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + [[package]] name = "siphasher" version = "0.3.10" @@ -3391,6 +3484,17 @@ dependencies = [ "syn 2.0.22", ] +[[package]] +name = "tiff" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d172b0f4d3fba17ba89811858b9d3d97f928aece846475bbda076ca46736211" +dependencies = [ + "flate2", + "jpeg-decoder", + "weezl", +] + [[package]] name = "time" version = "0.3.22" @@ -3898,6 +4002,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "weezl" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" + [[package]] name = "whoami" version = "1.4.1" @@ -4135,15 +4245,6 @@ dependencies = [ "wayland-protocols", ] -[[package]] -name = "x11-clipboard" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "980b9aa9226c3b7de8e2adb11bf20124327c054e0e5812d2aac0b5b5a87e7464" -dependencies = [ - "x11rb", -] - [[package]] name = "x11rb" version = "0.10.1" @@ -4183,9 +4284,9 @@ checksum = "a67300977d3dc3f8034dae89778f502b6ba20b269527b3223ba59c0cf393bb8a" [[package]] name = "xml-rs" -version = "0.8.14" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52839dc911083a8ef63efa4d039d1f58b5e409f923e44c80828f206f66e5541c" +checksum = "47430998a7b5d499ccee752b41567bc3afc57e1327dc855b1a2aa44ce29b5fa1" [[package]] name = "xxhash-rust" diff --git a/Cargo.toml b/Cargo.toml index c2ebc06e..90c7884f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ license = "GPL-3.0-only" edition = '2021' [dependencies] +arboard = "3.2.1" glob = "0.3.1" gpgme = "0.11.0" chrono = { version = "0.4", default_features = false, features = ["clock"] } diff --git a/cursive/Cargo.toml b/cursive/Cargo.toml index 31b0f932..6d6d2dd7 100644 --- a/cursive/Cargo.toml +++ b/cursive/Cargo.toml @@ -12,7 +12,7 @@ build = "build.rs" [dependencies] cursive = { version = "0.20.0", default-features = false, features = ["toml", "crossterm-backend"]} -cli-clipboard = "0.4.0" +arboard = { version = "3.2.1", features = ["wayland-data-control"]} ripasso = { path = "../", version = "0.7.0-alpha" } locale_config = "0.3.0" unic-langid = "0.9.1" diff --git a/cursive/src/helpers.rs b/cursive/src/helpers.rs index ffddd06e..7267291b 100644 --- a/cursive/src/helpers.rs +++ b/cursive/src/helpers.rs @@ -14,15 +14,22 @@ along with this program. If not, see . */ -use cli_clipboard::{ClipboardContext, ClipboardProvider}; +use std::sync::{Arc, Mutex}; + +use arboard::Clipboard; use cursive::{ event::Key, views::{Checkbox, Dialog, EditView, OnEventView, RadioButton, TextView}, Cursive, }; +use lazy_static::lazy_static; use pass::Result; use ripasso::{crypto::CryptoImpl, pass}; +lazy_static! { + static ref CLIPBOARD: Arc> = Arc::new(Mutex::new(Clipboard::new().unwrap())); +} + /// Displays an error in a cursive dialog pub fn errorbox(ui: &mut Cursive, err: &pass::Error) { let text = match err { @@ -46,10 +53,7 @@ pub fn errorbox(ui: &mut Cursive, err: &pass::Error) { /// Copies content to the clipboard. pub fn set_clipboard(content: String) -> Result<()> { - let mut ctx = ClipboardContext::new()?; - ctx.set_contents(content)?; - - Ok(()) + Ok(CLIPBOARD.lock().unwrap().set_text(content)?) } pub fn get_value_from_input(s: &mut Cursive, input_name: &str) -> Option> { diff --git a/src/error.rs b/src/error.rs index 214c875c..5f5a3fac 100644 --- a/src/error.rs +++ b/src/error.rs @@ -11,6 +11,7 @@ use crate::pass::PasswordStore; #[non_exhaustive] #[derive(Debug)] pub enum Error { + Clipboard(arboard::Error), Io(io::Error), Git(git2::Error), Gpg(gpgme::Error), @@ -33,6 +34,12 @@ pub enum Error { SystemTimeError(std::time::SystemTimeError), } +impl From for Error { + fn from(err: arboard::Error) -> Self { + Self::Clipboard(err) + } +} + impl From for Error { fn from(err: io::Error) -> Self { Self::Io(err) @@ -189,6 +196,7 @@ impl From>>>> for Error { impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { + Self::Clipboard(err) => write!(f, "{err}"), Self::Io(err) => write!(f, "{err}"), Self::Git(err) => write!(f, "{err}"), Self::Gpg(err) => write!(f, "{err}"), From 02e83c3b28fe6ed3e0533449df7bd105734e7248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Kj=C3=A4ll?= Date: Fri, 6 Oct 2023 19:33:41 +0200 Subject: [PATCH 2/2] clippy feedback --- src/pass.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pass.rs b/src/pass.rs index e0255cc8..c34789aa 100644 --- a/src/pass.rs +++ b/src/pass.rs @@ -704,8 +704,12 @@ impl PasswordStore { let keys = self .all_recipients()? .into_iter() - .map(|s| format!("0x{}, ", s.key_id)) - .collect::(); + .fold(String::new(), |mut acc, r| { + use std::fmt::Write; + let _ = write!(acc, ", 0x{}", r.key_id); + acc + }); + let message = format!("Reencrypt password store with new GPG ids {keys}"); self.add_and_commit(&names, &message)?;