Skip to main content

hpke_dispatch/
lib.rs

1#![forbid(unsafe_code)]
2#![deny(
3    clippy::dbg_macro,
4    missing_copy_implementations,
5    rustdoc::missing_crate_level_docs,
6    missing_debug_implementations,
7    nonstandard_style,
8    unused_qualifications
9)]
10#![warn(missing_docs, clippy::cargo)]
11#![allow(
12    clippy::missing_errors_doc,
13    clippy::use_self,
14    clippy::multiple_crate_versions
15)]
16#![doc = include_str!("../README.md")]
17#![cfg(all(
18    any(feature = "aes", feature = "chacha",),
19    any(feature = "hkdfsha2", feature = "shake"),
20    any(feature = "nistp", feature = "x25519", feature = "mlkem",),
21))]
22
23use hpke::Deserializable;
24pub use hpke::HpkeError;
25
26#[macro_use]
27mod macros;
28
29mod base_mode_open;
30pub use base_mode_open::base_mode_open;
31
32mod base_mode_seal;
33pub use base_mode_seal::base_mode_seal;
34
35mod config;
36pub use config::Config;
37
38mod keypair;
39pub use keypair::{gen_keypair, Keypair};
40
41mod ciphertext;
42pub use ciphertext::EncappedKeyAndCiphertext;
43
44mod aead;
45pub use aead::{Aead, AEAD_ALL};
46
47mod kdf;
48pub use kdf::{Kdf, KDF_ALL};
49
50mod kem;
51pub use kem::{Kem, KEM_ALL};
52
53/// A simple error type for failed id lookups
54#[derive(Copy, Clone, Debug)]
55#[cfg_attr(
56    feature = "serde",
57    derive(serde_crate::Serialize, serde_crate::Deserialize)
58)]
59#[cfg_attr(feature = "serde", serde(crate = "serde_crate"))]
60pub struct IdLookupError(&'static str);
61impl std::fmt::Display for IdLookupError {
62    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63        f.write_fmt(format_args!("id lookup error {}", self.0))
64    }
65}
66impl std::error::Error for IdLookupError {}
67
68pub(crate) fn from_bytes<T: Deserializable>(encoded: &[u8]) -> Result<T, HpkeError> {
69    T::from_bytes(encoded)
70}