From 61ae9c60d9c3c40fecf3e74201fbbc48ae17fac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Thu, 14 Sep 2023 19:40:58 +0200 Subject: [PATCH] Add common error type --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- api/Cargo.toml | 8 ++++---- api/src/lib.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b004758..a4f9675 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -640,7 +640,7 @@ dependencies = [ [[package]] name = "zipsign" -version = "0.1.0-a.0" +version = "0.1.0-a.1" dependencies = [ "clap", "ed25519-dalek", @@ -652,7 +652,7 @@ dependencies = [ [[package]] name = "zipsign-api" -version = "0.1.0-a.0" +version = "0.1.0-a.1" dependencies = [ "base64", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index c3f7ad2..c73e57b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zipsign" description = "Sign and verify `.zip` and `.tar.gz` files with an ed25519 signing key" -version = "0.1.0-a.0" +version = "0.1.0-a.1" edition = "2021" authors = ["René Kijewski "] repository = "https://github.com/Kijewski/zipsign" @@ -22,7 +22,7 @@ thiserror = "1" zip = { version = "0.6", default-features = false } [workspace.dependencies.zipsign-api] -version = "0.1.0-a.0" +version = "0.1.0-a.1" path = "api" default-features = false features = ["verify-tar", "verify-zip", "sign-tar", "sign-zip"] diff --git a/api/Cargo.toml b/api/Cargo.toml index af0d949..5febf83 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zipsign-api" description = "Sign and verify `.zip` and `.tar.gz` files with an ed25519 signing key" -version = "0.1.0-a.0" +version = "0.1.0-a.1" edition = "2021" authors = ["René Kijewski "] repository = "https://github.com/Kijewski/zipsign" @@ -10,17 +10,17 @@ license = "Apache-2.0 WITH LLVM-exception" [dependencies] base64 = { workspace = true, optional = true } ed25519-dalek.workspace = true -thiserror = { workspace = true, optional = true } +thiserror.workspace = true zip = { workspace = true, optional = true } [features] default = ["tar", "zip"] -verify = ["dep:thiserror"] +verify = [] verify-tar = ["verify", "dep:base64"] verify-zip = ["verify"] -sign = ["dep:thiserror"] +sign = [] sign-tar = ["sign", "dep:base64"] sign-zip = ["sign", "dep:zip"] diff --git a/api/src/lib.rs b/api/src/lib.rs index 8eea711..999a96f 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -91,3 +91,50 @@ where let _: u64 = copy(input, &mut prehashed_message)?; Ok(prehashed_message) } + +/// A collection of all error this library can return +#[non_exhaustive] +#[derive(Debug, thiserror::Error)] +#[error(transparent)] +pub enum ZipsignError { + /// An error returned by [`gather_signature_data()`][self::sign::gather_signature_data] + #[cfg(feature = "sign")] + #[cfg_attr(docsrs, doc(cfg(feature = "sign")))] + GatherSignatureData(#[from] self::sign::GatherSignatureDataError), + /// An error returned by [`read_signing_keys()`][self::sign::read_signing_keys] + #[cfg(feature = "sign")] + #[cfg_attr(docsrs, doc(cfg(feature = "sign")))] + ReadSigningKeys(#[from] self::sign::ReadSigningKeysError), + /// An error returned by [`copy_and_sign_tar()`][self::sign::copy_and_sign_tar] + #[cfg(feature = "sign-tar")] + #[cfg_attr(docsrs, doc(cfg(feature = "sign-tar")))] + SignTar(#[from] self::sign::SignTarError), + /// An error returned by [`copy_and_sign_zip()`][self::sign::copy_and_sign_zip] + #[cfg(feature = "sign-zip")] + #[cfg_attr(docsrs, doc(cfg(feature = "sign-zip")))] + SignZip(#[from] self::sign::SignZipError), + + /// No matching key/signature pair found + #[cfg(feature = "verify")] + #[cfg_attr(docsrs, doc(cfg(feature = "verify")))] + NoMatch(#[from] self::verify::NoMatch), + /// An error returned by [`collect_keys()`][self::verify::collect_keys] + #[cfg(feature = "verify")] + #[cfg_attr(docsrs, doc(cfg(feature = "verify")))] + CollectKeys(#[from] self::verify::CollectKeysError), + /// An error returned by [`read_signatures()`][self::verify::read_signatures] + #[cfg(feature = "verify")] + #[cfg_attr(docsrs, doc(cfg(feature = "verify")))] + ReadSignatures(#[from] self::verify::ReadSignaturesError), + /// An error returned by [`verify_tar()`][self::verify::verify_tar] + #[cfg(feature = "verify-tar")] + #[cfg_attr(docsrs, doc(cfg(feature = "verify-tar")))] + VerifyTar(#[from] self::verify::VerifyTarError), + /// An error retuned by [`verify_zip()`][self::verify::verify_zip] + #[cfg(feature = "verify-zip")] + #[cfg_attr(docsrs, doc(cfg(feature = "verify-zip")))] + VerifyZip(#[from] self::verify::VerifyZipError), + + /// An I/O occurred + Io(#[from] std::io::Error), +}