From 578ae57a0a055adf5fcc9bfc1d3afb02e0f3552c Mon Sep 17 00:00:00 2001 From: samialabri Date: Sat, 17 Oct 2026 00:49:00 +0900 Subject: [PATCH] Add rustfmt.toml (same as core and server) and apply cargo fmt Formatting only. CI now runs cargo fmt --check here as in the other Rust repos. Co-Authored-By: Claude Opus 5.5 --- src-tauri/rustfmt.toml | 2 ++ src-tauri/src/autolock.rs | 4 ++- src-tauri/src/broker.rs | 29 +++++++++++++++------ src-tauri/src/channel.rs | 7 ++--- src-tauri/src/ipc.rs | 10 +------- src-tauri/src/main.rs | 15 +++++++---- src-tauri/src/words.rs | 54 ++++++++++++++++----------------------- 7 files changed, 61 insertions(+), 60 deletions(-) create mode 100644 src-tauri/rustfmt.toml diff --git a/src-tauri/rustfmt.toml b/src-tauri/rustfmt.toml new file mode 100644 index 0000000..c775577 --- /dev/null +++ b/src-tauri/rustfmt.toml @@ -0,0 +1,2 @@ +max_width = 120 +use_small_heuristics = "Max" diff --git a/src-tauri/src/autolock.rs b/src-tauri/src/autolock.rs index 2a7bf1e..8937419 100644 --- a/src-tauri/src/autolock.rs +++ b/src-tauri/src/autolock.rs @@ -135,7 +135,9 @@ mod platform { mod platform { use std::time::Duration; - use windows_sys::Win32::System::StationsAndDesktops::{CloseDesktop, OpenInputDesktop, SwitchDesktop, DESKTOP_SWITCHDESKTOP}; + use windows_sys::Win32::System::StationsAndDesktops::{ + CloseDesktop, OpenInputDesktop, SwitchDesktop, DESKTOP_SWITCHDESKTOP, + }; use windows_sys::Win32::System::SystemInformation::GetTickCount; use windows_sys::Win32::UI::Input::KeyboardAndMouse::{GetLastInputInfo, LASTINPUTINFO}; diff --git a/src-tauri/src/broker.rs b/src-tauri/src/broker.rs index 5bed48b..21ae296 100644 --- a/src-tauri/src/broker.rs +++ b/src-tauri/src/broker.rs @@ -230,7 +230,8 @@ impl Broker { Some("ping") => json!({ "t": "pong", "version": env!("CARGO_PKG_VERSION") }), Some("pair_init") => { let Some(ext_pub) = v.get("pub").and_then(b64_array::<32>) else { return outer_err("bad_request") }; - let name: String = v.get("name").and_then(Value::as_str).unwrap_or("Browser").chars().take(80).collect(); + let name: String = + v.get("name").and_then(Value::as_str).unwrap_or("Browser").chars().take(80).collect(); self.pair_init(conn, &ext_pub, name).unwrap_or_else(|| outer_err("bad_request")) } Some("pair_confirm") => { @@ -268,7 +269,9 @@ impl Broker { let parsed: Option = serde_json::from_slice(&pt).ok(); drop(pt); let (rid, body) = match &parsed { - Some(p) => (p.get("rid").cloned().unwrap_or(Value::Null), p.get("body").cloned().unwrap_or(Value::Null)), + Some(p) => { + (p.get("rid").cloned().unwrap_or(Value::Null), p.get("body").cloned().unwrap_or(Value::Null)) + } None => (Value::Null, Value::Null), }; let reply = Zeroizing::new( @@ -397,7 +400,9 @@ impl Broker { self.ui.activity(); match self.matching_item(&origin, id) { Ok(d) => match d.totp.as_deref().map(|t| kv_ffi::totp_code(t.to_string(), now_secs())) { - Some(Ok(c)) => json!({ "type": "totp", "code": c.code, "secondsRemaining": c.seconds_remaining }), + Some(Ok(c)) => { + json!({ "type": "totp", "code": c.code, "secondsRemaining": c.seconds_remaining }) + } _ => err("bad_request"), }, Err(v) => v, @@ -622,7 +627,8 @@ mod tests { fn unpaired_and_revoked_extensions_are_refused() { let (b, _) = broker_with_item(); let mut conn = Conn { caller: String::new(), session: None }; - let r = b.handle_frame(&mut conn, &json!({ "t": "open", "pairing_id": "nope", "nonce": B64.encode([0u8; 16]) })); + let r = + b.handle_frame(&mut conn, &json!({ "t": "open", "pairing_id": "nope", "nonce": B64.encode([0u8; 16]) })); assert_eq!(r["code"], "not_paired"); let r = b.handle_frame(&mut conn, &json!({ "t": "msg", "n": 0, "c": "AAAA" })); assert_eq!(r["code"], "bad_session"); @@ -641,7 +647,8 @@ mod tests { let ext = Ephemeral::generate(); let r = b.handle_frame(&mut conn, &json!({ "t": "pair_init", "pub": B64.encode(ext.public) })); let id = r["pairing_id"].as_str().unwrap().to_string(); - let r = b.handle_frame(&mut conn, &json!({ "t": "pair_confirm", "pairing_id": id, "proof": B64.encode([0u8; 40]) })); + let r = b + .handle_frame(&mut conn, &json!({ "t": "pair_confirm", "pairing_id": id, "proof": B64.encode([0u8; 40]) })); assert_eq!(r["code"], "not_paired"); b.core().lock(); assert!(b.resolve_pairing(&id, true).is_err()); @@ -652,16 +659,22 @@ mod tests { #[test] fn save_prompts_then_creates_or_updates() { let (b, id) = broker_with_item(); - let r = b.handle_request(&json!({ "type": "save", "origin": "https://example.com", "username": "alice", "password": "s3cret" })); + let r = b.handle_request( + &json!({ "type": "save", "origin": "https://example.com", "username": "alice", "password": "s3cret" }), + ); assert_eq!(r["type"], "saved"); // identical: nothing to ask - let r = b.handle_request(&json!({ "type": "save", "origin": "https://example.com/login", "username": "alice", "password": "new" })); + let r = b.handle_request( + &json!({ "type": "save", "origin": "https://example.com/login", "username": "alice", "password": "new" }), + ); assert_eq!(r["type"], "save_prompted"); let views = b.pending_saves(); assert_eq!((views.len(), views[0].update, views[0].origin.as_str()), (1, true, "https://example.com")); assert_eq!(b.resolve_save(&views[0].id, true).unwrap().as_deref(), Some(id.as_str())); assert_eq!(b.core().get_item(id).unwrap().password.as_deref(), Some("new")); - b.handle_request(&json!({ "type": "save", "origin": "https://new.example.org", "username": "bob", "password": "pw" })); + b.handle_request( + &json!({ "type": "save", "origin": "https://new.example.org", "username": "bob", "password": "pw" }), + ); let v = b.pending_saves().pop().unwrap(); assert!(!v.update); let new_id = b.resolve_save(&v.id, true).unwrap().unwrap(); diff --git a/src-tauri/src/channel.rs b/src-tauri/src/channel.rs index da56ad0..800914e 100644 --- a/src-tauri/src/channel.rs +++ b/src-tauri/src/channel.rs @@ -77,11 +77,8 @@ pub struct Pairing { impl Pairing { pub fn derive(shared: &[u8; 32], ext_pub: &[u8; 32], app_pub: &[u8; 32]) -> Self { - let salt = Sha256::new() - .chain_update(b"kestrove/v1/pair") - .chain_update(ext_pub) - .chain_update(app_pub) - .finalize(); + let salt = + Sha256::new().chain_update(b"kestrove/v1/pair").chain_update(ext_pub).chain_update(app_pub).finalize(); let hk = Hkdf::::new(Some(&salt), shared); let mut key = Zeroizing::new([0u8; 32]); hk.expand(b"kestrove/v1/pair/key", key.as_mut()).expect("32 bytes is a valid HKDF length"); diff --git a/src-tauri/src/ipc.rs b/src-tauri/src/ipc.rs index 4320f87..b16bc0c 100644 --- a/src-tauri/src/ipc.rs +++ b/src-tauri/src/ipc.rs @@ -389,15 +389,7 @@ mod imp { let name = wide(&pipe_name()); // SAFETY: name is NUL-terminated; the handle is owned by File on success. let h = unsafe { - CreateFileW( - name.as_ptr(), - GENERIC_READ | GENERIC_WRITE, - 0, - ptr::null(), - OPEN_EXISTING, - 0, - ptr::null_mut(), - ) + CreateFileW(name.as_ptr(), GENERIC_READ | GENERIC_WRITE, 0, ptr::null(), OPEN_EXISTING, 0, ptr::null_mut()) }; if h == INVALID_HANDLE_VALUE { return Err(io::Error::last_os_error()); diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index f2b1819..f8ff8c5 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -223,7 +223,15 @@ fn list_items(app: State<'_, App>) -> CmdResult> { #[tauri::command] fn get_item(app: State<'_, App>, id: String) -> CmdResult { let d = app.core.get_item(id).map_err(err)?; - Ok(Detail { id: d.id, title: d.title, username: d.username, password: d.password, urls: d.urls, totp: d.totp, notes: d.notes }) + Ok(Detail { + id: d.id, + title: d.title, + username: d.username, + password: d.password, + urls: d.urls, + totp: d.totp, + notes: d.notes, + }) } #[tauri::command] @@ -282,10 +290,7 @@ fn copy_secret(app: State<'_, App>, id: String, field: Option) -> CmdRes cb.set().exclude_from_monitoring().exclude_from_cloud().exclude_from_history().text(secret.to_string()) } #[cfg(not(windows))] - { - cb.set_text(secret.to_string()) - } - .map_err(|e| e.to_string())?; + { cb.set_text(secret.to_string()) }.map_err(|e| e.to_string())?; drop(guard); thread::spawn(move || { thread::sleep(CLIPBOARD_CLEAR); diff --git a/src-tauri/src/words.rs b/src-tauri/src/words.rs index 7f9b897..0c15e78 100644 --- a/src-tauri/src/words.rs +++ b/src-tauri/src/words.rs @@ -2,38 +2,28 @@ //! The same list, in the same order, is in kestrove-browser/src/words.ts. pub const WORDS: [&str; 256] = [ - "acid", "acorn", "actor", "adult", "agent", "alarm", "album", "alley", - "amber", "angle", "ankle", "apple", "april", "apron", "arena", "armor", - "arrow", "atlas", "attic", "audio", "aunt", "autumn", "award", "bacon", - "badge", "bagel", "baker", "bamboo", "banjo", "barn", "basil", "basket", - "beach", "beard", "beetle", "bell", "bench", "berry", "bike", "birch", - "bison", "blade", "blanket", "blimp", "bloom", "boat", "bonus", "boot", - "bottle", "boxer", "brain", "brick", "bridge", "broom", "brush", "bucket", - "bugle", "cabin", "cable", "cactus", "camel", "camera", "canal", "candle", - "canoe", "canyon", "carbon", "cargo", "carpet", "castle", "cedar", "cello", - "chalk", "cherry", "chess", "chief", "cider", "cinema", "circus", "clay", - "cliff", "clock", "cloud", "clover", "cobra", "cocoa", "comet", "coral", - "cotton", "cousin", "coyote", "crane", "crayon", "cricket", "crown", "cup", - "daisy", "dancer", "delta", "denim", "desert", "diary", "diesel", "dingo", - "disco", "doctor", "dolphin", "donkey", "dragon", "drum", "duck", "eagle", - "earth", "easel", "echo", "eclipse", "elbow", "elder", "ember", "emerald", - "engine", "falcon", "fang", "farmer", "feather", "fence", "ferry", "fiddle", - "finch", "flag", "flute", "forest", "fossil", "fox", "frost", "galaxy", - "garden", "garlic", "gecko", "ghost", "ginger", "giraffe", "glacier", "globe", - "goat", "gold", "gorilla", "grape", "gravel", "guitar", "hammer", "harbor", - "harp", "hawk", "hazel", "helmet", "heron", "hiker", "honey", "hornet", - "hotel", "igloo", "index", "iris", "island", "ivory", "jacket", "jaguar", - "jelly", "jewel", "jungle", "kayak", "kettle", "kitten", "koala", "ladder", - "lagoon", "lake", "lantern", "laser", "lemon", "lentil", "lily", "lion", - "lizard", "lobster", "locket", "lotus", "magnet", "mango", "maple", "marble", - "meadow", "melon", "mint", "mirror", "monkey", "moose", "mosaic", "motor", - "mountain", "mulberry", "museum", "napkin", "nectar", "needle", "nickel", "noodle", - "novel", "nugget", "oasis", "ocean", "olive", "onion", "orange", "orbit", - "orchid", "otter", "owl", "oyster", "paddle", "palace", "panda", "paper", - "parrot", "peach", "pebble", "pepper", "piano", "pickle", "pilot", "pine", - "planet", "plum", "poem", "pony", "puzzle", "quartz", "quill", "rabbit", - "radar", "radio", "raven", "ribbon", "river", "robin", "rocket", "rose", - "ruby", "saddle", "salmon", "sandal", "satin", "scarf", "scout", "sugar", + "acid", "acorn", "actor", "adult", "agent", "alarm", "album", "alley", "amber", "angle", "ankle", "apple", "april", + "apron", "arena", "armor", "arrow", "atlas", "attic", "audio", "aunt", "autumn", "award", "bacon", "badge", + "bagel", "baker", "bamboo", "banjo", "barn", "basil", "basket", "beach", "beard", "beetle", "bell", "bench", + "berry", "bike", "birch", "bison", "blade", "blanket", "blimp", "bloom", "boat", "bonus", "boot", "bottle", + "boxer", "brain", "brick", "bridge", "broom", "brush", "bucket", "bugle", "cabin", "cable", "cactus", "camel", + "camera", "canal", "candle", "canoe", "canyon", "carbon", "cargo", "carpet", "castle", "cedar", "cello", "chalk", + "cherry", "chess", "chief", "cider", "cinema", "circus", "clay", "cliff", "clock", "cloud", "clover", "cobra", + "cocoa", "comet", "coral", "cotton", "cousin", "coyote", "crane", "crayon", "cricket", "crown", "cup", "daisy", + "dancer", "delta", "denim", "desert", "diary", "diesel", "dingo", "disco", "doctor", "dolphin", "donkey", "dragon", + "drum", "duck", "eagle", "earth", "easel", "echo", "eclipse", "elbow", "elder", "ember", "emerald", "engine", + "falcon", "fang", "farmer", "feather", "fence", "ferry", "fiddle", "finch", "flag", "flute", "forest", "fossil", + "fox", "frost", "galaxy", "garden", "garlic", "gecko", "ghost", "ginger", "giraffe", "glacier", "globe", "goat", + "gold", "gorilla", "grape", "gravel", "guitar", "hammer", "harbor", "harp", "hawk", "hazel", "helmet", "heron", + "hiker", "honey", "hornet", "hotel", "igloo", "index", "iris", "island", "ivory", "jacket", "jaguar", "jelly", + "jewel", "jungle", "kayak", "kettle", "kitten", "koala", "ladder", "lagoon", "lake", "lantern", "laser", "lemon", + "lentil", "lily", "lion", "lizard", "lobster", "locket", "lotus", "magnet", "mango", "maple", "marble", "meadow", + "melon", "mint", "mirror", "monkey", "moose", "mosaic", "motor", "mountain", "mulberry", "museum", "napkin", + "nectar", "needle", "nickel", "noodle", "novel", "nugget", "oasis", "ocean", "olive", "onion", "orange", "orbit", + "orchid", "otter", "owl", "oyster", "paddle", "palace", "panda", "paper", "parrot", "peach", "pebble", "pepper", + "piano", "pickle", "pilot", "pine", "planet", "plum", "poem", "pony", "puzzle", "quartz", "quill", "rabbit", + "radar", "radio", "raven", "ribbon", "river", "robin", "rocket", "rose", "ruby", "saddle", "salmon", "sandal", + "satin", "scarf", "scout", "sugar", ]; #[cfg(test)]