Skip to content

Commit

Permalink
refactor:
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Nov 7, 2023
1 parent a43d5c8 commit 185eae2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src-tauri/crypto/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
use std::io;

use ed25519::pkcs8::{self, spki};
use rsa::pkcs8::der;
use ed25519::pkcs8::{
self,
spki::{self, der},
};

use thiserror::Error;

#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
Io(#[from] io::Error),

#[error(transparent)]
Pkcs8(#[from] pkcs8::Error),
#[error(transparent)]
Spki(#[from] spki::Error),
#[error(transparent)]
Der(#[from] der::Error),
}

pub type Result<T> = core::result::Result<T, Error>;
pub type Result<T> = std::result::Result<T, Error>;

impl From<spki::Error> for Error {
fn from(error: spki::Error) -> Self {
Self::Pkcs8(pkcs8::Error::PublicKey(error))
}
}

impl From<der::Error> for Error {
fn from(error: der::Error) -> Self {
Self::Pkcs8(pkcs8::Error::Asn1(error))
}
}
2 changes: 2 additions & 0 deletions src-tauri/crypto/src/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub async fn write_key_pair(path: impl AsRef<Path>) -> Result<()> {
}
Ok(())
}

#[cfg(test)]
mod tests {
use std::{env, io, path::PathBuf};
Expand Down Expand Up @@ -82,6 +83,7 @@ mod tests {
}

#[tokio::test]
#[ignore = "Manual testing for file generation."]
async fn test() -> Result<()> {
let tmp = tmp_dir("keygen").await?;
write_key_pair(dbg!(tmp).join("key")).await?;
Expand Down

0 comments on commit 185eae2

Please sign in to comment.