Coverage Report

Created: 2025-07-23 07:04

/rust/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-rs-1.13.0/src/encoding.rs
Line
Count
Source (jump to first uncovered line)
1
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
// SPDX-License-Identifier: Apache-2.0 OR ISC
3
4
//! Serialization formats
5
6
use crate::buffer::Buffer;
7
8
macro_rules! generated_encodings {
9
    ($(($name:ident, $name_type:ident)),*) => {
10
        use core::fmt::{Debug, Error, Formatter};
11
        use core::ops::Deref;
12
        mod buffer_type {
13
            $(
14
                pub struct $name_type {
15
                    _priv: (),
16
                }
17
            )*
18
        }
19
        $(
20
            /// Serialized bytes
21
            pub struct $name<'a>(Buffer<'a, buffer_type::$name_type>);
22
23
            impl<'a> Deref for $name<'a> {
24
                type Target = Buffer<'a, buffer_type::$name_type>;
25
26
0
                fn deref(&self) -> &Self::Target {
27
0
                    &self.0
28
0
                }
Unexecuted instantiation: <aws_lc_rs::kem::EncapsulationKeyBytes as core::ops::deref::Deref>::deref
Unexecuted instantiation: <aws_lc_rs::encoding::Curve25519SeedBin as core::ops::deref::Deref>::deref
Unexecuted instantiation: <aws_lc_rs::encoding::EcPrivateKeyBin as core::ops::deref::Deref>::deref
Unexecuted instantiation: <aws_lc_rs::encoding::EcPrivateKeyRfc5915Der as core::ops::deref::Deref>::deref
Unexecuted instantiation: <aws_lc_rs::encoding::EcPublicKeyCompressedBin as core::ops::deref::Deref>::deref
Unexecuted instantiation: <aws_lc_rs::encoding::EcPublicKeyUncompressedBin as core::ops::deref::Deref>::deref
Unexecuted instantiation: <aws_lc_rs::encoding::Pkcs8V1Der as core::ops::deref::Deref>::deref
Unexecuted instantiation: <aws_lc_rs::encoding::Pkcs8V2Der as core::ops::deref::Deref>::deref
Unexecuted instantiation: <aws_lc_rs::encoding::PqdsaPrivateKeyRaw as core::ops::deref::Deref>::deref
Unexecuted instantiation: <aws_lc_rs::encoding::PqdsaSeedRaw as core::ops::deref::Deref>::deref
Unexecuted instantiation: <aws_lc_rs::encoding::PublicKeyX509Der as core::ops::deref::Deref>::deref
29
            }
30
31
            impl $name<'static> {
32
                #[allow(dead_code)]
33
0
                pub(crate) fn new(owned: Vec<u8>) -> Self {
34
0
                    Self(Buffer::new(owned))
35
0
                }
Unexecuted instantiation: <aws_lc_rs::kem::EncapsulationKeyBytes>::new
Unexecuted instantiation: <aws_lc_rs::encoding::Curve25519SeedBin>::new
Unexecuted instantiation: <aws_lc_rs::encoding::EcPrivateKeyBin>::new
Unexecuted instantiation: <aws_lc_rs::encoding::EcPrivateKeyRfc5915Der>::new
Unexecuted instantiation: <aws_lc_rs::encoding::EcPublicKeyCompressedBin>::new
Unexecuted instantiation: <aws_lc_rs::encoding::EcPublicKeyUncompressedBin>::new
Unexecuted instantiation: <aws_lc_rs::encoding::Pkcs8V1Der>::new
Unexecuted instantiation: <aws_lc_rs::encoding::Pkcs8V2Der>::new
Unexecuted instantiation: <aws_lc_rs::encoding::PublicKeyX509Der>::new
Unexecuted instantiation: <aws_lc_rs::encoding::PqdsaPrivateKeyRaw>::new
Unexecuted instantiation: <aws_lc_rs::encoding::PqdsaSeedRaw>::new
36
                #[allow(dead_code)]
37
0
                pub(crate) fn take_from_slice(owned: &mut [u8]) -> Self {
38
0
                    Self(Buffer::take_from_slice(owned))
39
0
                }
Unexecuted instantiation: <aws_lc_rs::encoding::EcPrivateKeyRfc5915Der>::take_from_slice
Unexecuted instantiation: <aws_lc_rs::encoding::Curve25519SeedBin>::take_from_slice
Unexecuted instantiation: <aws_lc_rs::encoding::EcPrivateKeyBin>::take_from_slice
Unexecuted instantiation: <aws_lc_rs::encoding::EcPublicKeyCompressedBin>::take_from_slice
Unexecuted instantiation: <aws_lc_rs::encoding::EcPublicKeyUncompressedBin>::take_from_slice
Unexecuted instantiation: <aws_lc_rs::encoding::Pkcs8V1Der>::take_from_slice
Unexecuted instantiation: <aws_lc_rs::encoding::Pkcs8V2Der>::take_from_slice
Unexecuted instantiation: <aws_lc_rs::encoding::PqdsaPrivateKeyRaw>::take_from_slice
Unexecuted instantiation: <aws_lc_rs::encoding::PqdsaSeedRaw>::take_from_slice
Unexecuted instantiation: <aws_lc_rs::encoding::PublicKeyX509Der>::take_from_slice
Unexecuted instantiation: <aws_lc_rs::kem::EncapsulationKeyBytes>::take_from_slice
40
            }
41
42
            impl Debug for $name<'_> {
43
0
                fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
44
0
                    f.debug_struct(stringify!($name)).finish()
45
0
                }
