#[path = "verify_internal/mod.rs"]
mod verify_internal;
use ed25519_dalek::VerifyingKey;
use crate::canonicalize::CanonicalizeError;
use crate::error::RegistryResult;
use crate::trust::TrustStore;
use crate::types::FetchResult;
pub const PAYLOAD_TYPE_PACK_V1: &str = "application/vnd.assay.pack+yaml;v=1";
#[derive(Debug, Clone)]
pub struct VerifyResult {
pub signed: bool,
pub key_id: Option<String>,
pub digest: String,
}
#[derive(Debug, Clone, Default)]
pub struct VerifyOptions {
pub allow_unsigned: bool,
pub skip_signature: bool,
}
impl VerifyOptions {
pub fn allow_unsigned(mut self) -> Self {
self.allow_unsigned = true;
self
}
pub fn skip_signature(mut self) -> Self {
self.skip_signature = true;
self
}
}
pub fn verify_pack(
result: &FetchResult,
trust_store: &TrustStore,
options: &VerifyOptions,
) -> RegistryResult<VerifyResult> {
verify_internal::policy::verify_pack_impl(result, trust_store, options)
}
pub fn verify_digest(content: &str, expected: &str) -> RegistryResult<()> {
verify_internal::digest::verify_digest_impl(content, expected)
}
pub fn compute_digest(content: &str) -> String {
verify_internal::digest::compute_digest_impl(content)
}
pub fn compute_digest_strict(content: &str) -> Result<String, CanonicalizeError> {
verify_internal::digest::compute_digest_strict_impl(content)
}
#[deprecated(since = "2.11.0", note = "use compute_digest for canonical JCS digest")]
pub fn compute_digest_raw(content: &str) -> String {
verify_internal::digest::compute_digest_raw_impl(content)
}
pub fn compute_key_id(spki_bytes: &[u8]) -> String {
verify_internal::keys::compute_key_id_impl(spki_bytes)
}
pub fn compute_key_id_from_key(key: &VerifyingKey) -> RegistryResult<String> {
verify_internal::keys::compute_key_id_from_key_impl(key)
}