Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/rfc3161_client/tsp.py: 98%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Timestamp protocol objects."""
3from __future__ import annotations
5import abc
6import enum
7from typing import TYPE_CHECKING
9from rfc3161_client import _rust
11if TYPE_CHECKING:
12 import datetime
14 import cryptography.x509
17class MessageImprint(metaclass=abc.ABCMeta):
18 """Represents a Message Imprint (per RFC 3161)."""
20 @property
21 @abc.abstractmethod
22 def hash_algorithm(self) -> cryptography.x509.ObjectIdentifier:
23 """Returns the Object Identifier of the Hash algorithm used."""
25 @property
26 @abc.abstractmethod
27 def message(self) -> bytes:
28 """Return the hashed message."""
31MessageImprint.register(_rust.PyMessageImprint)
34class TimeStampRequest(metaclass=abc.ABCMeta):
35 """Represents a Timestamp Request (per RFC 3161)."""
37 @property
38 @abc.abstractmethod
39 def version(self) -> int:
40 """Returns the version of the Timestamp Request."""
42 @property
43 @abc.abstractmethod
44 def nonce(self) -> int | None:
45 """Returns the nonce generated for this request."""
47 @property
48 @abc.abstractmethod
49 def policy(self) -> cryptography.x509.ObjectIdentifier | None:
50 """Returns the request policy OID."""
52 @property
53 @abc.abstractmethod
54 def cert_req(self) -> bool:
55 """Is the certificate request present."""
57 @property
58 @abc.abstractmethod
59 def message_imprint(self) -> MessageImprint:
60 """Returns the Timestamp Request Message Imprint."""
62 @abc.abstractmethod
63 def as_bytes(self) -> bytes:
64 """Returns the Timestamp Request as bytes."""
67TimeStampRequest.register(_rust.TimeStampReq)
70class PKIStatus(enum.IntEnum):
71 """Response status."""
73 GRANTED = 0
74 GRANTED_WITH_MODS = 1
75 REJECTION = 2
76 WAITING = 3
77 REVOCATION_WARNING = 4
78 REVOCATION_NOTIFICATION = 5
81class TimeStampResponse(metaclass=abc.ABCMeta):
82 """Timestamp response (per RFC 3161)."""
84 @property
85 @abc.abstractmethod
86 def status(self) -> int:
87 """Returns the status of the Timestamp Response."""
89 @property
90 @abc.abstractmethod
91 def status_string(self) -> list[str]:
92 """Returns the status string."""
94 @property
95 @abc.abstractmethod
96 def tst_info(self) -> TimeStampTokenInfo:
97 """Returns the Timestamp Token Info."""
99 @property
100 @abc.abstractmethod
101 def signed_data(self) -> SignedData:
102 """Returns the Signed Data."""
104 @abc.abstractmethod
105 def time_stamp_token(self) -> bytes:
106 """Return the bytes of the TimestampToken field."""
108 @abc.abstractmethod
109 def as_bytes(self) -> bytes:
110 """Returns the Timestamp Response as bytes."""
113TimeStampResponse.register(_rust.TimeStampResp)
116class Accuracy(metaclass=abc.ABCMeta):
117 """Accuracy of the timestamp response."""
119 @property
120 @abc.abstractmethod
121 def seconds(self) -> int:
122 """Returns the seconds."""
124 @property
125 @abc.abstractmethod
126 def millis(self) -> int | None:
127 """Returns the seconds."""
129 @property
130 @abc.abstractmethod
131 def micros(self) -> int | None:
132 """Returns the seconds."""
135Accuracy.register(_rust.Accuracy)
138class TimeStampTokenInfo(metaclass=abc.ABCMeta):
139 """Timestamp token info (per RFC 3161)."""
141 @property
142 @abc.abstractmethod
143 def version(self) -> int:
144 """Returns the version."""
146 @property
147 @abc.abstractmethod
148 def policy(self) -> cryptography.x509.ObjectIdentifier:
149 """Returns the policy OID."""
151 @property
152 @abc.abstractmethod
153 def message_imprint(self) -> MessageImprint:
154 """Returns the Message Imprint."""
156 @property
157 @abc.abstractmethod
158 def serial_number(self) -> int:
159 """Returns the Serial Number."""
161 @property
162 @abc.abstractmethod
163 def gen_time(self) -> datetime.datetime:
164 """Returns the policy OID."""
166 @property
167 @abc.abstractmethod
168 def accuracy(self) -> Accuracy:
169 """Returns the Accuracy."""
171 @property
172 @abc.abstractmethod
173 def ordering(self) -> bool:
174 """Returns the ordering."""
176 @property
177 @abc.abstractmethod
178 def nonce(self) -> int:
179 """Returns the nonce."""
181 @property
182 @abc.abstractmethod
183 def name(self) -> cryptography.x509.GeneralName:
184 """Returns the name."""
187TimeStampTokenInfo.register(_rust.PyTSTInfo)
190class SignedData(metaclass=abc.ABCMeta):
191 """Signed data (CMS - RFC 2630)"""
193 @property
194 @abc.abstractmethod
195 def version(self) -> int:
196 """Returns the version."""
198 @property
199 @abc.abstractmethod
200 def digest_algorithms(self) -> set[cryptography.x509.ObjectIdentifier]:
201 """Returns the set of digest algorithms."""
203 @property
204 @abc.abstractmethod
205 def certificates(self) -> set[bytes]:
206 """Returns the set of certificates.
207 Warning: they are returned as a byte array and should be loaded.
208 """
210 @property
211 @abc.abstractmethod
212 def signer_infos(self) -> set[SignerInfo]:
213 """Returns the signers infos."""
216SignedData.register(_rust.SignedData)
219class SignerInfo(metaclass=abc.ABCMeta):
220 """Signer info (RFC 2634)."""
222 @property
223 @abc.abstractmethod
224 def version(self) -> int:
225 """Returns the version."""
228SignerInfo.register(_rust.SignerInfo)