Debian Codegraph @

src/buffer.rs

raw symbols SCIP
1 //! Array-backed buffer for BER bytes.
2
3 /// Array-backed buffer for storing BER computed at compile-time.
4 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)]
5 pub struct Bufferrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#<const SIZE: usize> {
6 /// Length in bytes
7 pub(craterust-analyzer cargo const-oid 0.10.2 crate/) lengthrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#length.: u8,
8
9 /// Array containing BER/DER-serialized bytes (no header)
10 pub(craterust-analyzer cargo const-oid 0.10.2 crate/) bytesrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#bytes.: [u8; SIZE],
11 }
12
13 impl<const SIZE: usize> Bufferrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#<SIZE> {
14 /// Borrow the inner byte slice.
15 pub const fn as_bytesrust-analyzer cargo const-oid 0.10.2 buffer/impl#[`Buffer<SIZE>`]as_bytes().(&self) -> &[u8] {
16 self.bytesrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#bytes..split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(self.lengthrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#length. as usize).0
17 }
18
19 /// Get the length of the BER message.
20 pub const fn lenrust-analyzer cargo const-oid 0.10.2 buffer/impl#[`Buffer<SIZE>`]len().(&self) -> usize {
21 self.lengthrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#length. as usize
22 }
23
24 /// Const comparison of two buffers.
25 pub const fn eqrust-analyzer cargo const-oid 0.10.2 buffer/impl#[`Buffer<SIZE>`]eq().(&self, rhs: &Selfrust-analyzer cargo const-oid 0.10.2 buffer/impl#[`Buffer<SIZE>`]) -> bool {
26 if self.lengthrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#length. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().rhs.lengthrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#length. {
27 return false;
28 }
29
30 let mut i = 0usize;
31
32 while i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.lenrust-analyzer cargo const-oid 0.10.2 buffer/impl#[`Buffer<SIZE>`]len().() {
33 if self.bytesrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#bytes.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().rhs.bytesrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#bytes.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). {
34 return false;
35 }
36
37 // Won't overflow due to `i < self.len()` check above
38 #[allow(clippy::arithmetic_side_effects)]
39 {
40 i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
41 }
42 }
43
44 true
45 }
46 }
47
48 impl<const SIZE: usize> AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]> for Bufferrust-analyzer cargo const-oid 0.10.2 buffer/Buffer#<SIZE> {
49 fn as_refrust-analyzer cargo const-oid 0.10.2 buffer/impl#[`Buffer<SIZE>`][`AsRef<[u8]>`]as_ref().(&self) -> &[u8] {
50 self.as_bytesrust-analyzer cargo const-oid 0.10.2 buffer/impl#[`Buffer<SIZE>`]as_bytes().()
51 }
52 }