Coverage Report

Created: 2026-09-28 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/crypto-bigint-0.5.5/src/limb/encoding.rs
Line
Count
Source
1
//! Limb encoding
2
3
use super::{Limb, Word};
4
use crate::Encoding;
5
6
impl Encoding for Limb {
7
    #[cfg(target_pointer_width = "32")]
8
    type Repr = [u8; 4];
9
    #[cfg(target_pointer_width = "64")]
10
    type Repr = [u8; 8];
11
12
    #[inline]
13
0
    fn from_be_bytes(bytes: Self::Repr) -> Self {
14
0
        Limb(Word::from_be_bytes(bytes))
15
0
    }
16
17
    #[inline]
18
0
    fn from_le_bytes(bytes: Self::Repr) -> Self {
19
0
        Limb(Word::from_le_bytes(bytes))
20
0
    }
21
22
    #[inline]
23
172k
    fn to_be_bytes(&self) -> Self::Repr {
24
172k
        self.0.to_be_bytes()
25
172k
    }
<crypto_bigint::limb::Limb as crypto_bigint::traits::Encoding>::to_be_bytes
Line
Count
Source
23
172k
    fn to_be_bytes(&self) -> Self::Repr {
24
172k
        self.0.to_be_bytes()
25
172k
    }
Unexecuted instantiation: <crypto_bigint::limb::Limb as crypto_bigint::traits::Encoding>::to_be_bytes
26
27
    #[inline]
28
34.5k
    fn to_le_bytes(&self) -> Self::Repr {
29
34.5k
        self.0.to_le_bytes()
30
34.5k
    }
<crypto_bigint::limb::Limb as crypto_bigint::traits::Encoding>::to_le_bytes
Line
Count
Source
28
34.5k
    fn to_le_bytes(&self) -> Self::Repr {
29
34.5k
        self.0.to_le_bytes()
30
34.5k
    }
Unexecuted instantiation: <crypto_bigint::limb::Limb as crypto_bigint::traits::Encoding>::to_le_bytes
31
}
32
33
#[cfg(test)]
34
mod test {
35
    use super::*;
36
    use proptest::prelude::*;
37
38
    prop_compose! {
39
        fn limb()(inner in any::<Word>()) -> Limb {
40
            Limb(inner)
41
        }
42
    }
43
44
    proptest! {
45
        #[test]
46
        fn roundtrip(a in limb()) {
47
            assert_eq!(a, Limb::from_be_bytes(a.to_be_bytes()));
48
            assert_eq!(a, Limb::from_le_bytes(a.to_le_bytes()));
49
        }
50
    }
51
52
    proptest! {
53
        #[test]
54
        fn reverse(a in limb()) {
55
            let mut bytes = a.to_be_bytes();
56
            bytes.reverse();
57
            assert_eq!(a, Limb::from_le_bytes(bytes));
58
59
            let mut bytes = a.to_le_bytes();
60
            bytes.reverse();
61
            assert_eq!(a, Limb::from_be_bytes(bytes));
62
        }
63
    }
64
}