1#![doc = include_str!("../README.md")]
2#![no_std]
3
4use rasn::prelude::*;
5
6use rasn_pkix::{
7 AlgorithmIdentifier, AuthorityInfoAccessSyntax, Certificate, CertificateSerialNumber,
8 CrlReason, Extensions, GeneralName, Name,
9};
10
11pub type Version = Integer;
12pub type Nonce = OctetString;
13pub type KeyHash = OctetString;
14pub type UnknownInfo = ();
15pub type ArchiveCutoff = GeneralizedTime;
16pub type AcceptableResponses = SequenceOf<ObjectIdentifier>;
17
18#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
20pub struct OcspRequest {
21 pub tbs_request: TbsRequest,
23 #[rasn(tag(explicit(0)))]
25 pub optional_signature: Option<Signature>,
26}
27
28#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
30pub struct TbsRequest {
31 #[rasn(tag(explicit(0)), default)]
33 pub version: Version,
34 #[rasn(tag(explicit(1)))]
36 pub requestor_name: Option<GeneralName>,
37 pub request_list: SequenceOf<Request>,
39 #[rasn(tag(explicit(2)))]
41 pub request_extensions: Option<Extensions>,
42}
43
44#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
46pub struct Signature {
47 pub signature_algorithm: AlgorithmIdentifier,
49 pub signature: BitString,
51 #[rasn(tag(explicit(0)))]
54 pub certs: Option<SequenceOf<Certificate>>,
55}
56
57#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
59pub struct Request {
60 pub req_cert: CertId,
62 #[rasn(tag(explicit(0)))]
64 pub single_request_extensions: Option<Extensions>,
65}
66
67#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
69pub struct CertId {
70 pub hash_algorithm: AlgorithmIdentifier,
73 pub issuer_name_hash: OctetString,
78 pub issuer_key_hash: OctetString,
83 pub serial_number: CertificateSerialNumber,
86}
87
88#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
90pub struct OcspResponse {
91 pub status: OcspResponseStatus,
93 #[rasn(tag(explicit(0)))]
95 pub bytes: Option<ResponseBytes>,
96}
97
98#[derive(AsnType, Clone, Copy, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
99#[rasn(enumerated)]
100pub enum OcspResponseStatus {
101 Successful = 0,
103 MalformedRequest = 1,
105 InternalError = 2,
107 TryLater = 3,
109 SigRequired = 5,
111 Unauthorized = 6,
113}
114
115#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
117pub struct ResponseBytes {
118 pub r#type: ObjectIdentifier,
120 pub response: OctetString,
122}
123
124#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
126pub struct BasicOcspResponse {
127 pub tbs_response_data: ResponseData,
129 pub signature_algorithm: AlgorithmIdentifier,
131 pub signature: BitString,
136 #[rasn(tag(explicit(0)))]
139 pub certs: Option<SequenceOf<Certificate>>,
140}
141
142#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
144pub struct ResponseData {
145 #[rasn(tag(explicit(0)), default)]
146 pub version: Version,
147 pub responder_id: ResponderId,
148 pub produced_at: GeneralizedTime,
149 pub responses: SequenceOf<SingleResponse>,
150 #[rasn(tag(explicit(1)))]
151 pub response_extensions: Option<Extensions>,
152}
153
154#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
155#[rasn(choice)]
156pub enum ResponderId {
157 #[rasn(tag(explicit(1)))]
158 ByName(Name),
159 #[rasn(tag(explicit(2)))]
160 ByKey(KeyHash),
161}
162
163#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
164pub struct SingleResponse {
165 pub cert_id: CertId,
167 pub cert_status: CertStatus,
169 pub this_update: GeneralizedTime,
171 #[rasn(tag(explicit(0)))]
173 pub next_update: Option<GeneralizedTime>,
174 #[rasn(tag(explicit(1)))]
176 pub single_extensions: Option<Extensions>,
177}
178
179#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
181#[rasn(choice)]
182pub enum CertStatus {
183 #[rasn(tag(0))]
184 Good,
185 #[rasn(tag(1))]
186 Revoked(RevokedInfo),
187 #[rasn(tag(2))]
188 Unknown(UnknownInfo),
189}
190
191#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
192pub struct RevokedInfo {
193 pub revocation_time: GeneralizedTime,
194 #[rasn(tag(explicit(0)))]
195 pub revocation_reason: Option<CrlReason>,
196}
197
198#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
199pub struct ServiceLocator {
200 pub issuer: Name,
201 pub locator: AuthorityInfoAccessSyntax,
202}
203
204#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
205pub struct CrlId {
206 #[rasn(tag(explicit(0)))]
207 pub url: Option<Ia5String>,
208 #[rasn(tag(explicit(1)))]
209 pub num: Option<Integer>,
210 #[rasn(tag(explicit(2)))]
211 pub time: Option<GeneralizedTime>,
212}