Skip to content

Commit

Permalink
bump toml crate
Browse files Browse the repository at this point in the history
  • Loading branch information
tkhr0 committed Dec 2, 2023
1 parent bc9f70c commit 9aaada6
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 31 deletions.
111 changes: 89 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ impl Config {
}

// Serialize to strings
pub fn serialize(&self) -> Result<Vec<u8>, String> {
match toml::to_vec(&self) {
pub fn serialize(&self) -> Result<String, String> {
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<u8>) -> 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(())
Expand Down
8 changes: 4 additions & 4 deletions src/mfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
Expand All @@ -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.
Expand Down

0 comments on commit 9aaada6

Please sign in to comment.