Unexecuted instantiation: <aws_lc_rs::kem::EncapsulationKeyBytes as core::fmt::Debug>::fmt
Unexecuted instantiation: <aws_lc_rs::encoding::Curve25519SeedBin as core::fmt::Debug>::fmt
Unexecuted instantiation: <aws_lc_rs::encoding::EcPrivateKeyBin as core::fmt::Debug>::fmt
Unexecuted instantiation: <aws_lc_rs::encoding::EcPrivateKeyRfc5915Der as core::fmt::Debug>::fmt
Unexecuted instantiation: <aws_lc_rs::encoding::EcPublicKeyCompressedBin as core::fmt::Debug>::fmt
Unexecuted instantiation: <aws_lc_rs::encoding::EcPublicKeyUncompressedBin as core::fmt::Debug>::fmt
Unexecuted instantiation: <aws_lc_rs::encoding::Pkcs8V1Der as core::fmt::Debug>::fmt
Unexecuted instantiation: <aws_lc_rs::encoding::Pkcs8V2Der as core::fmt::Debug>::fmt
Unexecuted instantiation: <aws_lc_rs::encoding::PqdsaPrivateKeyRaw as core::fmt::Debug>::fmt
Unexecuted instantiation: <aws_lc_rs::encoding::PqdsaSeedRaw as core::fmt::Debug>::fmt
Unexecuted instantiation: <aws_lc_rs::encoding::PublicKeyX509Der as core::fmt::Debug>::fmt
46
            }
47
48
            impl<'a> From<Buffer<'a, buffer_type::$name_type>> for $name<'a> {
49
0
                fn from(value: Buffer<'a, buffer_type::$name_type>) -> Self {
50
0
                    Self(value)
51
0
                }
