use uor_foundation::enforcement::{GroundedShape, ShapeViolation};
use uor_foundation::pipeline::{ConstrainedTypeShape, ConstraintRef, IntoBindingValue};
macro_rules! parametric_byte_shape {
($(#[$attr:meta])* $name:ident) => {
$(#[$attr])*
#[derive(Debug, Clone, Copy)]
pub struct $name<const BYTES: usize>;
impl<const BYTES: usize> Default for $name<BYTES> {
fn default() -> Self {
Self
}
}
impl<const BYTES: usize> ConstrainedTypeShape for $name<BYTES> {
const IRI: &'static str = "https://uor.foundation/type/ConstrainedType";
const SITE_COUNT: usize = BYTES;
const CONSTRAINTS: &'static [ConstraintRef] = &[];
#[allow(clippy::cast_possible_truncation)]
const CYCLE_SIZE: u64 = 256u64.saturating_pow(BYTES as u32);
}
impl<const BYTES: usize> uor_foundation::pipeline::__sdk_seal::Sealed
for $name<BYTES>
{
}
impl<const BYTES: usize> GroundedShape for $name<BYTES> {}
impl<const BYTES: usize> IntoBindingValue for $name<BYTES> {
const MAX_BYTES: usize = BYTES;
fn into_binding_bytes(&self, _out: &mut [u8]) -> Result<usize, ShapeViolation> {
Ok(0)
}
}
};
}
parametric_byte_shape! {
Digest
}
parametric_byte_shape! {
PublicKey
}
parametric_byte_shape! {
Signature
}