pub struct Mpint { /* private fields */ }alloc only.Expand description
Multiple precision integer, a.k.a. mpint.
This type supports the non-negative subset of RFC4251 § 5, matching OpenSSH. Values are limited to 16384-bits. Negative SSH encodings are rejected.
Self::from_bytes and Self::as_bytes use an unsigned big endian magnitude,
without a length prefix or sign padding. Leading zeros are stripped and zero
is represented by an empty slice.
Decode accepts redundant leading zeros like OpenSSH, but limits the input
to Self::MAX_SIZE bytes plus one leading zero byte before stripping zeros.
Encode always emits the canonical SSH encoding, including a leading zero
when the most significant bit is set and an empty string for zero.
With the ctutils feature, constant-time order and equality operations on equal-length
magnitudes are supported. Lengths are not treated as secret. Byte conversion, decoding, and
encoding are variable-time.
§Examples
| value (hex) | SSH encoding (hex) |
|---|---|
| 0 | 00 00 00 00 |
| 9a378f9b2e332a7 | 00 00 00 08 09 a3 78 f9 b2 e3 32 a7 |
| 80 | 00 00 00 02 00 80 |
Implementations§
Source§impl Mpint
impl Mpint
Sourcepub const MAX_SIZE: usize = MpintRef::MAX_SIZE
pub const MAX_SIZE: usize = MpintRef::MAX_SIZE
Maximum magnitude size in bytes, excluding SSH sign padding.
This 16384-bit limit is enforced by every constructor and decoder.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Mpint, Error>
pub fn from_bytes(bytes: &[u8]) -> Result<Mpint, Error>
Create an integer from its unsigned big endian magnitude.
Leading zeros are stripped. The most significant bit is part of the magnitude, not a sign bit. This method does not expect an SSH length prefix or sign padding.
§Errors
Returns Error::Length if the magnitude exceeds Self::MAX_SIZE.
Returns Error::Alloc if reserving capacity fails.
Trait Implementations§
Source§impl Encode for Mpint
impl Encode for Mpint
Source§fn encoded_len(&self) -> Result<usize, Error>
fn encoded_len(&self) -> Result<usize, Error>
Source§fn encoded_len_prefixed(&self) -> Result<usize, Error>
fn encoded_len_prefixed(&self) -> Result<usize, Error>
uint32 length prefix. Read moreimpl Eq for Mpint
ctutils only.Source§impl Ord for Mpint
Available on crate feature ctutils only.
impl Ord for Mpint
ctutils only.1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Mpint
Available on crate feature ctutils only.
impl PartialOrd for Mpint
ctutils only.Source§impl TryFrom<Mpint> for DsaPrivateKey
impl TryFrom<Mpint> for DsaPrivateKey
Auto Trait Implementations§
impl Forget for Mpint
impl Freeze for Mpint
impl Move for Mpint
impl RefUnwindSafe for Mpint
impl Send for Mpint
impl Sync for Mpint
impl Unpin for Mpint
impl UnsafeUnpin for Mpint
impl UnwindSafe for Mpintwhere
BoxRaw<[u8]>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)