Skip to main content

s2n_quic_dc/stream/
processing.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::crypto::open;
5
6#[derive(Clone, Copy, Debug, thiserror::Error)]
7pub enum Error {
8    #[error("packet could not be decrypted: {0}")]
9    Crypto(open::Error),
10    #[error("packet has already been processed")]
11    Duplicate,
12    #[error("the crypto key has been replayed and is invalid")]
13    KeyReplayPrevented,
14    #[error("the crypto key has been potentially replayed (gap: {gap:?}) and is invalid")]
15    KeyReplayPotentiallyPrevented { gap: Option<u64> },
16}
17
18impl From<open::Error> for Error {
19    fn from(value: open::Error) -> Self {
20        match value {
21            open::Error::ReplayDefinitelyDetected => Self::KeyReplayPrevented,
22            open::Error::ReplayPotentiallyDetected { gap } => {
23                Self::KeyReplayPotentiallyPrevented { gap }
24            }
25            error => Self::Crypto(error),
26        }
27    }
28}