Skip to content

Commit

Permalink
Merge pull request #4 from dfns/new-release
Browse files Browse the repository at this point in the history
udigest v0.2
  • Loading branch information
survived authored Jun 5, 2024
2 parents d253182 + 15fd58c commit 8410883
Show file tree
Hide file tree
Showing 15 changed files with 656 additions and 127 deletions.
22 changes: 22 additions & 0 deletions .github/changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

m_branch=m;
changelog_file=CHANGELOG.md;

# fetch master since we might be in a shallow clone
git fetch origin "$m_branch:$m_branch" --depth=1

changed=0;
for log in */"$changelog_file"; do
dir=$(dirname "$log");
# check if version changed
if git diff "$m_branch" -- "$dir/Cargo.toml" | grep -q "^-version = "; then
# check if changelog updated
if git diff --exit-code --no-patch "$m_branch" -- "$log"; then
echo "$dir version changed, but $log is not updated"
changed=1;
fi
fi
done

exit "$changed";
24 changes: 16 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,31 @@ env:
CARGO_NET_GIT_FETCH_WITH_CLI: true

jobs:
build-and-test:
check-and-test:
strategy:
matrix:
features: ["", "derive", "derive,alloc", "derive,std"]
features: ["", "derive", "derive,alloc", "derive,std", "digest", "digest,std"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "true"
- name: Build
run: cargo build -p udigest --features "${{ matrix.features }}"
- name: Check
run: cargo check -p udigest --features "${{ matrix.features }}"
- name: Run tests
run: cargo test -p udigest --lib --tests --features "${{ matrix.features }}"
doctest:
test-all-features:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "true"
- name: Doctests
run: cargo test --doc --all-features
- name: Check
run: cargo check -p udigest --all-features
- name: Run tests
run: cargo test -p udigest --all-features
run-examples:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -64,4 +66,10 @@ jobs:
with:
cache-on-failure: "true"
- name: Run clippy
run: cargo clippy -- -D clippy::all
run: cargo clippy --all-features -- -D clippy::all
check-changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check changelogs
run: ./.github/changelog.sh
39 changes: 38 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
.PHONY: docs docs-open

docs:
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --no-deps --all-features

docs-open:
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --no-deps --all-features --open

docs-private:
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --no-deps --all-features --document-private-items

readme:
cargo readme -i src/lib.rs -r udigest/ -t ../docs/readme.tpl \
| perl -ne 's/\[(.+?)\]\((?!https).+?\)/\1/g; print;' \
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,34 @@ data can be anything that implements `Digestable` trait:

The trait is intentionally not implemented for certain types:

* `HashMap`, `HashSet` as they can not be traversed in determenistic order
* `usize`, `isize` as their byte size varies on differnet platforms
* `HashMap`, `HashSet` as they can not be traversed in deterministic order
* `usize`, `isize` as their byte size varies on different platforms

The `Digestable` trait can be implemented for the struct using a macro:
```rust
use udigest::{Tag, udigest};
use sha2::Sha256;

#[derive(udigest::Digestable)]
struct Person {
name: String,
job_title: String,
}
let alice = &Person {
let alice = Person {
name: "Alice".into(),
job_title: "cryptographer".into(),
};

let tag = Tag::<Sha256>::new("udigest.example");
let hash = udigest(tag, &alice);
let hash = udigest::hash::<sha2::Sha256>(&alice);
```

The crate intentionally does not try to follow any existing standards for unambiguous
encoding. The format for encoding was desingned specifically for `udigest` to provide
encoding. The format for encoding was designed specifically for `udigest` to provide
a better usage experience in Rust. The details of encoding format can be found in
`encoding` module.

### Features
* `digest` enables support of hash functions that implement `digest` traits \
If feature is not enabled, the crate is still usable via `Digestable` trait that
generically implements unambiguous encoding
* `inline-struct` is required to use `inline_struct!` macro
* `std` implements `Digestable` trait for types in standard library
* `alloc` implements `Digestable` trait for type in `alloc` crate
* `derive` enables `Digestable` proc macro
11 changes: 11 additions & 0 deletions cspell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
words:
- digestable
- udigest
- VecDeque
- bytestring
- bytestrings
- biglen
- sublist
- docsrs
- concated
- inlines
14 changes: 14 additions & 0 deletions udigest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## v0.2.0
* Breaking change: remove `udigest::Tag` [#4]
* Breaking change: rename `udigest::udigest` function to `udigest::hash` [#4]
* Add support of all hash functions compatible with `digest` crate:
hash functions with fixed output, with extendable output, and with
variable output [#4]
* Add `udigest::inline_struct!` macro [#4]
* fix: handle cases when `EncodeValue` is dropped without being used

[#4]: https://github.com/dfns/udigest/pull/4

## v0.1.0

The first release!
27 changes: 22 additions & 5 deletions udigest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "udigest"
version = "0.1.0"
version = "0.2.0-rc1"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Unambiguously digest structured data"
Expand All @@ -11,27 +11,44 @@ readme = "../README.md"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
digest = { version = "0.10", default-features = false }
digest = { version = "0.10", default-features = false, optional = true }

udigest-derive = { version = "0.1", optional = true }

[dev-dependencies]
sha2 = "0.10"
hex = "0.4"

sha2 = "0.10"
sha3 = "0.10"
blake2 = "0.10"

[features]
default = ["digest", "std", "inline-struct"]

std = ["alloc"]
alloc = []
derive = ["dep:udigest-derive"]

digest = ["dep:digest"]
inline-struct = []

[[test]]
name = "derive"
required-features = ["std", "derive"]
required-features = ["std", "derive", "digest"]

[[test]]
name = "deterministic_hash"
required-features = ["derive", "digest"]

[[test]]
name = "inline_struct"
required-features = ["derive", "inline-struct"]

[[example]]
name = "derivation"
required-features = ["std", "derive"]
required-features = ["std", "derive", "digest"]
6 changes: 1 addition & 5 deletions udigest/examples/derivation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use sha2::Sha256;
use udigest::udigest;

#[derive(udigest::Digestable)]
#[udigest(tag = "udigest.example.Person.v1")]
struct Person {
Expand All @@ -15,7 +12,6 @@ fn main() {
job_title: "cryptographer".into(),
};

let tag = udigest::Tag::<Sha256>::new("udigest.example");
let hash = udigest(tag, &person);
let hash = udigest::hash::<sha2::Sha256>(&person);
println!("{}", hex::encode(hash));
}
Loading

0 comments on commit 8410883

Please sign in to comment.