From e4ad766315879e1ff05bb111229f073f8f0ed68e Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Mon, 10 Oct 2022 21:30:02 +0200 Subject: PassFish: Initial Commit Well, that's a lie. But nobody needs to see all the iterations I decided to sweep under the rug. That said, I think the repo is, while not clean, clean enough now, to not be embarrassed by uploading it to github. --- rust/src/implementation/mod.rs | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 rust/src/implementation/mod.rs (limited to 'rust/src/implementation/mod.rs') diff --git a/rust/src/implementation/mod.rs b/rust/src/implementation/mod.rs new file mode 100644 index 0000000..889e743 --- /dev/null +++ b/rust/src/implementation/mod.rs @@ -0,0 +1,70 @@ +mod profiles; +mod passwordmaker; +mod pwm_macros; + +pub use self::profiles::Profiles; +pub use self::passwordmaker::PasswordMaker; +pub use self::passwordmaker::Settings; + +//------------------------------------------------------------------------------ +// helper types that are used in multiple modules. + +fn get_config_folder() -> Option { + dirs::config_dir() + .map(|p| p.join("info.grois/harbour-passfish/")) +} + +#[derive(Debug)] +enum LoadError { + Xdg, + Loading(std::io::Error), + Parsing(toml::de::Error), +} +impl std::fmt::Display for LoadError { + fn fmt(&self, f : &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + match self { + LoadError::Xdg => { write!(f, "XDG config path not found") } + LoadError::Loading(e) => { e.fmt(f) } + LoadError::Parsing(e) => { e.fmt(f) } + } + } +} +impl std::error::Error for LoadError {} +impl From for LoadError { + fn from(e : std::io::Error) -> Self { + LoadError::Loading(e) + } +} +impl From for LoadError { + fn from(e : toml::de::Error) -> Self { + LoadError::Parsing(e) + } +} + + +#[derive(Debug)] +enum StoreError { + Xdg, + Writing(std::io::Error), + Serialization(toml::ser::Error) +} +impl std::fmt::Display for StoreError { + fn fmt(&self, f : &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + match self { + StoreError::Xdg => { write!(f, "XDC config path not found") } + StoreError::Writing(e) => { e.fmt(f) } + StoreError::Serialization(e) => { e.fmt(f) } + } + } +} +impl std::error::Error for StoreError {} +impl From for StoreError { + fn from(e: std::io::Error) -> Self { + StoreError::Writing(e) + } +} +impl From for StoreError { + fn from(e: toml::ser::Error) -> Self { + StoreError::Serialization(e) + } +} -- cgit v1.2.3