#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "std")]
pub mod host_functions;
mod runtime_interface;
#[cfg(not(feature = "std"))]
extern crate alloc;
pub use crate::runtime_interface::auto_id_runtime_interface;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_core::U256;
use sp_runtime_interface::pass_by;
use sp_runtime_interface::pass_by::PassBy;
use subspace_runtime_primitives::Moment;
#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
pub struct SignatureVerificationRequest {
pub public_key_info: DerVec,
pub signature_algorithm: DerVec,
pub data: Vec<u8>,
pub signature: Vec<u8>,
}
impl PassBy for SignatureVerificationRequest {
type PassBy = pass_by::Codec<Self>;
}
#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
pub struct Validity {
pub not_before: Moment,
pub not_after: Moment,
}
impl Validity {
pub fn is_valid_at(&self, time: Moment) -> bool {
time >= self.not_before && time <= self.not_after
}
}
#[cfg(feature = "std")]
#[derive(TypeInfo, Encode, Decode, Debug, PartialEq)]
pub enum ValidityError {
Overflow,
}
#[cfg(feature = "std")]
impl TryFrom<x509_parser::prelude::Validity> for Validity {
type Error = ValidityError;
fn try_from(value: x509_parser::certificate::Validity) -> Result<Self, Self::Error> {
Ok(Validity {
not_before: (value.not_before.timestamp() as u64)
.checked_mul(1000)
.and_then(|secs| {
secs.checked_add(value.not_before.to_datetime().millisecond() as u64)
})
.ok_or(Self::Error::Overflow)?,
not_after: (value.not_after.timestamp() as u64)
.checked_mul(1000)
.and_then(|secs| {
secs.checked_add(value.not_after.to_datetime().millisecond() as u64)
})
.ok_or(Self::Error::Overflow)?,
})
}
}
#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
pub struct TbsCertificate {
pub serial: U256,
pub subject_common_name: Vec<u8>,
pub subject_public_key_info: DerVec,
pub validity: Validity,
}
#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
pub struct DerVec(pub Vec<u8>);
impl PassBy for DerVec {
type PassBy = pass_by::Codec<Self>;
}
impl AsRef<[u8]> for DerVec {
fn as_ref(&self) -> &[u8] {
&self.0
}
}
impl From<Vec<u8>> for DerVec {
fn from(value: Vec<u8>) -> Self {
Self(value)
}
}