serde_encrypt_core/key/
combined_key.rs

1//! "Combined key" for Diffie-Hellman key exchange.
2//! A combined key consists of either:
3//!
4//! - (`Alice's private key`, `Bob's public key`) pair
5//! - (`Alice's public key`, `Bob's private key`) pair
6
7use super::key_pair::{
8    private_key::{ReceiverPrivateKey, SenderPrivateKey},
9    public_key::{ReceiverPublicKey, SenderPublicKey},
10};
11
12/// (`Alice's private key`, `Bob's public key`) pair.
13///
14/// (Alice is a sender and Bob a receiver.)
15#[derive(Clone, Debug)]
16pub struct SenderCombinedKey<'s, 'r> {
17    sender_private_key: &'s SenderPrivateKey,
18    receiver_public_key: &'r ReceiverPublicKey,
19}
20
21impl<'s, 'r> SenderCombinedKey<'s, 'r> {
22    /// Constructor.
23    pub fn new(
24        sender_private_key: &'s SenderPrivateKey,
25        receiver_public_key: &'r ReceiverPublicKey,
26    ) -> Self {
27        Self {
28            sender_private_key,
29            receiver_public_key,
30        }
31    }
32
33    pub(crate) fn sender_private_key(&self) -> &SenderPrivateKey {
34        self.sender_private_key
35    }
36
37    pub(crate) fn receiver_public_key(&self) -> &ReceiverPublicKey {
38        self.receiver_public_key
39    }
40}
41
42/// (`Alice's public key`, `Bob's private key`) pair.
43///
44/// (Alice is a sender and Bob a receiver.)
45#[derive(Clone, Debug)]
46pub struct ReceiverCombinedKey<'s, 'r> {
47    sender_public_key: &'s SenderPublicKey,
48    receiver_private_key: &'r ReceiverPrivateKey,
49}
50
51impl<'s, 'r> ReceiverCombinedKey<'s, 'r> {
52    /// Constructor.
53    pub fn new(
54        sender_public_key: &'s SenderPublicKey,
55        receiver_private_key: &'r ReceiverPrivateKey,
56    ) -> Self {
57        Self {
58            sender_public_key,
59            receiver_private_key,
60        }
61    }
62
63    pub(crate) fn receiver_private_key(&self) -> &ReceiverPrivateKey {
64        self.receiver_private_key
65    }
66
67    pub(crate) fn sender_public_key(&self) -> &SenderPublicKey {
68        self.sender_public_key
69    }
70}