From 1e34c1737a5edfa1686d1375ec3d4ff418841179 Mon Sep 17 00:00:00 2001 From: tkhr0 Date: Sat, 2 Dec 2023 12:10:32 +0900 Subject: [PATCH] bump toml crate --- Cargo.lock | 111 ++++++++++++++++++++++++++++++++++++++++---------- Cargo.toml | 2 +- src/config.rs | 19 ++++----- src/mfa.rs | 8 ++-- 4 files changed, 102 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c59bd65..97a9701 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" version = "0.7.10" @@ -108,6 +110,12 @@ dependencies = [ "generic-array 0.12.3", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "fake-simd" version = "0.1.2" @@ -132,6 +140,12 @@ dependencies = [ "typenum", ] +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + [[package]] name = "hermit-abi" version = "0.1.13" @@ -151,6 +165,16 @@ dependencies = [ "digest", ] +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -165,9 +189,9 @@ checksum = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" [[package]] name = "memchr" -version = "2.3.3" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "mfa-cli" @@ -193,18 +217,18 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" [[package]] name = "proc-macro2" -version = "1.0.17" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1502d12e458c49a4c9cbff560d0fe0060c252bc29799ed94ca2ed4bb665a0101" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.6" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a21852a652ad6f610c9510194f398ff6f8692e334fd1145fed931f7fbe44ea" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -229,24 +253,33 @@ checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" [[package]] name = "serde" -version = "1.0.110" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e7b308464d16b56eba9964e4972a3eee817760ab60d88c3f86e1fecb08204c" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.110" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "818fbf6bfa9a42d3bfcaca148547aa00c7b915bec71d1757aa2d44ca68771984" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "serde_spanned" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80" +dependencies = [ + "serde", +] + [[package]] name = "sha-1" version = "0.8.2" @@ -273,13 +306,13 @@ checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" [[package]] name = "syn" -version = "1.0.23" +version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b5f192649e48a5302a13f2feb224df883b98933222369e4b3b0fe2a5447269" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -302,11 +335,36 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.6" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" +checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" dependencies = [ "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", ] [[package]] @@ -316,16 +374,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] -name = "unicode-width" -version = "0.1.7" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] -name = "unicode-xid" -version = "0.2.0" +name = "unicode-width" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" [[package]] name = "vec_map" @@ -354,3 +412,12 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winnow" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml index 2c0963f..5010fda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,6 @@ digest = "0.8.1" byteorder = "1" base32 = "0.4.0" clap = "2.33" -toml = "0.5" serde = { version = "1.0.0", features = ["derive"] } +toml = "0.8" regex = "1" diff --git a/src/config.rs b/src/config.rs index 0d3e994..1c9fc33 100644 --- a/src/config.rs +++ b/src/config.rs @@ -100,16 +100,16 @@ impl Config { } // Serialize to strings - pub fn serialize(&self) -> Result, String> { - match toml::to_vec(&self) { + pub fn serialize(&self) -> Result { + match toml::to_string(&self) { Ok(data) => Ok(data), Err(err) => Err(err.to_string()), } } // Deserialize config from strings - pub fn deserialize(&mut self, content: Vec) -> Result<(), String> { - match toml::from_slice(&content) { + pub fn deserialize(&mut self, content: &str) -> Result<(), String> { + match toml::from_str(content) { Ok(config) => { *self = config; Ok(()) @@ -202,9 +202,9 @@ mod tests { #[test] fn serialize_profile() { let profile = Profile::new("test", "secret"); - let expected = b"name = \"test\"\nsecret = \"secret\"\n"; + let expected = "name = \"test\"\nsecret = \"secret\"\n"; - assert_eq!(toml::to_vec(&profile).unwrap(), expected); + assert_eq!(toml::to_string(&profile).unwrap(), expected); } #[test] @@ -217,15 +217,12 @@ name = "test" secret = "secret" "#; - assert_eq!( - String::from_utf8(config.serialize().unwrap()).unwrap(), - expected - ); + assert_eq!(config.serialize().unwrap(), expected); } #[test] fn deserialize_config() { - let string_config = b"[[profiles]]\nname = \"test\"\nsecret = \"secret\"\n ".to_vec(); + let string_config = "[[profiles]]\nname = \"test\"\nsecret = \"secret\"\n "; let mut config: Config = Default::default(); config.deserialize(string_config).unwrap(); diff --git a/src/mfa.rs b/src/mfa.rs index 6905b65..3995029 100644 --- a/src/mfa.rs +++ b/src/mfa.rs @@ -97,7 +97,7 @@ impl Mfa { Ok(file) => file, Err(err) => return Err(err.to_string()), }; - match file.write_all(&config_data) { + match file.write_all(config_data.as_bytes()) { Ok(()) => Ok(()), Err(err) => Err(err.to_string()), } @@ -109,12 +109,12 @@ impl Mfa { Ok(file) => file, Err(err) => return Err(err.to_string()), }; - let mut buffer = Vec::new(); - if let Err(err) = file.read_to_end(&mut buffer) { + let mut contents = String::new(); + if let Err(err) = file.read_to_string(&mut contents) { return Err(err.to_string()); }; - self.config.deserialize(buffer) + self.config.deserialize(&contents) } // Run setup steps.