Compare commits

...
Author SHA1 Message Date
4103c913a7 Update Rust crate chacha20poly1305 to 0.11
Some checks failed
renovate/stability-days Updates have met minimum release age requirement
CI / checks (pull_request) Failing after 5m56s
2026-08-14 16:00:52 +03:00
Alex Emmet
188caf56cc [Fix] Clean
All checks were successful
CI / checks (push) Successful in 4m36s
2026-08-14 14:39:09 +02:00
13 changed files with 125 additions and 158 deletions

1
Cargo.lock generated
View file

@ -1485,7 +1485,6 @@ dependencies = [
"mtp-host",
"mtp-transport",
"quinn",
"rand",
"rcgen",
"rustls",
"thiserror 2.0.20",

View file

@ -200,14 +200,13 @@ pub(crate) async fn expire_pending_request(
let mut expired = dispatcher.expired_requests.lock().await;
let now = Instant::now();
expired.retain(|_, expires_at| *expires_at > now);
if expired.len() >= MAX_EXPIRED_REQUEST_TOMBSTONES {
if let Some(oldest) = expired
if expired.len() >= MAX_EXPIRED_REQUEST_TOMBSTONES
&& let Some(oldest) = expired
.iter()
.min_by_key(|(_, expires_at)| **expires_at)
.map(|(id, _)| *id)
{
expired.remove(&oldest);
}
{
expired.remove(&oldest);
}
expired.insert(request_id, now + EXPIRED_REQUEST_TOMBSTONE_TTL);
}

View file

@ -16,8 +16,8 @@ pub use mtp_common::{CodecError, TimeError, unix_time_millis};
#[cfg(feature = "crypto")]
pub use protected::{
CURRENT_PROTECTED_VERSION, InMemoryReplayGuard, ProtectedError, ProtectedMessageBuilder,
ReplayError, ReplayGuard, VerifiedProtectedMessage, open_protected, open_protected_with,
open_protected_with_keys, protected_claimed_signer_id,
ProtectedOpenOptions, ReplayError, ReplayGuard, VerifiedProtectedMessage, open_protected,
open_protected_with, open_protected_with_keys, protected_claimed_signer_id,
};
#[cfg(feature = "crypto")]
pub use relay::{

View file

@ -247,6 +247,35 @@ pub struct VerifiedProtectedMessage {
pub matched_signer_key_index: usize,
}
/// Options that control verification of a direct protected message.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ProtectedOpenOptions {
/// Require the protected frame to be addressed to this receiver when set.
pub expected_receiver_id: Option<u64>,
/// Purpose used to verify the protected envelope signature.
pub signature_purpose: ProtectionPurpose,
/// Purpose used to decrypt the protected envelope.
pub encryption_purpose: ProtectionPurpose,
/// Signature algorithms accepted by the receiver.
pub policy: ProtectionPolicy,
}
impl ProtectedOpenOptions {
pub const fn new(
expected_receiver_id: Option<u64>,
signature_purpose: ProtectionPurpose,
encryption_purpose: ProtectionPurpose,
policy: ProtectionPolicy,
) -> Self {
Self {
expected_receiver_id,
signature_purpose,
encryption_purpose,
policy,
}
}
}
fn protected_field_id(
data_type: DataType,
type_map: &TypeMap,
@ -385,10 +414,7 @@ pub fn open_protected_with<F>(
keyrings: &[&Keyring],
expected_signer_id: Option<u64>,
resolve_signer_keys: F,
expected_receiver_id: Option<u64>,
signature_purpose: ProtectionPurpose,
encryption_purpose: ProtectionPurpose,
policy: ProtectionPolicy,
options: ProtectedOpenOptions,
replay_guard: Option<&mut dyn ReplayGuard>,
) -> Result<VerifiedProtectedMessage, ProtectedError>
where
@ -396,7 +422,7 @@ where
{
validate_protected_frame(frame)?;
let type_map = frame.type_map().cloned().unwrap_or_else(TypeMap::latest);
let decrypted = decrypt_protected_payload(frame, keyrings, encryption_purpose)?;
let decrypted = decrypt_protected_payload(frame, keyrings, options.encryption_purpose)?;
let signed = decrypted
.as_signed()
.ok_or(ProtectedError::PayloadNotSigned)?;
@ -411,16 +437,7 @@ where
}
let signer_keys = resolve_signer_keys(signed.signer_id)
.ok_or(ProtectionError::SignerKeyNotFound(signed.signer_id))?;
open_decrypted_protected(
frame,
type_map,
signed,
&signer_keys,
expected_receiver_id,
signature_purpose,
policy,
replay_guard,
)
open_decrypted_protected(frame, type_map, signed, &signer_keys, options, replay_guard)
}
/// Open a direct protected message against already resolved trusted signer
@ -431,14 +448,11 @@ pub fn open_protected_with_keys(
keyrings: &[&Keyring],
expected_signer_id: u64,
signer_public_keys: &[PublicKeyBundle],
expected_receiver_id: Option<u64>,
signature_purpose: ProtectionPurpose,
encryption_purpose: ProtectionPurpose,
policy: ProtectionPolicy,
options: ProtectedOpenOptions,
replay_guard: Option<&mut dyn ReplayGuard>,
) -> Result<VerifiedProtectedMessage, ProtectedError> {
let type_map = validate_protected_frame(frame)?;
let decrypted = decrypt_protected_payload(frame, keyrings, encryption_purpose)?;
let decrypted = decrypt_protected_payload(frame, keyrings, options.encryption_purpose)?;
let signed = decrypted
.as_signed()
.ok_or(ProtectedError::PayloadNotSigned)?;
@ -454,9 +468,7 @@ pub fn open_protected_with_keys(
type_map,
signed,
signer_public_keys,
expected_receiver_id,
signature_purpose,
policy,
options,
replay_guard,
)
}
@ -468,21 +480,15 @@ pub fn open_protected(
keyring: &Keyring,
expected_signer_id: u64,
signer_public_key: &PublicKeyBundle,
expected_receiver_id: Option<u64>,
signature_purpose: ProtectionPurpose,
encryption_purpose: ProtectionPurpose,
policy: ProtectionPolicy,
options: ProtectedOpenOptions,
replay_guard: Option<&mut dyn ReplayGuard>,
) -> Result<VerifiedProtectedMessage, ProtectedError> {
open_protected_with_keys(
frame,
std::slice::from_ref(&keyring),
expected_signer_id,
std::slice::from_ref(&signer_public_key),
expected_receiver_id,
signature_purpose,
encryption_purpose,
policy,
std::slice::from_ref(signer_public_key),
options,
replay_guard,
)
}
@ -492,19 +498,20 @@ fn open_decrypted_protected(
type_map: TypeMap,
signed: &crate::SignedValue,
signer_public_keys: &[PublicKeyBundle],
expected_receiver_id: Option<u64>,
signature_purpose: ProtectionPurpose,
policy: ProtectionPolicy,
options: ProtectedOpenOptions,
mut replay_guard: Option<&mut dyn ReplayGuard>,
) -> Result<VerifiedProtectedMessage, ProtectedError> {
let matched_signer_key_index = signed.verify_with_key_history_index(
signed.signer_id,
signer_public_keys,
signature_purpose,
policy,
options.signature_purpose,
options.policy,
)?;
let receiver_id = frame.receiver().ok_or(ProtectedError::MissingReceiver)?;
if expected_receiver_id.is_some_and(|expected| expected != receiver_id) {
if options
.expected_receiver_id
.is_some_and(|expected| expected != receiver_id)
{
return Err(ProtectedError::ExpectedReceiverMismatch);
}
if frame
@ -568,6 +575,15 @@ mod tests {
const SIGNATURE_PURPOSE: ProtectionPurpose = ProtectionPurpose(0x40);
const ENCRYPTION_PURPOSE: ProtectionPurpose = ProtectionPurpose(0x41);
fn open_options(expected_receiver_id: Option<u64>) -> ProtectedOpenOptions {
ProtectedOpenOptions::new(
expected_receiver_id,
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
)
}
#[derive(Default)]
struct RecordingReplayGuard {
created_at: Option<u64>,
@ -720,10 +736,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
Some(42),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(42)),
Some(&mut guard),
)
.expect("protected message should open");
@ -737,10 +750,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
Some(42),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(42)),
Some(&mut guard),
),
Err(ProtectedError::Replay)
@ -777,10 +787,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
Some(42),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(42)),
None,
)
.expect("outer fields should verify");
@ -813,10 +820,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
Some(42),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(42)),
None,
),
Err(ProtectedError::MissingProtectedVersion)
@ -844,10 +848,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
Some(42),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(42)),
None,
),
Err(ProtectedError::UnsupportedProtectedVersion(2))
@ -897,10 +898,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
None,
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(None),
None,
),
Err(ProtectedError::MessageTypeMismatch)
@ -913,10 +911,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
None,
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(None),
None,
),
Err(ProtectedError::FinalRecipientMismatch)
@ -944,10 +939,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
None,
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(None),
None,
),
Err(ProtectedError::FinalRecipientMismatch)
@ -959,10 +951,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
Some(43),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(43)),
None,
),
Err(ProtectedError::ExpectedReceiverMismatch)
@ -994,10 +983,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
Some(42),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(42)),
None,
)
.expect("matching exposed sender");
@ -1007,10 +993,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
Some(42),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(42)),
None,
),
Err(ProtectedError::SenderMismatch)
@ -1049,10 +1032,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
Some(42),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(42)),
None,
),
Err(ProtectedError::PayloadNotEncrypted)
@ -1066,10 +1046,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
Some(42),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(42)),
None,
),
Err(ProtectedError::PayloadNotSigned)
@ -1090,10 +1067,7 @@ mod tests {
resolver_calls += 1;
Some(vec![sender.public_key_bundle()])
},
Some(42),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(42)),
None,
);
assert!(matches!(
@ -1138,10 +1112,7 @@ mod tests {
current_sender.public_key_bundle(),
old_sender.public_key_bundle(),
],
Some(42),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(42)),
None,
)
.expect("key history should open");
@ -1167,10 +1138,7 @@ mod tests {
&recipient,
7,
&sender.public_key_bundle(),
Some(42),
SIGNATURE_PURPOSE,
ENCRYPTION_PURPOSE,
ProtectionPolicy::from(crate::SignaturePolicy::Ed25519),
open_options(Some(42)),
None,
)
.expect("arbitrary application value should open");