Unexecuted instantiation: <aws_lc_rs::kem::EncapsulationKeyBytes as core::convert::From<aws_lc_rs::buffer::Buffer<aws_lc_rs::kem::buffer_type::EncapsulationKeyBytesType>>>::from
Unexecuted instantiation: <aws_lc_rs::encoding::Curve25519SeedBin as core::convert::From<aws_lc_rs::buffer::Buffer<aws_lc_rs::encoding::buffer_type::Curve25519SeedBinType>>>::from
Unexecuted instantiation: <aws_lc_rs::encoding::EcPrivateKeyBin as core::convert::From<aws_lc_rs::buffer::Buffer<aws_lc_rs::encoding::buffer_type::EcPrivateKeyBinType>>>::from
Unexecuted instantiation: <aws_lc_rs::encoding::EcPrivateKeyRfc5915Der as core::convert::From<aws_lc_rs::buffer::Buffer<aws_lc_rs::encoding::buffer_type::EcPrivateKeyRfc5915DerType>>>::from
Unexecuted instantiation: <aws_lc_rs::encoding::EcPublicKeyCompressedBin as core::convert::From<aws_lc_rs::buffer::Buffer<aws_lc_rs::encoding::buffer_type::EcPublicKeyCompressedBinType>>>::from
Unexecuted instantiation: <aws_lc_rs::encoding::EcPublicKeyUncompressedBin as core::convert::From<aws_lc_rs::buffer::Buffer<aws_lc_rs::encoding::buffer_type::EcPublicKeyUncompressedBinType>>>::from
Unexecuted instantiation: <aws_lc_rs::encoding::Pkcs8V1Der as core::convert::From<aws_lc_rs::buffer::Buffer<aws_lc_rs::encoding::buffer_type::Pkcs8V1DerType>>>::from
Unexecuted instantiation: <aws_lc_rs::encoding::Pkcs8V2Der as core::convert::From<aws_lc_rs::buffer::Buffer<aws_lc_rs::encoding::buffer_type::Pkcs8V2DerType>>>::from
Unexecuted instantiation: <aws_lc_rs::encoding::PqdsaPrivateKeyRaw as core::convert::From<aws_lc_rs::buffer::Buffer<aws_lc_rs::encoding::buffer_type::PqdsaPrivateKeyRawType>>>::from
Unexecuted instantiation: <aws_lc_rs::encoding::PqdsaSeedRaw as core::convert::From<aws_lc_rs::buffer::Buffer<aws_lc_rs::encoding::buffer_type::PqdsaSeedRawType>>>::from
Unexecuted instantiation: <aws_lc_rs::encoding::PublicKeyX509Der as core::convert::From<aws_lc_rs::buffer::Buffer<aws_lc_rs::encoding::buffer_type::PublicKeyX509DerType>>>::from
52
            }
53
        )*
54
    }
55
}
56
pub(crate) use generated_encodings;
57
generated_encodings!(
58
    (Curve25519SeedBin, Curve25519SeedBinType),
59
    (EcPrivateKeyBin, EcPrivateKeyBinType),
60
    (EcPrivateKeyRfc5915Der, EcPrivateKeyRfc5915DerType),
61
    (EcPublicKeyCompressedBin, EcPublicKeyCompressedBinType),
62
    (EcPublicKeyUncompressedBin, EcPublicKeyUncompressedBinType),
63
    (Pkcs8V1Der, Pkcs8V1DerType),
64
    (Pkcs8V2Der, Pkcs8V2DerType),
65
    (PqdsaPrivateKeyRaw, PqdsaPrivateKeyRawType),
66
    (PqdsaSeedRaw, PqdsaSeedRawType),
67
    (PublicKeyX509Der, PublicKeyX509DerType)
68
);
69
70
/// Trait for types that can be serialized into a DER format.
71
pub trait AsDer<T> {
72
    /// Serializes into a DER format.
73
    ///
74
    /// # Errors
75
    /// Returns Unspecified if serialization fails.
76
    fn as_der(&self) -> Result<T, crate::error::Unspecified>;
77
}
78
79
/// Trait for values that can be serialized into a big-endian format
80
pub trait AsBigEndian<T> {
81
    /// Serializes into a big-endian format.
82
    ///
83
    /// # Errors
84
    /// Returns Unspecified if serialization fails.
85
    fn as_be_bytes(&self) -> Result<T, crate::error::Unspecified>;
86
}
87
88
/// Trait for values that can be serialized into a raw format
89
pub trait AsRawBytes<T> {
90
    /// Serializes into a raw format.
91
    ///
92
    /// # Errors
93
    /// Returns Unspecified if serialization fails.
94
    fn as_raw_bytes(&self) -> Result<T, crate::error::Unspecified>;
95
}