From 13d9e754b89a343f043048f56229e01091cd88a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Kj=C3=A4ll?= Date: Sat, 7 Feb 2026 17:55:24 +0100 Subject: [PATCH 1/2] use thiserror to create the error enum --- Cargo.lock | 335 ++++++++++++++++++----------------- Cargo.toml | 1 + cursive/src/main.rs | 30 ++-- cursive/src/tests/helpers.rs | 7 +- gtk/src/window/mod.rs | 15 +- src/crypto.rs | 26 +-- src/error.rs | 202 ++++----------------- src/git.rs | 48 +++-- src/pass.rs | 87 +++++---- src/passphrase_generator.rs | 6 +- src/signature.rs | 16 +- src/tests/crypto.rs | 3 +- src/tests/pass.rs | 17 +- src/tests/signature.rs | 2 +- src/tests/test_helpers.rs | 15 +- 15 files changed, 345 insertions(+), 465 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73de1707..14bd5d6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,9 +62,9 @@ checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" [[package]] name = "anyhow" -version = "1.0.100" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" +checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea" [[package]] name = "arboard" @@ -148,9 +148,9 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "aws-lc-rs" -version = "1.15.2" +version = "1.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a88aab2464f1f25453baa7a07c84c5b7684e274054ba06817f382357f77a288" +checksum = "7b7b6141e96a8c160799cc2d5adecd5cbbe5054cb8c7c4af53da0f83bb7ad256" dependencies = [ "aws-lc-sys", "zeroize", @@ -158,9 +158,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.35.0" +version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45afffdee1e7c9126814751f88dddc747f41d91da16c9551a0f1e8a11e788a1" +checksum = "5c34dda4df7017c8db52132f0f8a2e0f8161649d15723ed63fc00c82d0f2081a" dependencies = [ "cc", "cmake", @@ -182,9 +182,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64ct" -version = "1.8.2" +version = "1.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d809780667f4410e7c41b07f52439b94d2bdf8528eeedc287fa38d3b7f95d82" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" [[package]] name = "bindgen" @@ -279,7 +279,7 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db26bf1f092fd5e05b5ab3be2f290915aeb6f3f20c4e9f86ce0f07f336c2412f" dependencies = [ - "bzip2", + "bzip2 0.5.2", "flate2", "libc", ] @@ -298,9 +298,9 @@ checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" [[package]] name = "bytemuck" -version = "1.24.0" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fbdf580320f38b612e485521afda1ee26d10cc9884efaaa750d383e13e3c5f4" +checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec" [[package]] name = "byteorder" @@ -329,6 +329,15 @@ dependencies = [ "bzip2-sys", ] +[[package]] +name = "bzip2" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a53fac24f34a81bc9954b5d6cfce0c21e18ec6959f44f56e8e90e4bb7c346c" +dependencies = [ + "libbz2-rs-sys", +] + [[package]] name = "bzip2-sys" version = "0.1.13+1.0.8" @@ -409,9 +418,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.51" +version = "1.2.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a0aeaff4ff1a90589618835a598e545176939b97874f7abc7851caa0618f203" +checksum = "47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29" dependencies = [ "find-msvc-tools", "jobserver", @@ -446,9 +455,9 @@ dependencies = [ [[package]] name = "cfg-expr" -version = "0.20.5" +version = "0.20.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21be0e1ce6cdb2ee7fff840f922fb04ead349e5cfb1e750b769132d44ce04720" +checksum = "78cef5b5a1a6827c7322ae2a636368a573006b27cfa76c7ebd53e834daeaab6a" dependencies = [ "smallvec", "target-lexicon 0.13.3", @@ -468,9 +477,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chrono" -version = "0.4.42" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" dependencies = [ "iana-time-zone", "js-sys", @@ -519,18 +528,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.54" +version = "4.5.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6e6ff9dcd79cff5cd969a17a545d79e84ab086e444102a591e288a8aa3ce394" +checksum = "6899ea499e3fb9305a65d5ebf6e3d2248c5fab291f300ad0a704fbe142eae31a" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.54" +version = "4.5.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa42cf4d2b7a41bc8f663a7cab4031ebafa1bf3875705bfaf8466dc60ab52c00" +checksum = "7b12c8b680195a62a8364d16b8447b01b6c2c8f9aaf68bee653be34d4245e238" dependencies = [ "anstyle", "clap_lex", @@ -538,9 +547,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.6" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" +checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32" [[package]] name = "clipboard-win" @@ -599,7 +608,7 @@ dependencies = [ "serde-untagged", "serde_core", "serde_json", - "toml 0.9.10+spec-1.1.0", + "toml 0.9.11+spec-1.1.0", "winnow", "yaml-rust2", ] @@ -619,7 +628,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" dependencies = [ - "getrandom 0.2.16", + "getrandom 0.2.17", "once_cell", "tiny-keccak", ] @@ -694,9 +703,9 @@ dependencies = [ [[package]] name = "criterion" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d883447757bb0ee46f233e9dc22eb84d93a9508c9b868687b274fc431d886bf" +checksum = "950046b2aa2492f9a536f5f4f9a3de7b9e2476e575e05bd6c333371add4d98f3" dependencies = [ "alloca", "anes", @@ -719,9 +728,9 @@ dependencies = [ [[package]] name = "criterion-plot" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed943f81ea2faa8dcecbbfa50164acf95d555afec96a27871663b300e387b2e4" +checksum = "d8d80a2f4f5b554395e47b5d8305bc3d27813bacb73493eb1001e8f76dae29ea" dependencies = [ "cast", "itertools 0.13.0", @@ -1239,21 +1248,20 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.26" +version = "0.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc0505cd1b6fa6580283f6bdf70a73fcf4aba1184038c90902b92b3dd0df63ed" +checksum = "f98844151eee8917efc50bd9e8318cb963ae8b297431495d3f758616ea5c57db" dependencies = [ "cfg-if", "libc", "libredox", - "windows-sys 0.60.2", ] [[package]] name = "find-msvc-tools" -version = "0.1.6" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645cbb3a84e60b7531617d5ae4e57f7e27308f6445f5abf653209ea76dec8dff" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "fixedbitset" @@ -1269,9 +1277,9 @@ checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" [[package]] name = "flate2" -version = "1.1.5" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" dependencies = [ "crc32fast", "miniz_oxide", @@ -1492,9 +1500,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" dependencies = [ "cfg-if", "js-sys", @@ -1791,9 +1799,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c0b69cfcb4e1b9f1bf2f53f95f766e4661169728ec61cd3fe5a0166f2d1386" +checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" dependencies = [ "atomic-waker", "bytes", @@ -1949,14 +1957,13 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" dependencies = [ "base64", "bytes", "futures-channel", - "futures-core", "futures-util", "http", "http-body", @@ -1965,7 +1972,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2 0.6.1", + "socket2 0.6.2", "system-configuration", "tokio", "tower-service", @@ -1975,9 +1982,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.64" +version = "0.1.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -2121,9 +2128,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.12.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown 0.16.1", @@ -2212,9 +2219,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.83" +version = "0.3.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8" +checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3" dependencies = [ "once_cell", "wasm-bindgen", @@ -2338,11 +2345,17 @@ dependencies = [ "system-deps 7.0.7", ] +[[package]] +name = "libbz2-rs-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c4a545a15244c7d945065b5d392b2d2d7f21526fba56ce51467b06ed445e8f7" + [[package]] name = "libc" -version = "0.2.179" +version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5a2d376baa530d1238d133232d15e239abad80d05838b4b59354e5268af431f" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" [[package]] name = "libgit2-sys" @@ -2488,9 +2501,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.6" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "memoffset" @@ -2566,7 +2579,7 @@ version = "7.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44e6ff4a94e5d34a1fd5abbd39418074646e2fa51b257198701330f22fcd6936" dependencies = [ - "getrandom 0.2.16", + "getrandom 0.2.17", "libc", "nettle-sys", "thiserror 1.0.69", @@ -2810,9 +2823,9 @@ checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" [[package]] name = "openssl-probe" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f50d9b3dabb09ecd771ad0aa242ca6894994c130308ca3d7684634df8037391" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" [[package]] name = "openssl-sys" @@ -2934,9 +2947,9 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "pest" -version = "2.8.5" +version = "2.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9eb05c21a464ea704b53158d358a31e6425db2f63a1a7312268b05fe2b75f7" +checksum = "e0848c601009d37dfa3430c4666e147e49cdcf1b92ecd3e63657d8a5f19da662" dependencies = [ "memchr", "ucd-trie", @@ -2944,9 +2957,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.8.5" +version = "2.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f9dbced329c441fa79d80472764b1a2c7e57123553b8519b36663a2fb234ed" +checksum = "11f486f1ea21e6c10ed15d5a7c77165d0ee443402f0780849d1768e7d9d6fe77" dependencies = [ "pest", "pest_generator", @@ -2954,9 +2967,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.8.5" +version = "2.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bb96d5051a78f44f43c8f712d8e810adb0ebf923fc9ed2655a7f66f63ba8ee5" +checksum = "8040c4647b13b210a963c1ed407c1ff4fdfa01c31d6d2a098218702e6664f94f" dependencies = [ "pest", "pest_meta", @@ -2967,9 +2980,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.8.5" +version = "2.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "602113b5b5e8621770cfd490cfd90b9f84ab29bd2b0e49ad83eb6d186cef2365" +checksum = "89815c69d36021a140146f26659a81d6c2afa33d216d736dd4be5381a7362220" dependencies = [ "pest", "sha2", @@ -3115,9 +3128,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.104" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9695f8df41bb4f3d222c95a67532365f569318332d03d5f3f67f37b20e6ebdf0" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] @@ -3159,8 +3172,8 @@ dependencies = [ "quinn-udp", "rustc-hash 2.1.1", "rustls", - "socket2 0.6.1", - "thiserror 2.0.17", + "socket2 0.6.2", + "thiserror 2.0.18", "tokio", "tracing", "web-time", @@ -3182,7 +3195,7 @@ dependencies = [ "rustls", "rustls-pki-types", "slab", - "thiserror 2.0.17", + "thiserror 2.0.18", "tinyvec", "tracing", "web-time", @@ -3197,16 +3210,16 @@ dependencies = [ "cfg_aliases", "libc", "once_cell", - "socket2 0.6.1", + "socket2 0.6.2", "tracing", "windows-sys 0.60.2", ] [[package]] name = "quote" -version = "1.0.42" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" dependencies = [ "proc-macro2", ] @@ -3235,7 +3248,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ "rand_chacha 0.9.0", - "rand_core 0.9.3", + "rand_core 0.9.5", ] [[package]] @@ -3255,7 +3268,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core 0.9.3", + "rand_core 0.9.5", ] [[package]] @@ -3264,14 +3277,14 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.16", + "getrandom 0.2.17", ] [[package]] name = "rand_core" -version = "0.9.3" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" dependencies = [ "getrandom 0.3.4", ] @@ -3320,16 +3333,16 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ - "getrandom 0.2.16", + "getrandom 0.2.17", "libredox", "thiserror 1.0.69", ] [[package]] name = "regex" -version = "1.12.2" +version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" dependencies = [ "aho-corasick", "memchr", @@ -3339,9 +3352,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" dependencies = [ "aho-corasick", "memchr", @@ -3350,15 +3363,15 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" +checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" [[package]] name = "reqwest" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04e9018c9d814e5f30cc16a0f03271aeab3571e609612d9fe78c1aa8d11c2f62" +checksum = "ab3f43e3283ab1488b624b44b0e988d0acea0b3214e694730a055cb6b2efa801" dependencies = [ "base64", "bytes", @@ -3402,7 +3415,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", - "getrandom 0.2.16", + "getrandom 0.2.17", "libc", "untrusted", "windows-sys 0.52.0", @@ -3428,7 +3441,8 @@ dependencies = [ "sequoia-openpgp", "tar", "tempfile", - "toml 0.9.10+spec-1.1.0", + "thiserror 2.0.18", + "toml 0.9.11+spec-1.1.0", "totp-rs", "whoami", "zeroize", @@ -3548,9 +3562,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.35" +version = "0.23.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "533f54bc6a7d4f647e46ad909549eda97bf5afc1585190ef692b4286b198bd8f" +checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" dependencies = [ "aws-lc-rs", "once_cell", @@ -3566,7 +3580,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63" dependencies = [ - "openssl-probe 0.2.0", + "openssl-probe 0.2.1", "rustls-pki-types", "schannel", "security-framework", @@ -3574,9 +3588,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.13.2" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e6f2ab2928ca4291b86736a8bd920a277a399bba1589409d72154ff87c1282" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" dependencies = [ "web-time", "zeroize", @@ -3611,9 +3625,9 @@ checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" [[package]] name = "rustls-webpki" -version = "0.103.8" +version = "0.103.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" dependencies = [ "aws-lc-rs", "ring", @@ -3702,7 +3716,7 @@ dependencies = [ "sequoia-openpgp", "stfu8", "tempfile", - "thiserror 2.0.17", + "thiserror 2.0.18", "tokio", ] @@ -3725,7 +3739,7 @@ dependencies = [ "sequoia-openpgp", "socket2 0.5.10", "tempfile", - "thiserror 2.0.17", + "thiserror 2.0.18", "tokio", "tokio-util", "winapi", @@ -3733,29 +3747,29 @@ dependencies = [ [[package]] name = "sequoia-openpgp" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0e334ce3ec5b9b47d86a80563b3ecec435f59acf37e86058b3b686a42c5a2ba" +checksum = "0620e44a7d514adf7df87b44db235f13b81fed7ddc265adb26f014d42626ac47" dependencies = [ "anyhow", "argon2", "base64", "buffered-reader", - "bzip2", + "bzip2 0.6.1", "chrono", "dyn-clone", "flate2", - "getrandom 0.2.16", + "getrandom 0.2.17", "idna", - "lalrpop 0.20.2", - "lalrpop-util 0.20.2", + "lalrpop 0.22.2", + "lalrpop-util 0.22.2", "libc", "memsec", "nettle", "regex", "regex-syntax", "sha1collisiondetection", - "thiserror 2.0.17", + "thiserror 2.0.18", "xxhash-rust", ] @@ -3803,9 +3817,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.148" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3084b546a1dd6289475996f182a22aba973866ea8e8b02c51d9f46b1336a22da" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "itoa", "memchr", @@ -3919,15 +3933,15 @@ checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" [[package]] name = "siphasher" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" +checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e" [[package]] name = "slab" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smallvec" @@ -3947,9 +3961,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" +checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" dependencies = [ "libc", "windows-sys 0.60.2", @@ -3993,9 +4007,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.113" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678faa00651c9eb72dd2020cbdf275d92eccb2400d568e419efdd64838145cb4" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -4024,9 +4038,9 @@ dependencies = [ [[package]] name = "system-configuration" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b" dependencies = [ "bitflags 2.10.0", "core-foundation 0.9.4", @@ -4062,10 +4076,10 @@ version = "7.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c8f33736f986f16d69b6cb8b03f55ddcad5c41acc4ccc39dd88e84aa805e7f" dependencies = [ - "cfg-expr 0.20.5", + "cfg-expr 0.20.6", "heck", "pkg-config", - "toml 0.9.10+spec-1.1.0", + "toml 0.9.11+spec-1.1.0", "version-compare", ] @@ -4146,11 +4160,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.17" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ - "thiserror-impl 2.0.17", + "thiserror-impl 2.0.18", ] [[package]] @@ -4166,9 +4180,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.17" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", @@ -4277,7 +4291,7 @@ dependencies = [ "libc", "mio", "pin-project-lite", - "socket2 0.6.1", + "socket2 0.6.2", "windows-sys 0.61.2", ] @@ -4319,9 +4333,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.9.10+spec-1.1.0" +version = "0.9.11+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0825052159284a1a8b4d6c0c86cbc801f2da5afd2b225fa548c72f2e74002f48" +checksum = "f3afc9a848309fe1aaffaed6e1546a7a14de1f935dc9d89d32afd9a44bab7c46" dependencies = [ "indexmap", "serde_core", @@ -4414,9 +4428,9 @@ dependencies = [ [[package]] name = "tower" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" dependencies = [ "futures-core", "futures-util", @@ -4561,9 +4575,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.7" +version = "2.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" dependencies = [ "form_urlencoded", "idna", @@ -4637,27 +4651,27 @@ dependencies = [ [[package]] name = "wasip2" -version = "1.0.1+wasi-0.2.4" +version = "1.0.2+wasi-0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" dependencies = [ "wit-bindgen", ] [[package]] name = "wasite" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "313fb64fed616e75426cf738284efe4e85017243bccfae42698be1d7fa9b05d5" +checksum = "66fe902b4a6b8028a753d5424909b764ccf79b7a209eac9bf97e59cda9f71a42" dependencies = [ "wasi 0.14.7+wasi-0.2.4", ] [[package]] name = "wasm-bindgen" -version = "0.2.106" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd" +checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566" dependencies = [ "cfg-if", "once_cell", @@ -4668,11 +4682,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.56" +version = "0.4.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836d9622d604feee9e5de25ac10e3ea5f2d65b41eac0d9ce72eb5deae707ce7c" +checksum = "70a6e77fd0ae8029c9ea0063f87c46fde723e7d887703d74ad2616d792e51e6f" dependencies = [ "cfg-if", + "futures-util", "js-sys", "once_cell", "wasm-bindgen", @@ -4681,9 +4696,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.106" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3" +checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4691,9 +4706,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.106" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40" +checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55" dependencies = [ "bumpalo", "proc-macro2", @@ -4704,9 +4719,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.106" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4" +checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12" dependencies = [ "unicode-ident", ] @@ -4783,9 +4798,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.83" +version = "0.3.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac" +checksum = "312e32e551d92129218ea9a2452120f4aabc03529ef03e4d0d82fb2780608598" dependencies = [ "js-sys", "wasm-bindgen", @@ -4803,9 +4818,9 @@ dependencies = [ [[package]] name = "webpki-root-certs" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36a29fc0408b113f68cf32637857ab740edfafdf460c326cd2afaa2d84cc05dc" +checksum = "804f18a4ac2676ffb4e8b5b5fa9ae38af06df08162314f96a68d2a363e21a8ca" dependencies = [ "rustls-pki-types", ] @@ -4818,9 +4833,9 @@ checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88" [[package]] name = "whoami" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86dc1eeef7866078951fc09f1857d3d33a37432fe376d7ff45449c8bb50318c1" +checksum = "8fae98cf96deed1b7572272dfc777713c249ae40aa1cf8862e091e8b745f5361" dependencies = [ "libredox", "wasite", @@ -5255,9 +5270,9 @@ dependencies = [ [[package]] name = "wit-bindgen" -version = "0.46.0" +version = "0.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" [[package]] name = "wl-clipboard-rs" @@ -5269,7 +5284,7 @@ dependencies = [ "log", "os_pipe", "rustix 1.1.3", - "thiserror 2.0.17", + "thiserror 2.0.18", "tree_magic_mini", "wayland-backend", "wayland-client", @@ -5358,18 +5373,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.31" +version = "0.8.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3" +checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.31" +version = "0.8.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a" +checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517" dependencies = [ "proc-macro2", "quote", @@ -5453,9 +5468,9 @@ dependencies = [ [[package]] name = "zmij" -version = "1.0.10" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e0d8dffbae3d840f64bda38e28391faef673a7b5a6017840f2a106c8145868" +checksum = "3ff05f8caa9038894637571ae6b9e29466c1f4f829d26c9b28f869a29cbe3445" [[package]] name = "zune-core" diff --git a/Cargo.toml b/Cargo.toml index 650b7b77..920c4391 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ sequoia-openpgp = "2" anyhow = "1" sequoia-gpg-agent = "0.6" zeroize = { version = "1", features = ["zeroize_derive", "alloc"] } +thiserror = "2" [dependencies.config] version = "0.15" diff --git a/cursive/src/main.rs b/cursive/src/main.rs index 56a33d3e..f926acaa 100644 --- a/cursive/src/main.rs +++ b/cursive/src/main.rs @@ -14,6 +14,14 @@ along with this program. If not, see . */ +use std::{ + collections::HashMap, + path::{Path, PathBuf}, + process, + sync::{Arc, LazyLock, Mutex, MutexGuard}, + thread, time, +}; + use config::Config; use cursive::{ Cursive, CursiveExt, @@ -28,31 +36,21 @@ use cursive::{ }; use pass::Result; use ripasso::{ - crypto::CryptoImpl, + crypto::{CryptoImpl, Fingerprint}, git::{pull, push}, pass, pass::{ OwnerTrustLevel, PasswordStore, Recipient, SignatureStatus, all_recipients_from_stores, }, passphrase_generator::passphrase_generator, - password_generator::password_generator, -}; -use std::sync::{LazyLock, MutexGuard}; -use std::{ - collections::HashMap, - path::{Path, PathBuf}, - process, - sync::{Arc, Mutex}, - thread, time, + password_generator::{PasswordGenerationCategory, password_generator}, }; use unic_langid::LanguageIdentifier; +use zeroize::Zeroize; use crate::helpers::{ get_value_from_input, is_checkbox_checked, is_radio_button_selected, recipients_widths, }; -use ripasso::crypto::Fingerprint; -use ripasso::password_generator::PasswordGenerationCategory; -use zeroize::Zeroize; mod helpers; mod wizard; @@ -864,7 +862,7 @@ fn delete_recipient(ui: &mut Cursive, store: &PasswordStoreType) -> Result<()> { let sel = l.selection(); if sel.is_none() || sel.as_ref().unwrap().is_none() { - return Err(pass::Error::Generic("Selection is empty")); + return Err(pass::Error::from("Selection is empty")); } let binding = sel.unwrap(); @@ -914,7 +912,7 @@ fn add_recipient(ui: &mut Cursive, store: &PasswordStoreType, config_path: &Path Err(err) => helpers::errorbox(ui, &err), Ok(recipient) => { if recipient.trust_level != OwnerTrustLevel::Ultimate { - helpers::errorbox(ui, &pass::Error::Generic(CATALOG.gettext("Can't import team member due to that the GPG trust relationship level isn't Ultimate"))); + helpers::errorbox(ui, &pass::Error::from(CATALOG.gettext("Can't import team member due to that the GPG trust relationship level isn't Ultimate"))); return Ok(()); } @@ -1082,7 +1080,7 @@ fn view_recipients(ui: &mut Cursive, store: &PasswordStoreType, config_path: &Pa do_view_recipients_for_dir(ui, store, &sub_dirs[0], config_path); } std::cmp::Ordering::Less => { - helpers::errorbox(ui, &pass::Error::Generic("no subdirectories found")); + helpers::errorbox(ui, &pass::Error::from("no subdirectories found")); } } diff --git a/cursive/src/tests/helpers.rs b/cursive/src/tests/helpers.rs index 1daad2ff..164830e5 100644 --- a/cursive/src/tests/helpers.rs +++ b/cursive/src/tests/helpers.rs @@ -1,8 +1,5 @@ use std::sync::Arc; -use crate::helpers::{ - get_value_from_input, is_checkbox_checked, is_radio_button_selected, recipients_widths, -}; use cursive::{ view::Nameable, views::{Checkbox, EditView, LinearLayout, RadioButton, RadioGroup}, @@ -13,6 +10,10 @@ use ripasso::{ pass::{Comment, KeyRingStatus, OwnerTrustLevel, Recipient}, }; +use crate::helpers::{ + get_value_from_input, is_checkbox_checked, is_radio_button_selected, recipients_widths, +}; + #[test] fn test_get_value_from_input() { let mut siv = cursive::default(); diff --git a/gtk/src/window/mod.rs b/gtk/src/window/mod.rs index e361c26e..754e2f38 100644 --- a/gtk/src/window/mod.rs +++ b/gtk/src/window/mod.rs @@ -1,6 +1,11 @@ mod imp; -use crate::{collection_object::CollectionObject, password_object::PasswordObject}; +use std::{ + collections::HashMap, + path::{Path, PathBuf}, + sync::{Arc, Mutex}, +}; + use adw::{ActionRow, NavigationDirection, prelude::*, subclass::prelude::*}; use glib::{Object, clone}; use gtk::{ @@ -8,12 +13,8 @@ use gtk::{ ListBoxRow, NoSelection, ResponseType, SelectionMode, gio, glib, glib::BindingFlags, pango, }; use ripasso::{crypto::CryptoImpl, pass::PasswordStore}; -use std::path::Path; -use std::{ - collections::HashMap, - path::PathBuf, - sync::{Arc, Mutex}, -}; + +use crate::{collection_object::CollectionObject, password_object::PasswordObject}; glib::wrapper! { pub struct Window(ObjectSubclass) diff --git a/src/crypto.rs b/src/crypto.rs index ad67e8ac..ad569875 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -52,7 +52,7 @@ impl TryFrom<&str> for CryptoImpl { match value { "gpg" => Ok(Self::GpgMe), "sequoia" => Ok(Self::Sequoia), - _ => Err(Error::Generic( + _ => Err(Error::from( "unknown pgp implementation value, valid values are 'gpg' and 'sequoia'", )), } @@ -147,7 +147,7 @@ impl TryFrom<&[u8]> for Fingerprint { 32 => Ok(Fingerprint::V6( b.try_into().expect("slice with incorrect length"), )), - _ => Err(Error::Generic("slice isn't 20 or 32 bytes")), + _ => Err(Error::from("slice isn't 20 or 32 bytes")), } } } @@ -166,7 +166,7 @@ impl TryFrom<&str> for Fingerprint { } else if key.len() == 66 { Ok(Fingerprint::from(<[u8; 32]>::from_hex(&key[2..])?)) } else { - Err(Error::Generic("unable to parse fingerprint")) + Err(Error::from("unable to parse fingerprint")) } } } @@ -354,7 +354,7 @@ impl Crypto for GpgMe { if let Some(key) = key_opt { key.fingerprint()?.to_owned() } else { - return Err(Error::Generic("no valid signing key")); + return Err(Error::from("no valid signing key")); } } }; @@ -505,7 +505,7 @@ fn download_keys(recipient_key_id: &str) -> Result { "https://keys.openpgp.org/vks/v1/by-fingerprint/{}", &recipient_key_id[2..] ), - _ => return Err(Error::Generic("key id is not 16 or 40 hex chars")), + _ => return Err(Error::from("key id is not 16 or 40 hex chars")), }; Ok(reqwest::blocking::get(url)?.text()?) @@ -564,7 +564,7 @@ fn find( key_ring: &HashMap>, recipient: Option<&KeyHandle>, ) -> Result> { - let recipient = recipient.as_ref().ok_or(Error::Generic("No recipient"))?; + let recipient = recipient.as_ref().ok_or(Error::from("No recipient"))?; match recipient { KeyHandle::Fingerprint(fpr) => match fpr { @@ -579,7 +579,7 @@ fn find( } } sequoia_openpgp::Fingerprint::Unknown { .. } => { - return Err(Error::Generic("unknown fingerprint version")); + return Err(Error::from("unknown fingerprint version")); } _ => {} }, @@ -592,13 +592,13 @@ fn find( } } KeyID::Invalid(_) => { - return Err(Error::Generic("Invalid key ID")); + return Err(Error::from("Invalid key ID")); } _ => {} }, } - Err(Error::Generic("key not found in keyring")) + Err(Error::from("key not found in keyring")) } impl DecryptionHelper for Helper<'_> { @@ -764,7 +764,7 @@ impl Sequoia { match self.key_ring.get(fp) { Some(cert) => result.push(cert.clone()), None => { - return Err(Error::GenericDyn(format!( + return Err(Error::from(format!( "Recipient with key id {} not found", recipient.key_id ))); @@ -820,7 +820,7 @@ impl Crypto for Sequoia { let decrypt_key = self .key_ring .get(&self.user_key_id) - .ok_or(Error::Generic("no key for user found"))?; + .ok_or(Error::from("no key for user found"))?; if decrypt_key.is_tsk() { // Make a helper that that feeds the recipient's secret key to the @@ -920,7 +920,7 @@ impl Crypto for Sequoia { let tsk = self .key_ring .get(&self.user_key_id) - .ok_or(Error::Generic("no key for user found"))?; + .ok_or(Error::from("no key for user found"))?; // Get the keypair to do the signing from the Cert. let keypair = tsk @@ -1044,7 +1044,7 @@ impl Crypto for Sequoia { } } - Err(Error::GenericDyn(format!("no key found for {key_id}"))) + Err(Error::from(format!("no key found for {key_id}"))) } fn get_all_trust_items(&self) -> Result> { diff --git a/src/error.rs b/src/error.rs index b8e65b13..686cb4d3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,183 +1,59 @@ -use std::{ - io, path, string, - sync::{Arc, Mutex, MutexGuard, PoisonError}, -}; - +use std::{io, path, str::Utf8Error, string}; +use std::sync::PoisonError; use hex::FromHexError; - -use crate::pass::PasswordStore; +use thiserror::Error; /// An enum that contains the different types of errors that the library returns as part of Result's. #[non_exhaustive] -#[derive(Debug)] +#[derive(Error, Debug)] pub enum Error { - Clipboard(arboard::Error), - Io(io::Error), - Git(git2::Error), - Gpg(gpgme::Error), - Utf8(string::FromUtf8Error), - Generic(&'static str), - GenericDyn(String), - PathError(path::StripPrefixError), - PatternError(glob::PatternError), - GlobError(glob::GlobError), - Utf8Error(std::str::Utf8Error), + Clipboard(#[from] arboard::Error), + Io(#[from] io::Error), + Git(#[from] git2::Error), + Gpg(#[from] gpgme::Error), + Utf8(#[from] string::FromUtf8Error), + OptionUtf8(Option), + Generic(String), + PathError(#[from] path::StripPrefixError), + PatternError(#[from] glob::PatternError), + GlobError(#[from] glob::GlobError), + Utf8Error(#[from] std::str::Utf8Error), RecipientNotInKeyRing(String), - ConfigError(config::ConfigError), - SerError(toml::ser::Error), - ReqwestError(reqwest::Error), - AnyhowError(anyhow::Error), + ConfigError(#[from] config::ConfigError), + SerError(#[from] toml::ser::Error), + ReqwestError(#[from] reqwest::Error), + AnyhowError(#[from] anyhow::Error), NoneError, - HexError(FromHexError), - FmtError(std::fmt::Error), - TotpUrlError(totp_rs::TotpUrlError), - 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) - } -} - -impl From for Error { - fn from(err: gpgme::Error) -> Self { - Self::Gpg(err) - } -} - -impl From for Error { - fn from(err: git2::Error) -> Self { - Self::Git(err) - } -} - -impl From for Error { - fn from(err: string::FromUtf8Error) -> Self { - Self::Utf8(err) - } + HexError(#[from] FromHexError), + FmtError(#[from] std::fmt::Error), + TotpUrlError(#[from] totp_rs::TotpUrlError), + SystemTimeError(#[from] std::time::SystemTimeError), } -impl From for Error { - fn from(err: path::StripPrefixError) -> Self { - Self::PathError(err) - } -} - -impl From for Error { - fn from(err: glob::PatternError) -> Self { - Self::PatternError(err) - } -} - -impl From for Error { - fn from(err: glob::GlobError) -> Self { - Self::GlobError(err) - } -} - -impl From for Error { - fn from(err: std::str::Utf8Error) -> Self { - Self::Utf8Error(err) +impl From<&str> for Error { + fn from(err: &str) -> Self { + Self::Generic(err.to_owned()) } } -impl From> for Error { - fn from(err: Option) -> Self { +impl From> for Error { + fn from(err: Option) -> Self { match err { - None => Self::Generic("gpgme error with None"), + None => Self::from("gpgme error with None"), Some(e) => Self::Utf8Error(e), } } } -impl From> for Error { - fn from(err: Box) -> Self { - Self::GenericDyn(err.to_string()) - } -} - -impl From for Error { - fn from(err: config::ConfigError) -> Self { - Self::ConfigError(err) - } -} - -impl From for Error { - fn from(err: toml::ser::Error) -> Self { - Self::SerError(err) - } -} - -impl From<&str> for Error { - fn from(err: &str) -> Self { - Self::GenericDyn(err.to_owned()) - } -} - -impl From>> for Error { - fn from(_err: PoisonError>) -> Self { - Self::Generic("thread error") - } -} - -impl From for Error { - fn from(err: reqwest::Error) -> Self { - Self::ReqwestError(err) - } -} - -impl From for Error { - fn from(err: anyhow::Error) -> Self { - Self::AnyhowError(err) - } -} - -impl From>>> for Error { - fn from(_err: PoisonError>>) -> Self { - Self::Generic("thread error") - } -} - -impl From for Error { - fn from(err: FromHexError) -> Self { - Self::HexError(err) - } -} - -impl From for Error { - fn from(err: std::fmt::Error) -> Self { - Self::FmtError(err) - } -} - -impl From for Error { - fn from(err: totp_rs::TotpUrlError) -> Self { - Self::TotpUrlError(err) - } -} - -impl From for Error { - fn from(err: std::time::SystemTimeError) -> Self { - Self::SystemTimeError(err) - } -} - -impl From>>>>> for Error { - fn from(_err: PoisonError>>>>) -> Self { - Self::Generic("Error obtaining lock") +impl From for Error { + fn from(err: String) -> Self { + Self::Generic(err) } } -impl From>>>> for Error { - fn from(_err: PoisonError>>>) -> Self { - Self::Generic("Error obtaining lock") +impl From> for Error { + fn from(err: PoisonError) -> Self { + Self::Generic(err.to_string()) } } @@ -189,8 +65,7 @@ impl std::fmt::Display for Error { Self::Git(err) => write!(f, "{err}"), Self::Gpg(err) => write!(f, "{err}"), Self::Utf8(err) => write!(f, "{err}"), - Self::Generic(err) => write!(f, "{err}"), - Self::GenericDyn(err) | Self::RecipientNotInKeyRing(err) => write!(f, "{err}"), + Self::Generic(err) | Self::RecipientNotInKeyRing(err) => write!(f, "{err}"), Self::PathError(err) => write!(f, "{err}"), Self::PatternError(err) => write!(f, "{err}"), Self::GlobError(err) => write!(f, "{err}"), @@ -204,6 +79,7 @@ impl std::fmt::Display for Error { Self::SystemTimeError(err) => write!(f, "{err}"), Self::NoneError => write!(f, "NoneError"), Self::TotpUrlError(_err) => write!(f, "TOTP url error"), + Self::OptionUtf8(_err) => write!(f, "FromUtf8Error"), } } } @@ -219,8 +95,8 @@ pub fn to_result( res: chrono::LocalResult>, ) -> Result> { match res { - chrono::LocalResult::None => Err(Error::Generic("no timezone")), + chrono::LocalResult::None => Err(Error::from("no timezone")), chrono::LocalResult::Single(t) => Ok(t), - chrono::LocalResult::Ambiguous(_, _) => Err(Error::Generic("too many timezones")), + chrono::LocalResult::Ambiguous(_, _) => Err(Error::from("too many timezones")), } } diff --git a/src/git.rs b/src/git.rs index 5de8a099..af32d4b7 100644 --- a/src/git.rs +++ b/src/git.rs @@ -18,13 +18,13 @@ fn git_branch_name(repo: &Repository) -> Result { let head = repo.find_reference("HEAD")?; let symbolic = head .symbolic_target() - .ok_or(Error::Generic("no symbolic target"))?; + .ok_or(Error::from("no symbolic target"))?; let mut parts = symbolic.split('/'); Ok(parts .nth(2) - .ok_or(Error::Generic( + .ok_or(Error::from( "symbolic target name should be on format 'refs/heads/main'", ))? .to_owned()) @@ -85,7 +85,7 @@ pub fn commit( pub fn find_last_commit(repo: &Repository) -> Result> { let obj = repo.head()?.resolve()?.peel(git2::ObjectType::Commit)?; obj.into_commit() - .map_err(|_| Error::Generic("Couldn't find commit")) + .map_err(|_| Error::from("Couldn't find commit")) } /// Returns if a git commit should be gpg signed or not. @@ -149,7 +149,7 @@ pub fn add_and_commit_internal( pub fn remove_and_commit(store: &PasswordStore, paths: &[PathBuf], message: &str) -> Result { let repo = store .repo() - .map_err(|_| Error::Generic("must have a repository"))?; + .map_err(|_| Error::from("must have a repository"))?; let mut index = repo.index()?; for path in paths { @@ -192,7 +192,7 @@ pub fn move_and_commit( ) -> Result { let repo = store .repo() - .map_err(|_| Error::Generic("must have a repository"))?; + .map_err(|_| Error::from("must have a repository"))?; let mut index = repo.index()?; index.remove_path(old_name)?; @@ -240,7 +240,7 @@ fn find_origin(repo: &Repository) -> Result<(git2::Remote<'_>, String)> { } } - Err(Error::Generic("no remotes configured")) + Err(Error::from("no remotes configured")) } /// function that can be used for callback handling of the ssh interaction in git2 @@ -272,7 +272,7 @@ fn cred( pub fn push(store: &PasswordStore) -> Result<()> { let repo = store .repo() - .map_err(|_| Error::Generic("must have a repository"))?; + .map_err(|_| Error::from("must have a repository"))?; let mut ref_status = None; let (mut origin, branch_name) = find_origin(&repo)?; @@ -291,10 +291,10 @@ pub fn push(store: &PasswordStore) -> Result<()> { }; match res { Ok(()) if ref_status.is_none() => Ok(()), - Ok(()) => Err(Error::GenericDyn(format!( - "failed to push a ref: {ref_status:?}", - ))), - Err(e) => Err(Error::GenericDyn(format!("failure to push: {e}"))), + Ok(()) => Err(Error::from( + format!("failed to push a ref: {ref_status:?}",), + )), + Err(e) => Err(Error::from(format!("failure to push: {e}"))), } } @@ -304,7 +304,7 @@ pub fn push(store: &PasswordStore) -> Result<()> { pub fn pull(store: &PasswordStore) -> Result<()> { let repo = store .repo() - .map_err(|_| Error::Generic("must have a repository"))?; + .map_err(|_| Error::from("must have a repository"))?; let (mut origin, branch_name) = find_origin(&repo)?; @@ -358,9 +358,9 @@ fn triple( Result, ) { ( - Err(Error::GenericDyn(format!("{e}"))), - Err(Error::GenericDyn(format!("{e}"))), - Err(Error::GenericDyn(format!("{e}"))), + Err(Error::from(format!("{e}"))), + Err(Error::from(format!("{e}"))), + Err(Error::from(format!("{e}"))), ) } @@ -388,9 +388,7 @@ pub fn read_git_meta_data( return triple(&e); } let blame = blame_res.unwrap(); - let id_res = blame - .get_line(1) - .ok_or(Error::Generic("no git history found")); + let id_res = blame.get_line(1).ok_or(Error::from("no git history found")); if let Err(e) = id_res { return triple(&e); @@ -428,7 +426,7 @@ pub fn verify_git_signature( let signed_data_str = str::from_utf8(&signed_data)?.to_owned(); if store.get_valid_gpg_signing_keys().is_empty() { - return Err(Error::Generic( + return Err(Error::from( "signature not checked as PASSWORD_STORE_SIGNING_KEY is not configured", )); } @@ -438,15 +436,15 @@ pub fn verify_git_signature( store.get_valid_gpg_signing_keys(), ) { Ok(r) => Ok(r), - Err(VerificationError::InfrastructureError(message)) => Err(Error::GenericDyn(message)), - Err(VerificationError::SignatureFromWrongRecipient) => Err(Error::Generic( + Err(VerificationError::InfrastructureError(message)) => Err(Error::from(message)), + Err(VerificationError::SignatureFromWrongRecipient) => Err(Error::from( "the commit wasn't signed by one of the keys specified in the environmental variable PASSWORD_STORE_SIGNING_KEY", )), - Err(VerificationError::BadSignature) => Err(Error::Generic("Bad signature for commit")), + Err(VerificationError::BadSignature) => Err(Error::from("Bad signature for commit")), Err(VerificationError::MissingSignatures) => { - Err(Error::Generic("Missing signature for commit")) + Err(Error::from("Missing signature for commit")) } - Err(VerificationError::TooManySignatures) => Err(Error::Generic( + Err(VerificationError::TooManySignatures) => Err(Error::from( "If a git commit contains more than one signature, something is fishy", )), } @@ -494,7 +492,7 @@ fn name_from_commit(commit: &git2::Commit) -> Result { commit .committer() .name() - .map_or(Err(Error::Generic("missing committer name")), |s| { + .map_or(Err(Error::from("missing committer name")), |s| { Ok(s.to_owned()) }) } diff --git a/src/pass.rs b/src/pass.rs index eb960635..415d9960 100644 --- a/src/pass.rs +++ b/src/pass.rs @@ -29,9 +29,8 @@ use config::Config; use totp_rs::TOTP; use zeroize::Zeroize; -use crate::crypto::Fingerprint; use crate::{ - crypto::{Crypto, CryptoImpl, GpgMe, Sequoia, VerificationError}, + crypto::{Crypto, CryptoImpl, Fingerprint, GpgMe, Sequoia, VerificationError}, git::{ add_and_commit_internal, commit, find_last_commit, init_git_repo, match_with_parent, move_and_commit, push_password_if_match, read_git_meta_data, remove_and_commit, @@ -94,20 +93,20 @@ impl PasswordStore { ) -> Result { let pass_home = password_dir_raw(password_store_dir, home); if !pass_home.exists() { - return Err(Error::Generic("failed to locate password directory")); + return Err(Error::from("failed to locate password directory")); } let crypto: Box = match crypto_impl { CryptoImpl::GpgMe => Box::new(GpgMe {}), CryptoImpl::Sequoia => { let home: PathBuf = home - .ok_or(Error::Generic( + .ok_or(Error::from( "no home, required for using Sequoia as pgp implementation", ))? .to_owned(); Box::new(Sequoia::new( &home.join(".local"), - own_fingerprint.ok_or_else(|| Error::Generic("own_fingerprint is not configured, required for using Sequoia as pgp implementation"))?.to_owned(), + own_fingerprint.ok_or_else(|| Error::from("own_fingerprint is not configured, required for using Sequoia as pgp implementation"))?.to_owned(), &home, )?) } @@ -146,19 +145,17 @@ impl PasswordStore { ) -> Result { let pass_home = password_dir_raw(password_store_dir, home); if pass_home.exists() { - return Err(Error::Generic( + return Err(Error::from( "trying to create a pass store in an existing directory", )); } if recipients.is_empty() { - return Err(Error::Generic( - "password store must have at least one member", - )); + return Err(Error::from("password store must have at least one member")); } for recipient in recipients { if recipient.key_id.len() != 40 && recipient.key_id.len() != 42 { - return Err(Error::Generic( + return Err(Error::from( "member specification wasn't a full pgp fingerprint", )); } @@ -171,7 +168,7 @@ impl PasswordStore { let mut fingerprints = vec![]; for r in recipients { fingerprints.push(r.fingerprint.ok_or_else(|| { - Error::GenericDyn(format!( + Error::from(format!( "recipient {} ({}) doesn't have a fingerprint", r.name, r.key_id )) @@ -273,7 +270,7 @@ impl PasswordStore { let gpg_id = fs::read(gpg_id_file)?; let Ok(gpg_id_sig) = fs::read(gpg_id_sig_file) else { - return Err(Error::Generic( + return Err(Error::from( "problem reading .gpg-id.sig, and strict signature checking was asked for", )); }; @@ -288,23 +285,23 @@ impl PasswordStore { SignatureStatus::Bad => return Ok(SignatureStatus::Bad), }, Err(VerificationError::InfrastructureError(message)) => { - return Err(Error::GenericDyn(message)); + return Err(Error::from(message)); } Err(VerificationError::SignatureFromWrongRecipient) => { - return Err(Error::Generic( + return Err(Error::from( "the .gpg-id file wasn't signed by one of the keys specified in the environmental variable PASSWORD_STORE_SIGNING_KEY", )); } Err(VerificationError::BadSignature) => { - return Err(Error::Generic("Bad signature for .gpg-id file")); + return Err(Error::from("Bad signature for .gpg-id file")); } Err(VerificationError::MissingSignatures) => { - return Err(Error::Generic( + return Err(Error::from( "Missing signature for .gpg-id file, and PASSWORD_STORE_SIGNING_KEY specified", )); } Err(VerificationError::TooManySignatures) => { - return Err(Error::Generic( + return Err(Error::from( "Signature for .gpg-id file contained more than one signature, something is fishy", )); } @@ -323,7 +320,7 @@ impl PasswordStore { let gpg_id = fs::read(gpg_id_file)?; let Ok(gpg_id_sig) = fs::read(gpg_id_sig_file) else { - return Err(Error::Generic( + return Err(Error::from( "problem reading .gpg-id.sig, and strict signature checking was asked for", )); }; @@ -333,17 +330,17 @@ impl PasswordStore { .verify_sign(&gpg_id, &gpg_id_sig, &self.valid_gpg_signing_keys) { Ok(r) => Ok(r), - Err(VerificationError::InfrastructureError(message)) => Err(Error::GenericDyn(message)), - Err(VerificationError::SignatureFromWrongRecipient) => Err(Error::Generic( + Err(VerificationError::InfrastructureError(message)) => Err(Error::from(message)), + Err(VerificationError::SignatureFromWrongRecipient) => Err(Error::from( "the .gpg-id file wasn't signed by one of the keys specified in the environmental variable PASSWORD_STORE_SIGNING_KEY", )), Err(VerificationError::BadSignature) => { - Err(Error::Generic("Bad signature for .gpg-id file")) + Err(Error::from("Bad signature for .gpg-id file")) } - Err(VerificationError::MissingSignatures) => Err(Error::Generic( + Err(VerificationError::MissingSignatures) => Err(Error::from( "Missing signature for .gpg-id file, and PASSWORD_STORE_SIGNING_KEY specified", )), - Err(VerificationError::TooManySignatures) => Err(Error::Generic( + Err(VerificationError::TooManySignatures) => Err(Error::from( "Signature for .gpg-id file contained more than one signature, something is fishy", )), } @@ -366,7 +363,7 @@ impl PasswordStore { if let Ok(c_file) = c_file_res && !c_file.starts_with(c_path.as_path()) { - return Err(Error::Generic( + return Err(Error::from( "trying to write outside of password store directory", )); } @@ -379,7 +376,7 @@ impl PasswordStore { } if path.exists() { - return Err(Error::Generic("file already exist")); + return Err(Error::from("file already exist")); } match self.new_password_file_internal(&path, path_end, content) { @@ -587,9 +584,9 @@ impl PasswordStore { passwords.push(PasswordEntry::new( &self.root, ¬_found, - Err(Error::Generic("")), - Err(Error::Generic("")), - Err(Error::Generic("")), + Err(Error::from("")), + Err(Error::from("")), + Err(Error::from("")), RepositoryStatus::NotInRepo, )); } @@ -634,7 +631,7 @@ impl PasswordStore { let root = fs::canonicalize(&self.root)?; if !new_dir.starts_with(&root) { - return Err(Error::Generic("path traversal is not allowed")); + return Err(Error::from("path traversal is not allowed")); } while new_dir.starts_with(&root) { @@ -646,7 +643,7 @@ impl PasswordStore { new_dir.pop(); } - Err(Error::Generic("No .gpg-id file found")) + Err(Error::from("No .gpg-id file found")) } fn visit_dirs(dir: &Path, result: &mut Vec) -> Result<()> { @@ -706,20 +703,20 @@ impl PasswordStore { self.crypto.pull_keys(&[r], config_path)?; } if !self.crypto.is_key_in_keyring(r)? { - return Err(Error::Generic( + return Err(Error::from( "Key isn't in keyring and couldn't be downloaded from keyservers", )); } let dir = self.root.join(path); if !dir.exists() { - return Err(Error::Generic("path doesn't exist")); + return Err(Error::from("path doesn't exist")); } let dir = fs::canonicalize(self.root.join(path))?; let root = fs::canonicalize(&self.root)?; if !dir.starts_with(root) { - return Err(Error::Generic("path traversal not allowed")); + return Err(Error::from("path traversal not allowed")); } if !dir.join(".gpg-id").exists() { File::create(dir.join(".gpg-id"))?; @@ -775,7 +772,7 @@ impl PasswordStore { pub fn add_and_commit(&self, paths: &[PathBuf], message: &str) -> Result { let repo = self.repo(); if repo.is_err() { - return Err(Error::Generic("must have a repository")); + return Err(Error::from("must have a repository")); } let repo = repo?; @@ -814,7 +811,7 @@ impl PasswordStore { /// Returns an `Err` if the file is missing, or the target already exists. pub fn rename_file(&mut self, old_name: &str, new_name: &str) -> Result { if new_name.starts_with('/') || new_name.contains("..") { - return Err(Error::Generic("directory traversal not allowed")); + return Err(Error::from("directory traversal not allowed")); } let mut old_path = self.root.clone(); @@ -825,11 +822,11 @@ impl PasswordStore { let new_path = append_extension(new_path, ".gpg"); if !old_path.exists() { - return Err(Error::Generic("source file is missing")); + return Err(Error::from("source file is missing")); } if new_path.exists() { - return Err(Error::Generic("can't target file already exists")); + return Err(Error::from("can't target file already exists")); } let mut new_path_dir = new_path.clone(); @@ -892,11 +889,11 @@ pub fn all_recipients_from_stores( let mut ar: HashMap = HashMap::new(); let stores = stores .lock() - .map_err(|_e| Error::Generic("problem locking the mutex"))?; + .map_err(|_e| Error::from("problem locking the mutex"))?; for store in stores.iter() { let store = store .lock() - .map_err(|_e| Error::Generic("problem locking the mutex"))?; + .map_err(|_e| Error::from("problem locking the mutex"))?; for recipient in store.all_recipients()? { let key = match recipient.fingerprint.as_ref() { None => recipient.key_id.clone(), @@ -1062,7 +1059,7 @@ impl PasswordEntry { pub fn secret(&self, store: &PasswordStore) -> Result { let s = fs::metadata(&self.path)?; if s.len() == 0 { - return Err(Error::Generic("empty password file")); + return Err(Error::from("empty password file")); } let content = fs::read(&self.path)?; @@ -1103,7 +1100,7 @@ impl PasswordEntry { Ok(totp.generate_current()?) } else { secret.zeroize(); - Err(Error::Generic("No otpauth:// url in secret")) + Err(Error::from("No otpauth:// url in secret")) } } @@ -1275,7 +1272,7 @@ pub fn search(store: &PasswordStore, query: &str) -> Vec { pub fn password_dir(password_store_dir: Option<&Path>, home: Option<&Path>) -> Result { let pass_home = password_dir_raw(password_store_dir, home); if !pass_home.exists() { - return Err(Error::Generic("failed to locate password directory")); + return Err(Error::from("failed to locate password directory")); } Ok(pass_home) } @@ -1407,7 +1404,7 @@ fn xdg_config_file_location( if let Some(h) = home { Ok(h.join(".config/ripasso/settings.toml")) } else { - Err(Error::Generic("no home directory")) + Err(Error::from("no home directory")) } } } @@ -1467,11 +1464,11 @@ pub fn save_config( let mut all_stores_map = HashMap::new(); let stores_borrowed = stores .lock() - .map_err(|_e| Error::Generic("problem locking the mutex"))?; + .map_err(|_e| Error::from("problem locking the mutex"))?; for store in stores_borrowed.iter() { let store = store .lock() - .map_err(|_e| Error::Generic("problem locking the mutex"))?; + .map_err(|_e| Error::from("problem locking the mutex"))?; let mut store_map = HashMap::new(); store_map.insert( "path", diff --git a/src/passphrase_generator.rs b/src/passphrase_generator.rs index b9f4b55e..1476a84c 100644 --- a/src/passphrase_generator.rs +++ b/src/passphrase_generator.rs @@ -1,7 +1,7 @@ -use crate::error::Result; -use crate::pass::Error; use rand::prelude::IndexedRandom; +use crate::{error::Result, pass::Error}; + static WORDLIST: &str = include_str!("wordlists/eff_large.wordlist"); /// Returns a pass phrase consisting of `word_count` number of @@ -18,7 +18,7 @@ pub fn passphrase_generator(word_count: usize) -> Result> { .collect(); if words.is_empty() { - return Err(Error::Generic("empty wordlist")); + return Err(Error::from("empty wordlist")); } let mut rng = rand::rng(); diff --git a/src/signature.rs b/src/signature.rs index 7f4f2ad4..d810fc63 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -6,8 +6,10 @@ use std::{ path::{Path, PathBuf}, }; -use crate::crypto::{FindSigningFingerprintStrategy, Fingerprint}; -use crate::error::{Error, Result}; +use crate::{ + crypto::{FindSigningFingerprintStrategy, Fingerprint}, + error::{Error, Result}, +}; /// A git commit for a password might be signed by a gpg key, and this signature's verification /// state is one of these values. @@ -52,14 +54,14 @@ pub fn parse_signing_keys( let have_0x = trimmed.starts_with("0x"); if !(len == 40 || len == 64 || len == 42 && have_0x || len == 66 && have_0x) { - return Err(Error::Generic( + return Err(Error::from( "signing key isn't in full 40/64 hex character fingerprint format", )); } let key_res = crypto.get_key(&trimmed); if let Some(err) = key_res.err() { - return Err(Error::GenericDyn(format!( + return Err(Error::from(format!( "signing key not found in keyring, error: {err}", ))); } @@ -424,7 +426,7 @@ impl Recipient { if recipients.is_empty() { if recipients_file == store_root_path.join(".gpg_id") { - Err(Error::Generic("Can't delete the last encryption key")) + Err(Error::from("Can't delete the last encryption key")) } else { Ok(fs::remove_file(recipients_file)?) } @@ -451,9 +453,7 @@ impl Recipient { for r in &recipients { if r == recipient { - return Err(Error::Generic( - "Team member is already in the list of key ids", - )); + return Err(Error::from("Team member is already in the list of key ids")); } } recipients.push((*recipient).clone()); diff --git a/src/tests/crypto.rs b/src/tests/crypto.rs index 4ac741fe..dc6bc310 100644 --- a/src/tests/crypto.rs +++ b/src/tests/crypto.rs @@ -4,9 +4,8 @@ use hex::FromHex; use sequoia_openpgp::{Cert, cert::CertBuilder, parse::Parse, serialize::Serialize}; use tempfile::tempdir; -use crate::crypto::Fingerprint; use crate::{ - crypto::{Crypto, CryptoImpl, Sequoia}, + crypto::{Crypto, CryptoImpl, Fingerprint, Sequoia}, signature::Recipient, }; diff --git a/src/tests/pass.rs b/src/tests/pass.rs index 8bc0b2a9..2edb4d25 100644 --- a/src/tests/pass.rs +++ b/src/tests/pass.rs @@ -72,7 +72,7 @@ fn get_password_dir_no_env() { assert_eq!( path.unwrap_err(), - Error::Generic("failed to locate password directory") + Error::from("failed to locate password directory") ); } @@ -392,7 +392,7 @@ fn env_var_exists_test_with_dir() { #[test] fn home_settings_missing() { assert_eq!( - Error::GenericDyn("no home directory set".to_owned()), + Error::from("no home directory set"), home_settings(None).err().unwrap() ); } @@ -1230,7 +1230,7 @@ fn mfa_no_otpauth_url() -> Result<()> { let res = pe.mfa(&store); - assert_eq!(Err(Error::Generic("No otpauth:// url in secret")), res); + assert_eq!(Err(Error::from("No otpauth:// url in secret")), res); Ok(()) } @@ -1621,7 +1621,7 @@ fn test_verify_git_signature() -> Result<()> { let result = verify_git_signature(&repo, &oid, &store); assert_eq!( - Error::Generic( + Error::from( "the commit wasn\'t signed by one of the keys specified in the environmental variable PASSWORD_STORE_SIGNING_KEY" ), result.err().unwrap() @@ -1726,7 +1726,7 @@ fn test_verify_gpg_id_files_missing_sig_file() -> Result<()> { assert!(result.is_err()); assert_eq!( - Error::Generic("problem reading .gpg-id.sig, and strict signature checking was asked for"), + Error::from("problem reading .gpg-id.sig, and strict signature checking was asked for"), result.err().unwrap() ); @@ -1763,7 +1763,7 @@ fn test_verify_gpg_id_files() -> Result<()> { assert!(result.is_err()); assert_eq!( - Error::Generic( + Error::from( "the .gpg-id file wasn't signed by one of the keys specified in the environmental variable PASSWORD_STORE_SIGNING_KEY" ), result.err().unwrap() @@ -1869,10 +1869,7 @@ fn test_verify_gpg_id_files_untrusted_key_in_keyring() { assert!(result.is_err()); - assert_eq!( - Error::GenericDyn("No valid signature".to_owned()), - result.err().unwrap() - ); + assert_eq!(Error::from("No valid signature"), result.err().unwrap()); } #[test] diff --git a/src/tests/signature.rs b/src/tests/signature.rs index e1877940..7b6d2907 100644 --- a/src/tests/signature.rs +++ b/src/tests/signature.rs @@ -1,7 +1,7 @@ use hex::FromHex; -use crate::crypto::Fingerprint; use crate::{ + crypto::Fingerprint, pass::{KeyRingStatus, OwnerTrustLevel, Recipient}, signature::{Comment, parse_signing_keys}, test_helpers::{MockCrypto, MockKey, append_file_name, recipient_alex, recipient_alex_old}, diff --git a/src/tests/test_helpers.rs b/src/tests/test_helpers.rs index b26747d4..2e1cc58e 100644 --- a/src/tests/test_helpers.rs +++ b/src/tests/test_helpers.rs @@ -21,9 +21,10 @@ use sequoia_openpgp::{ }; use tar::Archive; -use crate::crypto::Fingerprint; use crate::{ - crypto::{Crypto, CryptoImpl, FindSigningFingerprintStrategy, Key, VerificationError}, + crypto::{ + Crypto, CryptoImpl, FindSigningFingerprintStrategy, Fingerprint, Key, VerificationError, + }, error::{Error, Result}, pass::{KeyRingStatus, OwnerTrustLevel, SignatureStatus}, signature::{Comment, Recipient}, @@ -221,9 +222,7 @@ impl Crypto for MockCrypto { fn encrypt_string(&self, _: &str, _: &[Recipient]) -> Result> { self.encrypt_called.replace(true); if self.encrypt_string_error.is_some() { - Err(Error::GenericDyn( - self.encrypt_string_error.clone().unwrap(), - )) + Err(Error::from(self.encrypt_string_error.clone().unwrap())) } else { Ok(self.encrypt_string_return.clone()) } @@ -266,13 +265,11 @@ impl Crypto for MockCrypto { fn get_key(&self, key_id: &str) -> Result> { if self.get_key_string_error.is_some() { - Err(Error::GenericDyn( - self.get_key_string_error.clone().unwrap(), - )) + Err(Error::from(self.get_key_string_error.clone().unwrap())) } else if self.get_key_answers.contains_key(key_id) { Ok(Box::new(self.get_key_answers.get(key_id).unwrap().clone())) } else { - Err(Error::Generic("no key configured")) + Err(Error::from("no key configured")) } } From 23fa82e0b1b7b1ec0dcb75eeed939e4156577696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Kj=C3=A4ll?= Date: Sat, 7 Feb 2026 18:05:45 +0100 Subject: [PATCH 2/2] fix fmt --- src/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 686cb4d3..7868fa60 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,5 @@ -use std::{io, path, str::Utf8Error, string}; -use std::sync::PoisonError; +use std::{io, path, str::Utf8Error, string, sync::PoisonError}; + use hex::FromHexError; use thiserror::Error;