1#![cfg_attr(not(feature = "std"), no_std)]
19
20#[cfg(feature = "std")]
21pub mod host_functions;
22mod runtime_interface;
23
24#[cfg(not(feature = "std"))]
25extern crate alloc;
26
27pub use crate::runtime_interface::auto_id_runtime_interface;
28#[cfg(not(feature = "std"))]
29use alloc::vec::Vec;
30use parity_scale_codec::{Decode, Encode};
31use scale_info::TypeInfo;
32use sp_core::U256;
33use sp_runtime_interface::pass_by;
34use sp_runtime_interface::pass_by::PassBy;
35use subspace_runtime_primitives::Moment;
36
37#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
39pub struct SignatureVerificationRequest {
40 pub public_key_info: DerVec,
42 pub signature_algorithm: DerVec,
44 pub data: Vec<u8>,
46 pub signature: Vec<u8>,
48}
49
50impl PassBy for SignatureVerificationRequest {
51 type PassBy = pass_by::Codec<Self>;
52}
53
54#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
56pub struct Validity {
57 pub not_before: Moment,
59 pub not_after: Moment,
61}
62
63impl Validity {
64 pub fn is_valid_at(&self, time: Moment) -> bool {
66 time >= self.not_before && time <= self.not_after
67 }
68}
69
70#[cfg(feature = "std")]
72#[derive(TypeInfo, Encode, Decode, Debug, PartialEq)]
73pub enum ValidityError {
74 Overflow,
76}
77
78#[cfg(feature = "std")]
79impl TryFrom<x509_parser::prelude::Validity> for Validity {
80 type Error = ValidityError;
81
82 fn try_from(value: x509_parser::certificate::Validity) -> Result<Self, Self::Error> {
83 Ok(Validity {
84 not_before: (value.not_before.timestamp() as u64)
85 .checked_mul(1000)
86 .and_then(|secs| {
87 secs.checked_add(value.not_before.to_datetime().millisecond() as u64)
88 })
89 .ok_or(Self::Error::Overflow)?,
90 not_after: (value.not_after.timestamp() as u64)
91 .checked_mul(1000)
92 .and_then(|secs| {
93 secs.checked_add(value.not_after.to_datetime().millisecond() as u64)
94 })
95 .ok_or(Self::Error::Overflow)?,
96 })
97 }
98}
99
100#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
102pub struct TbsCertificate {
103 pub serial: U256,
105 pub subject_common_name: Vec<u8>,
107 pub subject_public_key_info: DerVec,
109 pub validity: Validity,
111}
112
113#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
115pub struct DerVec(pub Vec<u8>);
116
117impl PassBy for DerVec {
118 type PassBy = pass_by::Codec<Self>;
119}
120
121impl AsRef<[u8]> for DerVec {
122 fn as_ref(&self) -> &[u8] {
123 &self.0
124 }
125}
126
127impl From<Vec<u8>> for DerVec {
128 fn from(value: Vec<u8>) -> Self {
129 Self(value)
130 }
131}