Skip to main content

confium_tc/kem/
share.rs

1//! Threshold share type for KEM sessions.
2
3use serde::{Deserialize, Serialize};
4
5/// A party's share of a threshold KEM decryption key.
6///
7/// Analogous to `CFMTcShare` in the signing interface. Each party
8/// holds one share; T-of-N shares are required to decapsulate.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct ThresholdShare {
11    /// Algorithm identifier (must match the public key's algorithm).
12    pub algorithm: String,
13    /// This share's party index (0-based).
14    pub party_index: u32,
15    /// Raw share bytes (format depends on algorithm).
16    pub bytes: Vec<u8>,
17}
18
19impl ThresholdShare {
20    /// Construct a new share.
21    pub fn new(algorithm: impl Into<String>, party_index: u32, bytes: Vec<u8>) -> Self {
22        Self {
23            algorithm: algorithm.into(),
24            party_index,
25            bytes,
26        }
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn share_construct() {
36        let s = ThresholdShare::new("ElGamal-P256-threshold", 0, vec![1, 2, 3]);
37        assert_eq!(s.algorithm, "ElGamal-P256-threshold");
38        assert_eq!(s.party_index, 0);
39        assert_eq!(s.bytes, vec![1, 2, 3]);
40    }
41}