1#[derive(Debug)]
3#[non_exhaustive]
4pub enum SodokenErrKind {
5 AllocationFailed,
7
8 BadHashSize,
10
11 BadSaltSize,
13
14 BadKeySize,
16
17 BadPublicKeySize,
19
20 BadSecretKeySize,
22
23 BadSignatureSize,
25
26 BadSeedSize,
28
29 BadCipherSize,
31
32 BadNonceSize,
34
35 BadMessageSize,
37
38 BadPassphraseSize,
40
41 BadOpsLimit,
43
44 BadMemLimit,
46
47 WriteOverflow,
49
50 InternalSodium,
52
53 SpawnBlocking,
55
56 Other,
58}
59
60impl From<SodokenErrKind> for &'static str {
61 fn from(k: SodokenErrKind) -> Self {
62 use SodokenErrKind::*;
63 match k {
64 AllocationFailed => "AllocationFailed",
65 BadHashSize => "BadHashSize",
66 BadSaltSize => "BadSaltSize",
67 BadKeySize => "BadKeySize",
68 BadPublicKeySize => "BadPublicKeySize",
69 BadSecretKeySize => "BadSecretKeySize",
70 BadSignatureSize => "BadSignatureSize",
71 BadSeedSize => "BadSeedSize",
72 BadCipherSize => "BadCipherSize",
73 BadNonceSize => "BadNonceSize",
74 BadMessageSize => "BadMessageSize",
75 BadPassphraseSize => "BadPassphraseSize",
76 BadOpsLimit => "BadOpsLimit",
77 BadMemLimit => "BadMemLimit",
78 WriteOverflow => "WriteOverflow",
79 InternalSodium => "InternalSodium",
80 SpawnBlocking => "SpawnBlocking",
81 _ => "Other",
82 }
83 }
84}
85
86impl From<&str> for SodokenErrKind {
87 fn from(e: &str) -> Self {
88 use SodokenErrKind::*;
89 match e {
90 "AllocationFailed" => AllocationFailed,
91 "BadHashSize" => BadHashSize,
92 "BadSaltSize" => BadSaltSize,
93 "BadKeySize" => BadKeySize,
94 "BadPublicKeySize" => BadPublicKeySize,
95 "BadSecretKeySize" => BadSecretKeySize,
96 "BadSignatureSize" => BadSignatureSize,
97 "BadSeedSize" => BadSeedSize,
98 "BadCipherSize" => BadCipherSize,
99 "BadNonceSize" => BadNonceSize,
100 "BadMessageSize" => BadMessageSize,
101 "BadPassphraseSize" => BadPassphraseSize,
102 "BadOpsLimit" => BadOpsLimit,
103 "BadMemLimit" => BadMemLimit,
104 "WriteOverflow" => WriteOverflow,
105 "InternalSodium" => InternalSodium,
106 "SpawnBlocking" => SpawnBlocking,
107 _ => Other,
108 }
109 }
110}
111
112impl std::str::FromStr for SodokenErrKind {
113 type Err = one_err::OneErr;
114
115 fn from_str(s: &str) -> Result<Self, Self::Err> {
116 Ok(s.into())
117 }
118}
119
120impl From<&one_err::OneErr> for SodokenErrKind {
121 fn from(e: &one_err::OneErr) -> Self {
122 e.str_kind().into()
123 }
124}
125
126impl From<SodokenErrKind> for one_err::OneErr {
127 fn from(k: SodokenErrKind) -> Self {
128 one_err::OneErr::new(<&'static str>::from(k))
129 }
130}
131
132pub type SodokenResult<T> = Result<T, one_err::OneErr>;