Skip to content

Commit

Permalink
Little better docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski committed Sep 13, 2023
1 parent bb71ae5 commit b08fcf1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ authors = ["René Kijewski <[email protected]>"]
license = "MIT OR Apache-2.0 WITH LLVM-exception"

[workspace]
resolver = "2"
members = [".", "api"]
default-members = [".", "api"]

Expand All @@ -29,3 +30,7 @@ rand_core.workspace = true
thiserror.workspace = true
zip.workspace = true
zipsign-api.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
7 changes: 6 additions & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ authors = ["René Kijewski <[email protected]>"]
license = "MIT OR Apache-2.0 WITH LLVM-exception"

[dependencies]
base64.workspace = true
base64 = { workspace = true, optional = true }
ed25519-dalek.workspace = true
thiserror.workspace = true

[features]
default = ["verify-tar", "verify-zip"]
verify-tar = ["dep:base64"]
verify-zip = []
3 changes: 3 additions & 0 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

pub mod verify;

#[doc(no_inline)]
pub use ed25519_dalek::{Sha512, SignatureError, VerifyingKey, PUBLIC_KEY_LENGTH};

// "\x0c\x04\x01" -- form feed, end of text, start of header
// "ed25519ph" -- used algorithm
// "\x00\x00" -- version number in network byte order
Expand Down
34 changes: 24 additions & 10 deletions api/src/verify.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
//! Common functions to verify a signed file

use std::io::{copy, Read, Seek, SeekFrom};
#[cfg(feature = "verify-tar")]
use std::io::SeekFrom;
use std::io::{copy, Read, Seek};

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
#[cfg(feature = "verify-tar")]
use base64::{prelude::BASE64_STANDARD, Engine};
use ed25519_dalek::{Digest, Signature, SIGNATURE_LENGTH};
#[doc(no_inline)]
pub use ed25519_dalek::{Sha512, SignatureError, VerifyingKey, PUBLIC_KEY_LENGTH};

use crate::{SignatureCountLeInt, GZIP_END, GZIP_START, HEADER_SIZE, MAGIC_HEADER};
use crate::{
Sha512, SignatureCountLeInt, SignatureError, VerifyingKey, HEADER_SIZE, MAGIC_HEADER,
PUBLIC_KEY_LENGTH,
};
#[cfg(feature = "verify-tar")]
use crate::{GZIP_END, GZIP_START};

const BUF_LIMIT: usize = 1 << 17; // 128 kiB

Expand Down Expand Up @@ -38,8 +43,10 @@ pub enum Error {
IllegalSignature(#[source] SignatureError, usize),
}

/// Find the index of the first [`VerifyingKey`] that matches the a signature in a signed .tar.gz
/// Find the index of the first [`VerifyingKey`] that matches the a signature in a signed `.tar.gz`
/// file
#[cfg(feature = "verify-tar")]
#[cfg_attr(docsrs, doc(cfg(feature = "verify-tar")))]
pub fn verify_tar<R: ?Sized + Read + Seek>(
signed_file: &mut R,
keys: &[[u8; PUBLIC_KEY_LENGTH]],
Expand All @@ -50,7 +57,10 @@ pub fn verify_tar<R: ?Sized + Read + Seek>(
find_match(&keys, &signatures, &prehashed_message, context)
}

/// Find the index of the first [`VerifyingKey`] that matches the a signature in a signed .zip file
/// Find the index of the first [`VerifyingKey`] that matches the a signature in a signed `.zip`
/// file
#[cfg(feature = "verify-zip")]
#[cfg_attr(docsrs, doc(cfg(feature = "verify-zip")))]
pub fn verify_zip<R: ?Sized + Read + Seek>(
signed_file: &mut R,
keys: &[[u8; PUBLIC_KEY_LENGTH]],
Expand Down Expand Up @@ -89,7 +99,9 @@ pub fn find_match(
Err(Error::NoMatch)
}

/// Hash the content of a signed .tar.gz file, and collect all contained signatures
/// Hash the content of a signed `.tar.gz` file, and collect all contained signatures
#[cfg(feature = "verify-tar")]
#[cfg_attr(docsrs, doc(cfg(feature = "verify-tar")))]
pub fn read_tar<R: ?Sized + Read + Seek>(signed_file: &mut R) -> Result<(Sha512, Vec<Signature>)> {
// seek to start of base64 encoded signatures
let mut tail = [0; u64::BITS as usize / 4 + GZIP_END.len()];
Expand Down Expand Up @@ -156,7 +168,9 @@ pub fn read_tar<R: ?Sized + Read + Seek>(signed_file: &mut R) -> Result<(Sha512,
Ok((prehashed_message, signatures))
}

/// Hash the content of a signed .zip file, and collect all contained signatures
/// Hash the content of a signed `.zip` file, and collect all contained signatures
#[cfg(feature = "verify-zip")]
#[cfg_attr(docsrs, doc(cfg(feature = "verify-zip")))]
pub fn read_zip<R: ?Sized + Read + Seek>(signed_file: &mut R) -> Result<(Sha512, Vec<Signature>)> {
let signatures = read_signatures(signed_file)?;
let prehashed_message = prehash(signed_file)?;
Expand Down
2 changes: 1 addition & 1 deletion src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::path::PathBuf;
use clap::{Args, Parser, Subcommand};
use zipsign_api::verify::{
collect_keys, find_match, prehash, read_signatures, read_tar, read_zip, Error as ApiError,
SignatureError, PUBLIC_KEY_LENGTH,
};
use zipsign_api::{SignatureError, PUBLIC_KEY_LENGTH};

pub(crate) fn main(args: Cli) -> Result<(), Error> {
let (kind, input, mut args) = args.subcommand.split();
Expand Down

0 comments on commit b08fcf1

Please sign in to comment.