Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: CI

on:
push:
branches: [master]
pull_request:

permissions:
contents: read

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo build --locked
- run: cargo test --locked

smoke:
name: Smoke (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install tools (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg zip unzip zstd xz-utils libheif-examples
sudo apt-get install -y libheif-plugin-x265 || true
- name: Install tools (macOS)
if: runner.os == 'macOS'
run: |
brew install ffmpeg zstd libheif coreutils
echo "$(brew --prefix coreutils)/libexec/gnubin" >> "$GITHUB_PATH"
- name: Install c2patool (Linux)
if: runner.os == 'Linux'
run: cargo install c2patool --locked
- run: cargo build --locked
- run: scripts/smoke.sh

lint:
name: Format and Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --check
- run: cargo clippy --locked --all-targets -- -D warnings

msrv:
name: Minimum Rust version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.96
- uses: Swatinem/rust-cache@v2
- run: cargo check --locked
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "significant"
version = "0.3.0"
edition = "2024"
rust-version = "1.89"
rust-version = "1.96"
description = "Sign and verify files using C2PA (with no sidecar files)"
homepage = "https://github.com/Y2Z/significant"
repository = "https://github.com/Y2Z/significant"
Expand All @@ -18,7 +18,7 @@ path = "src/main.rs"

[dependencies]
anyhow = "1"
c2pa = { version = "0.91", features = ["file_io"] }
c2pa = { version = "0.91.7", features = ["file_io"] }
clap = { version = "4", features = ["derive"] }
pem = "3"
p256 = { version = "0.13", features = ["ecdsa", "pkcs8", "pem"] }
Expand Down
7 changes: 4 additions & 3 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ fn trailer_embed<F: Read + Write + Seek>(
) -> Result<Embedded> {
let start = f.seek(SeekFrom::End(0))?;
if kind == Kind::Tar {
if start < 1024 || start % BLOCK as u64 != 0 {
if start < 1024 || !start.is_multiple_of(BLOCK as u64) {
return Err(ArchiveError::Malformed("not a whole number of TAR blocks"));
}
let mut end = [0; 1024];
Expand All @@ -249,9 +249,10 @@ fn trailer_embed<F: Read + Write + Seek>(

fn frame_location(kind: Kind, start: u64, payload_len: usize) -> Embedded {
let payload = start + payload_offset(kind) as u64;
let whole_frame = start..start + frame_len(kind, payload_len) as u64;
Embedded {
payload: payload..payload + payload_len as u64,
exclusions: vec![start..start + frame_len(kind, payload_len) as u64],
exclusions: vec![whole_frame],
kind,
}
}
Expand All @@ -270,7 +271,7 @@ fn trailer_find<R: Read + Seek>(kind: Kind, r: &mut R) -> Result<Option<Embedded
continue;
}
let candidate = &tail[position..];
if kind == Kind::Tar && (base + position as u64) % BLOCK as u64 != 0 {
if kind == Kind::Tar && !(base + position as u64).is_multiple_of(BLOCK as u64) {
continue;
}
let Some(len) = frame_payload_len(kind, candidate) else {
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ pub fn manifest_ranges(path: &Path) -> Result<Option<Vec<Range<u64>>>> {
let found = find_occurrences(&mut file, &store, 2, SCAN_CHUNK)?;
match found.as_slice() {
[] => Err(Error::ManifestFragmented(path.to_path_buf())),
[start] => Ok(Some(vec![*start..start + store.len() as u64])),
[start] => {
let manifest = *start..start + store.len() as u64;
Ok(Some(vec![manifest]))
}
_ => Err(Error::ManifestAmbiguous(path.to_path_buf())),
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ fn print_verification(result: &significant::Verification) {
Some(id) => println!("signer: sha256:{id}"),
None => println!("signer: unknown"),
}
if result.trusted {
if let Some(name) = &result.claimed_name {
println!("name: {name}");
}
if result.trusted
&& let Some(name) = &result.claimed_name
{
println!("name: {name}");
}
let identity = match (result.intact, result.trusted) {
(false, _) => "not checked, content failed",
Expand Down
9 changes: 7 additions & 2 deletions src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ mod tests {

#[test]
fn unix_prefers_xdg_then_home() {
let both = [("HOME", "/home/a"), ("XDG_CONFIG_HOME", "/xdg")];
assert_eq!(resolve(&both, false), Some("/xdg/significant".into()));
// What counts as absolute depends on the platform running the test.
let xdg = std::env::temp_dir();
let both = [
("HOME", "/home/a"),
("XDG_CONFIG_HOME", xdg.to_str().unwrap()),
];
assert_eq!(resolve(&both, false), Some(xdg.join("significant")));
let home = [("HOME", "/home/a")];
assert_eq!(
resolve(&home, false),
Expand Down
Loading