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::{DecodeWithMemTracking, U256};
33use subspace_runtime_primitives::Moment;
34
35#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
37pub struct SignatureVerificationRequest {
38 pub public_key_info: DerVec,
40 pub signature_algorithm: DerVec,
42 pub data: Vec<u8>,
44 pub signature: Vec<u8>,
46}
47
48#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
50pub struct Validity {
51 pub not_before: Moment,
53 pub not_after: Moment,
55}
56
57impl Validity {
58 pub fn is_valid_at(&self, time: Moment) -> bool {
60 time >= self.not_before && time <= self.not_after
61 }
62}
63
64#[cfg(feature = "std")]
66#[derive(TypeInfo, Encode, Decode, Debug, PartialEq)]
67pub enum ValidityError {
68 Overflow,
70}
71
72#[cfg(feature = "std")]
73impl TryFrom<x509_parser::prelude::Validity> for Validity {
74 type Error = ValidityError;
75
76 fn try_from(value: x509_parser::certificate::Validity) -> Result<Self, Self::Error> {
77 Ok(Validity {
78 not_before: (value.not_before.timestamp() as u64)
79 .checked_mul(1000)
80 .and_then(|secs| {
81 secs.checked_add(value.not_before.to_datetime().millisecond() as u64)
82 })
83 .ok_or(Self::Error::Overflow)?,
84 not_after: (value.not_after.timestamp() as u64)
85 .checked_mul(1000)
86 .and_then(|secs| {
87 secs.checked_add(value.not_after.to_datetime().millisecond() as u64)
88 })
89 .ok_or(Self::Error::Overflow)?,
90 })
91 }
92}
93
94#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
96pub struct TbsCertificate {
97 pub serial: U256,
99 pub subject_common_name: Vec<u8>,
101 pub subject_public_key_info: DerVec,
103 pub validity: Validity,
105}
106
107#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone, DecodeWithMemTracking)]
109pub struct DerVec(pub Vec<u8>);
110
111impl AsRef<[u8]> for DerVec {
112 fn as_ref(&self) -> &[u8] {
113 &self.0
114 }
115}
116
117impl From<Vec<u8>> for DerVec {
118 fn from(value: Vec<u8>) -> Self {
119 Self(value)
120 }
121}