zoe_app_primitives/group/events/key_info.rs
1use serde::{Deserialize, Serialize};
2
3/// Information about the group's encryption key (not the key itself)
4///
5/// This enum contains typed information about different encryption algorithms
6/// and their key derivation methods, without exposing the key material itself.
7#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
8pub enum GroupKeyInfo {
9 /// ChaCha20-Poly1305 encryption with BIP39+Argon2 key derivation
10 ///
11 /// This is the standard encryption method for groups, using ChaCha20-Poly1305
12 /// for encryption and BIP39 mnemonics with Argon2 for key derivation.
13 ChaCha20Poly1305 {
14 /// Key identifier (typically a hash of the derived key)
15 key_id: Vec<u8>,
16 /// Key derivation information for recreating the key from a mnemonic
17 derivation_info: zoe_wire_protocol::crypto::KeyDerivationInfo,
18 },
19}
20
21impl GroupKeyInfo {
22 /// Create a new ChaCha20-Poly1305 GroupKeyInfo
23 pub fn new_chacha20_poly1305(
24 key_id: Vec<u8>,
25 derivation_info: zoe_wire_protocol::crypto::KeyDerivationInfo,
26 ) -> Self {
27 Self::ChaCha20Poly1305 {
28 key_id,
29 derivation_info,
30 }
31 }
32
33 /// Get the key ID for this key info
34 pub fn key_id(&self) -> &[u8] {
35 match self {
36 Self::ChaCha20Poly1305 { key_id, .. } => key_id,
37 }
38 }
39
40 /// Get the algorithm name for this key info
41 pub fn algorithm(&self) -> &str {
42 match self {
43 Self::ChaCha20Poly1305 { .. } => "ChaCha20-Poly1305",
44 }
45 }
46
47 /// Get the derivation info if available
48 pub fn derivation_info(&self) -> Option<&zoe_wire_protocol::crypto::KeyDerivationInfo> {
49 match self {
50 Self::ChaCha20Poly1305 {
51 derivation_info, ..
52 } => Some(derivation_info),
53 }
54 }
55
56 /// Check if this key info matches a given key ID
57 pub fn matches_key_id(&self, other_key_id: &[u8]) -> bool {
58 self.key_id() == other_key_id
59 }
60}