Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich authored Nov 4, 2024
2 parents 9293f78 + 107f9d0 commit caad8c5
Show file tree
Hide file tree
Showing 19 changed files with 804 additions and 32 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Support for sqlx @ 0.8 ([#400])
- Support for fastrlp @ 0.4 ([#401])
- Added support for [`subtle`](https://docs.rs/subtle) and [`der`](https://docs.rs/der) ([#399])

### Removed

- Support for sqlx @ 0.7. This is a breaking change, outside of
regular semver policy, as 0.7 contains a security vulnerability ([#400])

[#399]: https://github.com/recmo/uint/pull/399
[#400]: https://github.com/recmo/uint/pull/400
[#401]: https://github.com/recmo/uint/pull/401

## [1.12.3] - 2024-06-03

### Changed
Expand Down
48 changes: 37 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ repository.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs", "--html-in-header", ".cargo/katex-header.html"]
rustdoc-args = [
"--cfg",
"docsrs",
"--html-in-header",
".cargo/katex-header.html",
]

[workspace]
members = [".", "ruint-macro"]
Expand Down Expand Up @@ -47,8 +52,14 @@ arbitrary = { version = "1", optional = true, default-features = false }
ark-ff-03 = { version = "0.3.0", package = "ark-ff", optional = true, default-features = false }
ark-ff-04 = { version = "0.4.0", package = "ark-ff", optional = true, default-features = false }
bn-rs = { version = "0.2", optional = true, default-features = true }
fastrlp = { version = "0.3", optional = true, default-features = false, features = ["alloc"] }
fastrlp-03 = { version = "0.3", package = "fastrlp", optional = true, default-features = false, features = [
"alloc",
] }
fastrlp-04 = { version = "0.4", package = "fastrlp", optional = true, default-features = false, features = [
"alloc",
] }
num-bigint = { version = "0.4", optional = true, default-features = false }
num-integer = { version = "0.1", optional = true, default-features = false }
num-traits = { version = "0.2.16", optional = true, default-features = false }
parity-scale-codec = { version = "3", optional = true, features = [
"derive",
Expand All @@ -65,13 +76,17 @@ valuable = { version = "0.1", optional = true, default-features = false }
zeroize = { version = "1.6", optional = true, default-features = false }
bytemuck = { version = "1.13.1", optional = true, default-features = false }
ethereum_ssz = { version = "0.5.3", optional = true, default-features = false }
der = { version = "0.7", optional = true, default-features = false, features = [
"alloc",
] }
subtle = { version = "2.6.1", optional = true, default-features = false }

# postgres
bytes = { version = "1.4", optional = true }
postgres-types = { version = "0.2", optional = true }

# sqlx
sqlx-core = { version = "0.7", optional = true }
sqlx-core = { version = "0.8.2", optional = true }

[dev-dependencies]
ruint = { path = ".", features = ["arbitrary", "proptest"] }
Expand All @@ -98,8 +113,10 @@ std = [
"ark-ff-03?/std",
"ark-ff-04?/std",
"bytes?/std",
"fastrlp?/std",
"fastrlp-03?/std",
"fastrlp-04?/std",
"num-bigint?/std",
"num-integer?/std",
"num-traits?/std",
"parity-scale-codec?/std",
"primitive-types?/std",
Expand All @@ -111,7 +128,13 @@ std = [
"zeroize?/std",
]
ssz = ["std", "dep:ethereum_ssz"]
alloc = ["proptest?/alloc", "rand?/alloc", "serde?/alloc", "valuable?/alloc", "zeroize?/alloc"]
alloc = [
"proptest?/alloc",
"rand?/alloc",
"serde?/alloc",
"valuable?/alloc",
"zeroize?/alloc",
]

# nightly-only features
nightly = []
Expand All @@ -123,20 +146,23 @@ arbitrary = ["dep:arbitrary", "std"]
ark-ff = ["dep:ark-ff-03"]
ark-ff-04 = ["dep:ark-ff-04"]
bn-rs = ["dep:bn-rs", "std"]
fastrlp = ["dep:fastrlp", "alloc"]
bytemuck = ["dep:bytemuck"]
der = ["dep:der", "alloc"] # TODO: also have alloc free der impls.
fastrlp = ["dep:fastrlp-03", "alloc"]
fastrlp-04 = ["dep:fastrlp-04", "alloc"]
num-bigint = ["dep:num-bigint", "alloc"]
num-integer = ["dep:num-integer", "num-traits", "alloc"]
num-traits = ["dep:num-traits", "alloc"]
parity-scale-codec = ["dep:parity-scale-codec", "alloc"]
postgres = ["dep:postgres-types", "dep:bytes", "dep:thiserror", "std"]
primitive-types = ["dep:primitive-types"]
proptest = ["dep:proptest", "alloc"]
pyo3 = ["dep:pyo3", "std"]
quickcheck = ["dep:quickcheck", "std"]
rand = ["dep:rand"]
rlp = ["dep:rlp", "alloc"]
serde = ["dep:serde", "alloc"] # TODO: try to avoid alloc in serde impls
serde = ["dep:serde", "alloc"] # TODO: try to avoid alloc in serde impls
sqlx = ["dep:sqlx-core", "std", "dep:thiserror"]
subtle = ["dep:subtle"]
valuable = ["dep:valuable"]
zeroize = ["dep:zeroize"]
bytemuck = ["dep:bytemuck"]

postgres = ["dep:postgres-types", "dep:bytes", "std", "dep:thiserror"]
sqlx = ["dep:sqlx-core", "std", "dep:thiserror"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ named feature flag.
* [`bn-rs`](https://docs.rs/bn-rs/latest/bn_rs/): Implements conversion to/from the [`BN`](https://docs.rs/bn-rs/latest/bn_rs/struct.BN.html) and [`BigNumber`](https://docs.rs/bn-rs/latest/bn_rs/struct.BigNumber.html).
* [`bytemuck`](https://docs.rs/bytemuck): Implements the [`Pod`](https://docs.rs/bytemuck/latest/bytemuck/trait.Pod.html) and [`Zeroable`](https://docs.rs/bytemuck/latest/bytemuck/trait.Zeroable.html) traits for [`Uint`] where the size is a multiple of 64, up to 1024. This allows `Uint` to be used where a `Pod` trait bound exists.
* [`num-traits`](https://docs.rs/num-traits): Implements about forty applicable traits.
* [`subtle`](https://docs.rs/subtle): Implements [`Uint::bit_ct`], [`ConditionallySelectable`](https://docs.rs/subtle/latest/subtle/trait.ConditionallySelectable.html),[`ConditionallyNegatable`](https://docs.rs/subtle/latest/subtle/trait.ConditionallyNegatable.html), [`ConstantTimeEq`](https://docs.rs/subtle/latest/subtle/trait.ConstantTimeEq.html)/[`ConstantTimeGreater`](https://docs.rs/subtle/latest/subtle/trait.ConstantTimeGreater.html)/[`ConstantTimeLess`](https://docs.rs/subtle/latest/subtle/trait.ConstantTimeLess.html).
* [`der`](https://docs.rs/der): Implements [`Encode`](https://docs.rs/der/latest/der/trait.Encode.html)/[`Decode`](https://docs.rs/der/latest/der/trait.Decode.html) and [`TryFrom`]/[`From`] casting for [`Any`](https://docs.rs/der/latest/der/asn1/struct.Any.html), [`AnyRef`](https://docs.rs/der/latest/der/asn1/struct.AnyRef.html), [`Int`](https://docs.rs/der/latest/der/asn1/struct.Int.html), [`IntRef`](https://docs.rs/der/latest/der/asn1/struct.IntRef.html), [`Uint`](https://docs.rs/der/latest/der/asn1/struct.Uint.html), [`UintRef`](https://docs.rs/der/latest/der/asn1/struct.UintRef.html).

## Building and testing

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ alias! {
// TODO: I0, I1, I8, ... I4096

#[cfg(test)]
pub mod tests {
mod tests {
use super::*;

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/base_convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,15 @@ mod tests {
#[test]
fn test_from_base_be_overflow() {
assert_eq!(
Uint::<0, 0>::from_base_be(10, std::iter::empty()),
Uint::<0, 0>::from_base_be(10, core::iter::empty()),
Ok(Uint::<0, 0>::ZERO)
);
assert_eq!(
Uint::<0, 0>::from_base_be(10, std::iter::once(0)),
Uint::<0, 0>::from_base_be(10, core::iter::once(0)),
Ok(Uint::<0, 0>::ZERO)
);
assert_eq!(
Uint::<0, 0>::from_base_be(10, std::iter::once(1)),
Uint::<0, 0>::from_base_be(10, core::iter::once(1)),
Err(BaseConvertError::Overflow)
);
assert_eq!(
Expand Down
8 changes: 6 additions & 2 deletions src/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,11 @@ mod tests {
}

#[test]
#[allow(clippy::cast_lossless, clippy::cast_possible_truncation)]
#[allow(
clippy::cast_lossless,
clippy::cast_possible_truncation,
clippy::cast_possible_wrap
)]
fn test_small() {
const_for!(BITS in [1, 2, 8, 16, 32, 63, 64] {
type U = Uint::<BITS, 1>;
Expand Down Expand Up @@ -821,7 +825,7 @@ mod tests {
// Expects resulting limbs: [0x0080_0000_0000_000, 0] with no fractional part.
assert_eq!(
Uint::<65, 2>::from_limbs([0x0010_0000_0000_0000, 0]).overflowing_shr(1),
(Uint::<65, 2>::from_limbs([0x0080_0000_0000_000, 0]), false)
(Uint::<65, 2>::from_limbs([0x0008_0000_0000_0000, 0]), false)
);

// Test: Shift beyond single limb capacity with MAX value.
Expand Down
2 changes: 1 addition & 1 deletion src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,12 @@ mod tests {
#[test]
const fn const_from_to_bytes() {
const NL: [u64; 2] = N.limbs;
const KL: [u64; 2] = K.limbs;
assert!(matches!(Uint::<128, 2>::from_be_bytes(BE).limbs, NL));
assert!(matches!(Uint::<128, 2>::from_le_bytes(LE).limbs, NL));
assert!(matches!(N.to_be_bytes::<{ BE.len() }>(), BE));
assert!(matches!(N.to_le_bytes::<{ LE.len() }>(), LE));

const KL: [u64; 2] = K.limbs;
assert!(matches!(Uint::<72, 2>::from_be_bytes(KBE).limbs, KL));
assert!(matches!(Uint::<72, 2>::from_le_bytes(KLE).limbs, KL));
assert!(matches!(K.to_be_bytes::<{ KBE.len() }>(), KBE));
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
clippy::pedantic,
clippy::nursery,
clippy::missing_inline_in_public_items,
clippy::std_instead_of_alloc,
clippy::std_instead_of_core,
missing_docs,
unreachable_pub
)]
Expand Down Expand Up @@ -345,8 +347,8 @@ mod test {
assert_eq!(mask(0), 0);
assert_eq!(mask(1), 1);
assert_eq!(mask(5), 0x1f);
assert_eq!(mask(63), u64::max_value() >> 1);
assert_eq!(mask(64), u64::max_value());
assert_eq!(mask(63), u64::MAX >> 1);
assert_eq!(mask(64), u64::MAX);
}

#[test]
Expand Down
Loading

0 comments on commit caad8c5

Please sign in to comment.