Debian Codegraph @

third_party/rust/ohttp/src/rh/mod.rs

raw
1 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4 // option. This file may not be copied, modified, or distributed
5 // except according to those terms.
6
7 pub mod aead;
8 pub mod hkdf;
9 pub mod hpke;
10
11 use crate::err::Res;
12
13 pub struct SymKey(Vec<u8>);
14
15 impl SymKey {
16 #[allow(clippy::unnecessary_wraps)]
17 pub fn key_data(&self) -> Res<&[u8]> {
18 Ok(&self.0)
19 }
20 }
21
22 impl From<Vec<u8>> for SymKey {
23 fn from(v: Vec<u8>) -> Self {
24 SymKey(v)
25 }
26 }
27 impl From<&[u8]> for SymKey {
28 fn from(v: &[u8]) -> Self {
29 SymKey(v.to_owned())
30 }
31 }
32
33 impl AsRef<[u8]> for SymKey {
34 fn as_ref(&self) -> &[u8] {
35 &self.0
36 }
37 }
38
39 impl std::fmt::Debug for SymKey {
40 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
41 if let Ok(b) = self.key_data() {
42 write!(f, "SymKey {}", hex::encode(b))
43 } else {
44 write!(f, "Opaque SymKey")
45 }
46 }
47 }