Skip to main content

bergshamra_crypto/
lib.rs

1#![forbid(unsafe_code)]
2
3//! Cryptographic algorithm implementations for Bergshamra XML Security library.
4//!
5//! Provides traits and implementations for all crypto operations needed by
6//! XML-DSig and XML-Enc: digests, signatures, block ciphers, key wrapping,
7//! and key transport.
8
9pub mod cipher;
10pub mod digest;
11pub mod kdf;
12pub mod keyagreement;
13pub mod keytransport;
14pub mod keywrap;
15pub mod registry;
16pub mod sign;
17
18pub use digest::DigestAlgorithm;
19pub use registry::AlgorithmRegistry;
20
21/// Convert a `kryptering::Error` to a `bergshamra_core::Error`.
22pub(crate) fn map_kryptering_err(e: kryptering::Error) -> bergshamra_core::Error {
23    match e {
24        kryptering::Error::Crypto(s) => bergshamra_core::Error::Crypto(s),
25        kryptering::Error::UnsupportedAlgorithm(s) => {
26            bergshamra_core::Error::UnsupportedAlgorithm(s)
27        }
28        kryptering::Error::Key(s) => bergshamra_core::Error::Key(s),
29        kryptering::Error::Io(e) => bergshamra_core::Error::Io(e),
30        // Handle additional error variants (e.g., Pkcs11) when the kryptering
31        // crate is compiled with optional features.
32        #[allow(unreachable_patterns)]
33        other => bergshamra_core::Error::Crypto(other.to_string()),
34    }
35}