isideload_apple_codesign/remote_signing/session_negotiation.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! Session establishment and crypto code for remote signing protocol.
6//!
7//! The intent of this module / file is to isolate the code with the highest
8//! sensitivity for security matters.
9
10use {
11 crate::remote_signing::RemoteSignError,
12 std::fmt::{Display, Formatter},
13};
14
15type Result<T> = std::result::Result<T, RemoteSignError>;
16
17/// The role being assumed by a peer.
18#[derive(Clone, Copy, Debug)]
19pub enum Role {
20 /// Peer who initiated the session.
21 A,
22 /// Peer who joined the session.
23 B,
24}
25
26impl Display for Role {
27 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
28 f.write_str(match self {
29 Self::A => "A",
30 Self::B => "B",
31 })
32 }
33}
34
35/// Describes a type that is capable of decrypting messages used during public key negotiation.
36pub trait PublicKeyPeerDecrypt {
37 /// Decrypt an encrypted message.
38 fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>>;
39}