sosecrets_rs/runtime/error.rs
1use crate::traits::ChooseMinimallyRepresentableUInt;
2
3/// An error representing that the secret has been exposed more times than allowed.
4#[derive(Debug)]
5#[non_exhaustive]
6pub enum ExposeSecretError<MEC: ChooseMinimallyRepresentableUInt> {
7 ExposeMoreThanMaximallyAllow(ExposeMoreThanMaximallyAllowError<MEC>),
8}
9
10/// An error representing that the secret has been exposed more times than allowed.
11#[derive(Debug)]
12pub struct ExposeMoreThanMaximallyAllowError<MEC: ChooseMinimallyRepresentableUInt> {
13 pub mec: <MEC as ChooseMinimallyRepresentableUInt>::Output,
14 pub ec: <MEC as ChooseMinimallyRepresentableUInt>::Output,
15}
16
17impl<MEC: ChooseMinimallyRepresentableUInt> core::fmt::Display
18 for ExposeMoreThanMaximallyAllowError<MEC>
19{
20 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21 write!(f, "`Secret` is exposed more than what it is maximally allowed to; it is exposed for {} times and it is only allowed to be exposed for {} times", self.ec, self.mec)
22 }
23}
24
25impl<MEC: ChooseMinimallyRepresentableUInt> core::fmt::Display for ExposeSecretError<MEC> {
26 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
27 match self {
28 Self::ExposeMoreThanMaximallyAllow(err) => err.fmt(f),
29 }
30 }
31}