From 185eae25bdf3c5a50097d494ee5e9615a71e2263 Mon Sep 17 00:00:00 2001 From: Jisu-Woniu <31986081+Jisu-Woniu@users.noreply.github.com> Date: Tue, 7 Nov 2023 16:35:09 +0800 Subject: [PATCH] refactor: --- src-tauri/crypto/src/error.rs | 26 +++++++++++++++++++------- src-tauri/crypto/src/keygen.rs | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src-tauri/crypto/src/error.rs b/src-tauri/crypto/src/error.rs index e6c931c..f6bc0e8 100644 --- a/src-tauri/crypto/src/error.rs +++ b/src-tauri/crypto/src/error.rs @@ -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 = core::result::Result; +pub type Result = std::result::Result; + +impl From for Error { + fn from(error: spki::Error) -> Self { + Self::Pkcs8(pkcs8::Error::PublicKey(error)) + } +} + +impl From for Error { + fn from(error: der::Error) -> Self { + Self::Pkcs8(pkcs8::Error::Asn1(error)) + } +} diff --git a/src-tauri/crypto/src/keygen.rs b/src-tauri/crypto/src/keygen.rs index 0c041c3..b610fbb 100644 --- a/src-tauri/crypto/src/keygen.rs +++ b/src-tauri/crypto/src/keygen.rs @@ -52,6 +52,7 @@ pub async fn write_key_pair(path: impl AsRef) -> Result<()> { } Ok(()) } + #[cfg(test)] mod tests { use std::{env, io, path::PathBuf}; @@ -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?;