Skip to content

Add from_*slice_truncated methods to Encoding trait#1301

Merged
tarcieri merged 1 commit into
masterfrom
add-from-slice-truncated-to-encoding-trait
Jun 21, 2026
Merged

Add from_*slice_truncated methods to Encoding trait#1301
tarcieri merged 1 commit into
masterfrom
add-from-slice-truncated-to-encoding-trait

Conversation

@tarcieri

Copy link
Copy Markdown
Member

The primary goal here is to make it possible to construct both Uint and BoxedUint from slice-based inputs in a generic context, particularly for implementing the bits2int function in the rfc6979 crate, but also useful for e.g. elliptic-curve when we have field elements backed by big integers that are larger than the field modulus, as is the case for NIST P-521.

It was possible to provide a basic impl for these functions in order to make the change non-breaking (since Encoding isn't sealed): it ensures the provided bits_precision matches the Repr size, and still implements big/little endian truncation, but doesn't handle short inputs and just thunks through from_be_bytes/from_le_bytes. This is particularly helpful as currently no impl for Int is provided, so it's using the default.

The primary goal here is to make it possible to construct both `Uint`
and `BoxedUint` from slice-based inputs in a generic context,
particularly for implementing the `bits2int` function in the `rfc6979`
crate, but also useful for e.g. `elliptic-curve` when we have field
elements backed by big integers that are larger than the field modulus,
as is the case for NIST P-521.

It was possible to provide a basic impl for these functions in order to
make the change non-breaking (since `Encoding` isn't sealed): it ensures
the provided `bits_precision` matches the `Repr` size, and still
implements big/little endian truncation, but doesn't handle short inputs
and just thunks through `from_be_bytes`/`from_le_bytes`. This is
particularly helpful as currently no impl for `Int` is provided, so it's
using the default.
@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 35.08772% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.14%. Comparing base (da7ca41) to head (30a08d4).

Files with missing lines Patch % Lines
src/encoding.rs 44.44% 15 Missing ⚠️
src/uint/boxed/encoding.rs 28.57% 10 Missing ⚠️
src/limb/encoding.rs 0.00% 6 Missing ⚠️
src/uint/encoding.rs 40.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1301      +/-   ##
==========================================
- Coverage   91.27%   91.14%   -0.14%     
==========================================
  Files         190      190              
  Lines       22682    22721      +39     
==========================================
+ Hits        20703    20709       +6     
- Misses       1979     2012      +33     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tarcieri tarcieri merged commit 0ac9bf4 into master Jun 21, 2026
32 checks passed
@tarcieri tarcieri deleted the add-from-slice-truncated-to-encoding-trait branch June 21, 2026 19:14
@tarcieri tarcieri mentioned this pull request Jun 22, 2026
tarcieri added a commit that referenced this pull request Jun 22, 2026
## Added
- `BoxedUint::{from_be_slice_truncated, from_le_slice_truncated}` (#1266)
- `Encoding::{from_bytes, to_bytes}` (#1297)
- `Uint::{from_be_slice_truncated, from_le_slice_truncated}` (#1299)
- `Limb::{from_*_bytes, from_*_slice_truncated, to_*_bytes}` as
  `const fn`s (#1300)
- `Encoding::{from_be_slice_truncated, from_le_slice_truncated}` trait
  methods (#1301)
- `ArrayEncoding::{from_byte_array, to_byte_array}` (#1302)

## Fixed
- Preserve `NonZero` and `Odd` invariants in `Zeroize` impls (#1287)
- `bitlen` performance (#1298)
- `floor_sqrt` regression (#1304)
- Truncated Karatsuba carry (#1305)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant