hbkr-rs 0.3.1

Hashblock Key Rotation
Documentation
//! kbkr Threshold

use serde::{Deserialize, Serialize};
use serde_hex::{Compact, SerHex};

use crate::{attached_signature::AttachedSignaturePrefix, errors::KrError};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(untagged)]
pub enum SignatureThreshold {
    #[serde(with = "SerHex::<Compact>")]
    Simple(u64),
}

impl SignatureThreshold {
    pub fn simple(t: u64) -> Self {
        Self::Simple(t)
    }

    pub fn enough_signatures(&self, sigs: &[AttachedSignaturePrefix]) -> Result<bool, KrError> {
        match self {
            SignatureThreshold::Simple(ref t) => Ok((sigs.len() as u64) >= *t),
        }
    }
}

impl Default for SignatureThreshold {
    fn default() -> Self {
        Self::Simple(1)
    }
}