Skip to main content

dcap_qvl/
configs.rs

1//! Preset [`Config`] bundles built from the audited in-tree backends.
2//!
3//! Each bundle pairs the audited X.509 parser ([`X509CertBackend`]) and
4//! signature encoder ([`DerSigEncoder`]) with one of the available
5//! [`CryptoProvider`](crate::config::CryptoProvider) implementations.
6//! [`DefaultConfig`] is a feature-selected type alias picking the right
7//! preset based on which crypto feature is enabled.
8
9use crate::config::Config;
10use crate::signature::DerSigEncoder;
11use crate::x509::X509CertBackend;
12
13#[cfg(feature = "ring")]
14use crate::crypto::RingCrypto;
15#[cfg(feature = "rustcrypto")]
16use crate::crypto::RustCryptoCrypto;
17
18/// Audited config pairing the `der` / `x509-cert` parser with the `ring`
19/// crypto provider. Selected as [`DefaultConfig`] when the `ring` feature is
20/// enabled.
21#[cfg(feature = "ring")]
22pub struct RingConfig;
23
24#[cfg(feature = "ring")]
25impl Config for RingConfig {
26    type X509 = X509CertBackend;
27    type SigEncoder = DerSigEncoder;
28    type Crypto = RingCrypto;
29}
30
31/// Audited config pairing the `der` / `x509-cert` parser with the RustCrypto
32/// crypto provider.
33#[cfg(feature = "rustcrypto")]
34pub struct RustCryptoConfig;
35
36#[cfg(feature = "rustcrypto")]
37impl Config for RustCryptoConfig {
38    type X509 = X509CertBackend;
39    type SigEncoder = DerSigEncoder;
40    type Crypto = RustCryptoCrypto;
41}
42
43/// Audited default config: prefers [`RingConfig`] if the `ring` feature is on,
44/// otherwise [`RustCryptoConfig`].
45#[cfg(feature = "ring")]
46pub type DefaultConfig = RingConfig;
47
48#[cfg(all(not(feature = "ring"), feature = "rustcrypto"))]
49pub type DefaultConfig = RustCryptoConfig;