Coverage Report

Created: 2026-08-14 08:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/aws-lc-rs-1.16.3/src/io/positive.rs
Line
Count
Source
1
// Copyright 2018 Brian Smith.
2
// SPDX-License-Identifier: ISC
3
// Modifications copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
// SPDX-License-Identifier: Apache-2.0 OR ISC
5
6
//! Serialization and deserialization.
7
8
/// A serialized positive integer.
9
#[derive(Copy, Clone)]
10
pub struct Positive<'a>(untrusted::Input<'a>);
11
12
impl<'a> Positive<'a> {
13
0
    pub(crate) fn new_non_empty_without_leading_zeros(input: untrusted::Input<'a>) -> Self {
14
0
        debug_assert!(!input.is_empty());
15
0
        debug_assert!(input.len() == 1 || input.as_slice_less_safe()[0] != 0);
16
0
        Self(input)
17
0
    }
18
19
    /// Returns the value, ordered from significant byte to least significant
20
    /// byte, without any leading zeros. The result is guaranteed to be
21
    /// non-empty.
22
    #[inline]
23
    #[must_use]
24
0
    pub fn big_endian_without_leading_zero(&self) -> &'a [u8] {
25
0
        self.big_endian_without_leading_zero_as_input()
26
0
            .as_slice_less_safe()
27
0
    }
28
29
    #[inline]
30
0
    pub(crate) fn big_endian_without_leading_zero_as_input(&self) -> untrusted::Input<'a> {
31
0
        self.0
32
0
    }
33
}
34
35
impl Positive<'_> {
36
    /// Returns the first byte.
37
    ///
38
    /// Will not panic because the value is guaranteed to have at least one
39
    /// byte.
40
    #[must_use]
41
0
    pub fn first_byte(&self) -> u8 {
42
        // This won't panic because
43
0
        self.0.as_slice_less_safe()[0]
44
0
    }
45
}