s2n_quic_core/crypto/
packet_protection.rs1pub const QUIC_KEY_LABEL: [u8; 8] = *b"quic key";
8
9pub const QUIC_IV_LABEL: [u8; 7] = *b"quic iv";
13
14pub const QUIC_HP_LABEL: [u8; 7] = *b"quic hp";
17
18use core::fmt;
19use s2n_codec::DecoderError;
20
21#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
23#[cfg_attr(feature = "thiserror", derive(thiserror::Error))]
24pub struct Error {
25 pub reason: &'static str,
26}
27
28impl Error {
29 pub const DECODE_ERROR: Self = Self {
30 reason: "DECODE_ERROR",
31 };
32 pub const DECRYPT_ERROR: Self = Self {
33 reason: "DECRYPT_ERROR",
34 };
35 pub const INTERNAL_ERROR: Self = Self {
36 reason: "INTERNAL_ERROR",
37 };
38}
39
40impl fmt::Display for Error {
41 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42 if !self.reason.is_empty() {
43 self.reason.fmt(f)
44 } else {
45 write!(f, "packet_protection::Error")
46 }
47 }
48}
49
50impl fmt::Debug for Error {
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 let mut d = f.debug_struct("packet_protection::Error");
53
54 if !self.reason.is_empty() {
55 d.field("reason", &self.reason);
56 }
57
58 d.finish()
59 }
60}
61
62impl From<DecoderError> for Error {
63 fn from(decoder_error: DecoderError) -> Self {
64 Self {
65 reason: decoder_error.into(),
66 }
67 }
68}