Coverage Report

Created: 2025-02-25 06:39

/rust/registry/src/index.crates.io-6f17d22bba15001f/ring-0.17.8/src/debug.rs
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2018 Trent Clarke.
2
//
3
// Permission to use, copy, modify, and/or distribute this software for any
4
// purpose with or without fee is hereby granted, provided that the above
5
// copyright notice and this permission notice appear in all copies.
6
//
7
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
8
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
10
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15
// Generates an implementation of the Debug trait for a type that defers to the
16
// Debug implementation for a given field.
17
macro_rules! derive_debug_via_id {
18
    ($typename:ident) => {
19
        impl ::core::fmt::Debug for $typename {
20
0
            fn fmt(&self, f: &mut ::core::fmt::Formatter) -> Result<(), ::core::fmt::Error> {
21
0
                ::core::fmt::Debug::fmt(&self.id, f)
22
0
            }
Unexecuted instantiation: <ring::ec::Curve as core::fmt::Debug>::fmt
Unexecuted instantiation: <ring::aead::quic::Algorithm as core::fmt::Debug>::fmt
Unexecuted instantiation: <ring::ec::suite_b::ecdsa::verification::EcdsaVerificationAlgorithm as core::fmt::Debug>::fmt
Unexecuted instantiation: <ring::aead::Algorithm as core::fmt::Debug>::fmt
Unexecuted instantiation: <ring::ec::suite_b::ecdsa::signing::EcdsaSigningAlgorithm as core::fmt::Debug>::fmt
Unexecuted instantiation: <ring::digest::Algorithm as core::fmt::Debug>::fmt
23
        }
24
    };
25
}
26
27
macro_rules! derive_debug_via_field {
28
    ($type:ty, $field:ident) => {
29
        derive_debug_via_field!($type, stringify!($type), $field);
30
    };
31
32
    ($type:ty, $typename:expr, $field:ident) => {
33
        impl ::core::fmt::Debug for $type {
34
0
            fn fmt(&self, f: &mut ::core::fmt::Formatter) -> Result<(), ::core::fmt::Error> {
35
0
                f.debug_struct($typename)
36
0
                    .field(stringify!($field), &self.$field)
37
0
                    .finish()
38
0
            }
Unexecuted instantiation: <ring::agreement::Algorithm as core::fmt::Debug>::fmt
Unexecuted instantiation: <ring::agreement::EphemeralPrivateKey as core::fmt::Debug>::fmt
Unexecuted instantiation: <ring::ec::curve25519::ed25519::signing::Ed25519KeyPair as core::fmt::Debug>::fmt
Unexecuted instantiation: <ring::ec::suite_b::ecdsa::signing::EcdsaKeyPair as core::fmt::Debug>::fmt
Unexecuted instantiation: <ring::rsa::keypair::KeyPair as core::fmt::Debug>::fmt
39
        }
40
    };
41
}
42
43
// Generates an implementation of the Debug trait for a type that outputs the
44
// hex encoding of the byte slice representation of the value.
45
macro_rules! derive_debug_self_as_ref_hex_bytes {
46
    ($typename:ident) => {
47
        impl ::core::fmt::Debug for $typename {
48
0
            fn fmt(&self, f: &mut ::core::fmt::Formatter) -> Result<(), ::core::fmt::Error> {
49
0
                crate::debug::write_hex_tuple(f, stringify!($typename), self)
50
0
            }
Unexecuted instantiation: <ring::ec::curve25519::ed25519::signing::PublicKey as core::fmt::Debug>::fmt
Unexecuted instantiation: <ring::ec::suite_b::ecdsa::signing::PublicKey as core::fmt::Debug>::fmt
Unexecuted instantiation: <ring::rsa::public_key::PublicKey as core::fmt::Debug>::fmt
51
        }
52
    };
53
}
54
55
0
pub(crate) fn write_hex_tuple(
56
0
    fmt: &mut core::fmt::Formatter,
57
0
    type_name: &str,
58
0
    value: &dyn AsRef<[u8]>,
59
0
) -> Result<(), ::core::fmt::Error> {
60
0
    fmt.debug_tuple(type_name)
61
0
        .field(&HexStr(value.as_ref()))
62
0
        .finish()
63
0
}
64
65
pub struct HexStr<'a>(pub &'a [u8]);
66
67
impl core::fmt::Debug for HexStr<'_> {
68
0
    fn fmt(&self, fmt: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
69
0
        fmt.write_str("\"")?;
70
0
        write_hex_bytes(fmt, self.0)?;
71
0
        fmt.write_str("\"")?;
72
0
        Ok(())
73
0
    }
74
}
75
76
0
pub(crate) fn write_hex_bytes(
77
0
    fmt: &mut core::fmt::Formatter,
78
0
    bytes: &[u8],
79
0
) -> Result<(), ::core::fmt::Error> {
80
0
    for byte in bytes {
81
0
        write!(fmt, "{:02x}", byte)?;
82
    }
83
0
    Ok(())
84
0
}