Skip to content

Commit

Permalink
feat: 🥅 Checking for errors in frontend code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Nov 25, 2023
1 parent 98f29b7 commit 6a649de
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file.

## [unreleased]
## [1.0.2] - 2023-11-25

### Miscellaneous Tasks

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ panic = "abort"
strip = true

[dev-dependencies]
tokio = { version = "1.34.0", features = ["rt-multi-thread"] }
tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread"] }
12 changes: 9 additions & 3 deletions src-tauri/crypto/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn sign(
Ok(sig_conf.sign(secret_key, passwd_fn, data)?)
}

/// Sign the given file with the given secret key.
/// Sign the given file with the specified secret key and password function.
///
/// # Errors
///
Expand Down Expand Up @@ -70,11 +70,17 @@ where
Ok(signature_path)
}

/// .
/// Verify the given signature with the specified public key.
///
/// # Errors
///
/// This function will return an error if .
/// This function will return an error if:
/// - The file, signature or public key cannot be read.
/// - The signature or public key's format is invalid.
///
/// However, these will not be considered an error, a `Ok(false)` is returned instead:
/// - The signature is signed with a secret key having a key ID different from that of public key.
/// - The file's hash does not match the one in signature.
pub async fn verify_file_with_key<S, P>(signature_path: S, public_key_path: P) -> Result<bool>
where
S: AsRef<Path> + Send,
Expand Down
22 changes: 2 additions & 20 deletions src-tauri/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub enum FileType {
File = 0,
Dir = 1,
Other = 2,
Inexist = 3,
Unavailable = 3,
}

impl Serialize for FileType {
Expand All @@ -35,7 +35,7 @@ pub async fn detect_file_type(path: &Path) -> Result<FileType> {
FileType::Other
}
}
Err(_) => FileType::Inexist,
Err(_) => FileType::Unavailable,
})
}

Expand All @@ -46,21 +46,3 @@ pub fn get_file_names(files: Vec<&Path>) -> Vec<&OsStr> {
.filter_map(|file| file.file_name())
.collect()
}

#[cfg(test)]
mod tests {
use std::path::PathBuf;

use super::detect_file_type;

#[tokio::test]
async fn test() {
println!("{:?}", detect_file_type(&PathBuf::from("/home/")).await);
println!("{:?}", detect_file_type(&PathBuf::from("/etc/fstab")).await);
println!(
"{:?}",
detect_file_type(&PathBuf::from("/home/inexist")).await
);
println!("{:?}", detect_file_type(&PathBuf::from("/bin/sh")).await);
}
}
2 changes: 1 addition & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const generateKeyPair = (
export const enum FileType {
dir = 1,
file = 0,
inexist = 3,
unavailable = 3,
other = 2,
}

Expand Down
4 changes: 2 additions & 2 deletions src/views/KeygenView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ const generate = async () => {
);
await message(
"生成成功\n" +
`你的私钥路径为:${paths.secretKeyPath}\n` +
`您的私钥路径为:${paths.secretKeyPath}\n` +
`公钥路径为:${paths.publicKeyPath}`,
);
}
} catch (x) {
await message("生成失败\n发生如下错误\n" + x);
await message("生成失败,发生了以下错误\n" + x);
}
};
</script>
Expand Down
20 changes: 12 additions & 8 deletions src/views/SignView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@ const back = () => {
const submit = async () => {
if (valid.value) {
if (step.value === items.value.length) {
const signatures = await signFiles(
data.filePaths,
data.keyPath,
data.passwd,
);
await message(
"签名成功。\n您的签名文件保存于:\n" + signatures.join("\n"),
);
try {
const signatures = await signFiles(
data.filePaths,
data.keyPath,
data.passwd,
);
await message(
"签名成功。\n您的签名文件保存于:\n" + signatures.join("\n"),
);
} catch (error) {
await message("校验失败,发生了以下错误:\n" + JSON.stringify(error));
}
} else {
step.value += 1;
}
Expand Down
21 changes: 14 additions & 7 deletions src/views/ValidateView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ const back = () => {
const submit = async () => {
if (valid.value) {
if (step.value === items.value.length) {
const results = await verifySignatures(data.signaturePaths, data.keyPath);
await message(
"校验成功\n" +
Object.keys(results)
.map((key) => `${key}: ${results[key] ? "✔️" : ""}`)
.join("\n"),
);
try {
const results = await verifySignatures(
data.signaturePaths,
data.keyPath,
);
await message(
"校验成功\n" +
Object.keys(results)
.map((key) => `${key}: ${results[key] ? "✔️" : ""}`)
.join("\n"),
);
} catch (error) {
await message("校验失败,发生了以下错误:\n" + JSON.stringify(error));
}
} else {
step.value += 1;
}
Expand Down

0 comments on commit 6a649de

Please sign in to comment.