1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#![no_std]
#[cfg(feature = "std")]
#[allow(unused_imports)]
#[macro_use]
extern crate std;
#[cfg(not(feature = "std"))]
#[allow(unused_imports)]
#[macro_use]
extern crate alloc;
pub use digest::generic_array;
#[cfg(all(test, feature = "std", feature = "x25519-dalek", feature = "p256"))]
mod kat_tests;
#[cfg(all(test, feature = "std", feature = "x25519-dalek", feature = "p256"))]
#[macro_use]
extern crate serde_derive;
#[cfg(test)]
mod test_util;
pub mod aead;
pub mod kdf;
pub mod kem;
pub mod kex;
pub mod op_mode;
mod prelude;
pub mod setup;
pub mod single_shot;
mod util;
#[doc(inline)]
pub use crate::aead::{AeadCtxR, AeadCtxS};
#[doc(inline)]
pub use kem::{EncappedKey, Kem};
#[doc(inline)]
pub use kex::{KeyExchange, Marshallable, Unmarshallable};
#[doc(inline)]
pub use op_mode::{OpModeR, OpModeS, PskBundle};
#[doc(inline)]
pub use setup::{setup_receiver, setup_sender};
#[doc(inline)]
pub use single_shot::{single_shot_open, single_shot_seal};
#[derive(Clone, Copy, Debug)]
pub enum HpkeError {
SeqOverflow,
InvalidTag,
Encryption,
InvalidKeyExchange,
InvalidKdfLength,
InvalidEncoding,
}
impl core::fmt::Display for HpkeError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let kind = match self {
HpkeError::SeqOverflow => "Sequence overflow",
HpkeError::InvalidTag => "Invalid tag",
HpkeError::Encryption => "Encryption error",
HpkeError::InvalidKeyExchange => "Key exchange validation error",
HpkeError::InvalidKdfLength => "Too many bytes requested from KDF",
HpkeError::InvalidEncoding => "Cannot marshal byte sequence: invalid encoding",
};
f.write_str(kind)
}
}
#[cfg(feature = "std")]
impl std::error::Error for HpkeError {}