ic-platform 0.33.4

Controlled Candid and IC runtime dependency boundary
Documentation
//! Shared state-root signature composition; primitives remain in the BLS boundary.
use super::Certificate;

#[derive(Clone, Copy)]
pub(crate) enum RootKey<'a> {
    Raw(&'a [u8]),
    #[cfg(feature = "signature-verification")]
    Prepared(&'a crate::bls::PreparedPublicKey),
}

pub(crate) fn authenticate_certificate(
    certificate: &Certificate,
    key: RootKey<'_>,
) -> Result<(), ()> {
    // The BLS boundary owns checked point/subgroup admission and identity refusal
    // for both root and delegated keys; no second point decode is needed here.
    let mut signed = [0; 46];
    signed[..14].copy_from_slice(b"\x0dic-state-root");
    signed[14..].copy_from_slice(&certificate.tree.digest());
    match key {
        RootKey::Raw(bytes) => {
            crate::bls::verify_bls_signature(&certificate.signature, &signed, bytes)
        }
        #[cfg(feature = "signature-verification")]
        RootKey::Prepared(key) => crate::bls::Signature::deserialize(&certificate.signature)
            .map_err(|_| ())
            .and_then(|signature| key.verify(&signed, &signature)),
    }
}