Add from_*slice_truncated methods to Encoding trait#1301
Merged
Conversation
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
Merged
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The primary goal here is to make it possible to construct both
UintandBoxedUintfrom slice-based inputs in a generic context, particularly for implementing thebits2intfunction in therfc6979crate, but also useful for e.g.elliptic-curvewhen 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
Encodingisn't sealed): it ensures the providedbits_precisionmatches theReprsize, and still implements big/little endian truncation, but doesn't handle short inputs and just thunks throughfrom_be_bytes/from_le_bytes. This is particularly helpful as currently no impl forIntis provided, so it's using the default.