View file

@ -7,7 +7,7 @@ edition = "2024"
ignored = ["rand_core"]
[dependencies]
chacha20poly1305 = { version = "0.10", optional = true }
chacha20poly1305 = { version = "0.11", optional = true }
aes-gcm = { version = "0.10", optional = true }
ed25519-dalek = { version = "3.0", optional = true, features = [
"pkcs8",

1
example/Cargo.lock generated
View file

@ -1404,7 +1404,6 @@ dependencies = [
"mtp-host",
"mtp-transport",
"quinn",
"rand",
"rustls",
"thiserror 2.0.20",
"tokio",

View file

@ -2,7 +2,7 @@ use std::collections::HashMap;
use mtp::codec::{
CommunicationType, CommunicationValue, DataType, DataTypeId, DataValue, InMemoryReplayGuard,
ProtectionPolicy, ProtectionPurpose, SignaturePolicy, TypeMap,
ProtectedOpenOptions, ProtectionPolicy, ProtectionPurpose, SignaturePolicy, TypeMap,
forward_relay_frame, open_protected_with, open_relay_content, open_relay_metadata_with,
};
use mtp::crypto::{Keyring, PublicKeyBundle};
@ -70,10 +70,12 @@ fn process_direct_protected(
std::slice::from_ref(&host_keyring),
None,
|signer_id| resolve_signer_key(signer_id, registered_clients).map(|key| vec![key]),
Some(DIRECT_DESTINATION_ID),
ProtectionPurpose::from(DIRECT_SIGNATURE_PURPOSE),
ProtectionPurpose::from(DIRECT_ENCRYPTION_PURPOSE),
SIGNATURE_POLICY,
ProtectedOpenOptions::new(
Some(DIRECT_DESTINATION_ID),
ProtectionPurpose::from(DIRECT_SIGNATURE_PURPOSE),
ProtectionPurpose::from(DIRECT_ENCRYPTION_PURPOSE),
SIGNATURE_POLICY,
),
Some(accepted_messages),
)
.map_err(|e| format!("direct protected message could not be authenticated: {e}"))?;

View file

@ -344,7 +344,7 @@ impl HandshakeEngine {
// Authenticated clients include PublicKeys in Identification as an
// intent marker; this avoids acknowledging the opening as a guest
// connection and leaving the client waiting for a Challenge.
if Some(first_msg.get_type()) == CommunicationType::Register.try_to_id(&tm)
if Some(first_msg.get_type()) == CommunicationType::Register.try_to_id(tm)
|| first_msg.get_data(DataType::PublicKeys).is_some()
{
send_rejection_generic(
@ -400,7 +400,7 @@ impl HandshakeEngine {
let tm = codec.type_map();
// Register frames always go through full authentication
if Some(first_msg.get_type()) == CommunicationType::Register.try_to_id(&tm) {
if Some(first_msg.get_type()) == CommunicationType::Register.try_to_id(tm) {
let bundle = match extract_register_bundle(&first_msg) {
Ok(bundle) => bundle,
Err(error) => {
@ -425,7 +425,7 @@ impl HandshakeEngine {
}
// Identification: try lookup, fall back to guest
if Some(first_msg.get_type()) == CommunicationType::Identification.try_to_id(&tm) {
if Some(first_msg.get_type()) == CommunicationType::Identification.try_to_id(tm) {
let cid = match first_msg.get_data(DataType::Id) {
Some(DataValue::UnsignedNumber(n)) => u64::try_from(*n).unwrap_or(0),
_ => 0,
@ -504,7 +504,7 @@ impl HandshakeEngine {
let tm = codec.type_map();
let (flow, response_type) = if Some(first_msg.get_type())
== CommunicationType::Identification.try_to_id(&tm)
== CommunicationType::Identification.try_to_id(tm)
{
let cid = match first_msg.get_data(DataType::Id) {
Some(DataValue::UnsignedNumber(n)) => match u64::try_from(*n) {
@ -545,7 +545,7 @@ impl HandshakeEngine {
Flow::Login { id: cid, bundle },
CommunicationType::IdentificationResponse,
)
} else if Some(first_msg.get_type()) == CommunicationType::Register.try_to_id(&tm) {
} else if Some(first_msg.get_type()) == CommunicationType::Register.try_to_id(tm) {
let bundle = match extract_register_bundle(&first_msg) {
Ok(bundle) => bundle,
Err(error) => {
@ -710,7 +710,7 @@ impl HandshakeEngine {
sender.close();
AcceptError::Receive(e)
})?;
if Some(proof.get_type()) != CommunicationType::ChallengeResponse.try_to_id(&tm) {
if Some(proof.get_type()) != CommunicationType::ChallengeResponse.try_to_id(tm) {
let error = AcceptError::AuthenticationFailed("missing challenge response".into());
reject_error_generic(sender, &error, tm).await;
return Err(error);
@ -1041,8 +1041,8 @@ impl HandshakeSender for mtp_transport::Sender {
) -> impl std::future::Future<Output = Result<(), CommunicationError>> + Send {
mtp_transport::Sender::finish_stream(self)
}
fn set_type_map(&self, type_map: &TypeMap) -> impl std::future::Future<Output = ()> + Send {
async move { self.set_type_map(type_map).await }
async fn set_type_map(&self, type_map: &TypeMap) {
self.set_type_map(type_map).await;
}
fn close(&self) {
let sender = self.clone();
@ -1058,8 +1058,8 @@ impl HandshakeReceiver for mtp_transport::Receiver {
mtp_transport::Receiver::receive(self)
}
fn set_type_map(&self, type_map: &TypeMap) -> impl std::future::Future<Output = ()> + Send {
async move { self.set_type_map(type_map).await }
async fn set_type_map(&self, type_map: &TypeMap) {
self.set_type_map(type_map).await;
}
}
@ -1075,8 +1075,8 @@ impl<C: mtp_transport::TransportConnection> HandshakeSender for mtp_transport::G
) -> impl std::future::Future<Output = Result<(), CommunicationError>> + Send {
mtp_transport::GenericSender::finish_stream(self)
}
fn set_type_map(&self, type_map: &TypeMap) -> impl std::future::Future<Output = ()> + Send {
async move { self.set_type_map(type_map).await }
async fn set_type_map(&self, type_map: &TypeMap) {
self.set_type_map(type_map).await;
}
fn close(&self) {
mtp_transport::GenericSender::close(self);
@ -1093,8 +1093,8 @@ impl<C: mtp_transport::TransportConnection> HandshakeReceiver
mtp_transport::GenericReceiver::receive(self)
}
fn set_type_map(&self, type_map: &TypeMap) -> impl std::future::Future<Output = ()> + Send {
async move { self.set_type_map(type_map).await }
async fn set_type_map(&self, type_map: &TypeMap) {
self.set_type_map(type_map).await;
}
}

View file

@ -25,7 +25,6 @@ rustls = "0.23"
tracing = "0.1"
thiserror = "2"
async-trait = "0.1"
rand = { version = "0.10.1", optional = true }
[dev-dependencies]
rcgen = "0.14"
@ -33,5 +32,5 @@ hyper = { version = "1", features = ["client", "http2"] }
[features]
default = []
crypto = ["mtp-host/crypto", "dep:rand"]
crypto = ["mtp-host/crypto"]
pipes = ["mtp-host/pipes", "mtp-transport/pipes"]

View file

@ -220,6 +220,7 @@ pub type WebMtpReceiver = GenericReceiver<H3TransportConnection>;
pub type WebMTPConnection =
mtp_host::MTPConnection<WebMtpSender, WebMtpReceiver, H3TransportReceiver>;
#[allow(clippy::too_many_arguments)]
pub(crate) async fn accept_web_connection(
session: Arc<Session>,
path: String,
@ -268,6 +269,7 @@ pub(crate) async fn accept_web_connection(
.await
}
#[allow(clippy::too_many_arguments)]
async fn accept_web_connection_inner(
session: Arc<Session>,
path: String,

View file

@ -1078,18 +1078,12 @@ impl Receiver {
#[instrument(skip(self), level = "trace")]
pub async fn receive(&self) -> Result<CommunicationValue, CommunicationError> {
let mut close_rx = self.inner.handle.subscribe_close();
if close_rx.borrow().is_some() {
return Err(self
.inner
.handle
.close_reason()
.unwrap_or(CommunicationError::StreamClosed));
}
#[cfg(feature = "pipes")]
{
let mut rx = self.inner.msg_rx.lock().await;
let result = tokio::select! {
biased;
message = rx.recv() => message,
_ = close_rx.changed() => return Err(close_rx
.borrow()
@ -1113,6 +1107,7 @@ impl Receiver {
{
let mut rx = self.inner.rx.lock().await;
let result = tokio::select! {
biased;
message = rx.recv() => message,
_ = close_rx.changed() => return Err(close_rx
.borrow()
@ -1136,17 +1131,11 @@ impl Receiver {
#[cfg(feature = "pipes")]
#[instrument(skip(self), level = "trace")]
pub async fn receive_event(&self) -> Result<TransportEvent, CommunicationError> {
if self.inner.handle.is_closed() {
return Err(self
.inner
.handle
.close_reason()
.unwrap_or(CommunicationError::StreamClosed));
}
let mut close_rx = self.inner.handle.subscribe_close();
let mut msg_rx = self.inner.msg_rx.lock().await;
let mut pipe_rx = self.inner.pipe_rx.lock().await;
tokio::select! {
biased;
msg = msg_rx.recv() => {
match msg {
Some(Ok(val)) => {
@ -1174,6 +1163,10 @@ impl Receiver {
.unwrap_or(CommunicationError::StreamClosed)),
}
}
_ = close_rx.changed() => Err(close_rx
.borrow()
.clone()
.unwrap_or(CommunicationError::StreamClosed)),
}
}

View file

@ -342,13 +342,17 @@ async fn test_max_frames_per_stream_enforced() -> Result<(), Box<dyn std::error:
let tm = TypeMap::latest();
client_tx
.send(&numbered_message(CommunicationType::Ping, 1, &tm))
.await?;
let first = host_rx.receive().await?;
.await
.expect("first frame should be sent");
let first = host_rx
.receive()
.await
.expect("first frame should be received");
assert_numbered_message(&first, CommunicationType::Ping, 1, &tm);
client_tx
let _ = client_tx
.send(&numbered_message(CommunicationType::Ping, 2, &tm))
.await?;
.await;
let second = host_rx.receive().await;
assert!(second.is_err(), "stream should be closed after frame limit");

View file

@ -1,8 +1,8 @@
use wasm_bindgen::prelude::*;
use mtp_codec::{
DataValue, ProtectedError, ProtectedMessageBuilder, ProtectionError, ProtectionPurpose,
VerifiedProtectedMessage,
DataValue, ProtectedError, ProtectedMessageBuilder, ProtectedOpenOptions, ProtectionError,
ProtectionPurpose, VerifiedProtectedMessage,
};
use crate::crypto::{
@ -273,10 +273,12 @@ pub fn open_protected_with_keyrings(
&references,
expected_signer_id,
&signer_public_keys,
expected_receiver_id,
ProtectionPurpose::from(signature_purpose),
ProtectionPurpose::from(encryption_purpose),
policy,
ProtectedOpenOptions::new(
expected_receiver_id,
ProtectionPurpose::from(signature_purpose),
ProtectionPurpose::from(encryption_purpose),
policy,
),
None,
)
.map_err(protected_error)?;