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

120 statements  

1"""Timestamp protocol objects.""" 

2 

3from __future__ import annotations 

4 

5import abc 

6import enum 

7from typing import TYPE_CHECKING 

8 

9from rfc3161_client import _rust 

10 

11if TYPE_CHECKING: 

12 import datetime 

13 

14 import cryptography.x509 

15 

16 

17class MessageImprint(metaclass=abc.ABCMeta): 

18 """Represents a Message Imprint (per RFC 3161).""" 

19 

20 @property 

21 @abc.abstractmethod 

22 def hash_algorithm(self) -> cryptography.x509.ObjectIdentifier: 

23 """Returns the Object Identifier of the Hash algorithm used.""" 

24 

25 @property 

26 @abc.abstractmethod 

27 def message(self) -> bytes: 

28 """Return the hashed message.""" 

29 

30 

31MessageImprint.register(_rust.PyMessageImprint) 

32 

33 

34class TimeStampRequest(metaclass=abc.ABCMeta): 

35 """Represents a Timestamp Request (per RFC 3161).""" 

36 

37 @property 

38 @abc.abstractmethod 

39 def version(self) -> int: 

40 """Returns the version of the Timestamp Request.""" 

41 

42 @property 

43 @abc.abstractmethod 

44 def nonce(self) -> int | None: 

45 """Returns the nonce generated for this request.""" 

46 

47 @property 

48 @abc.abstractmethod 

49 def policy(self) -> cryptography.x509.ObjectIdentifier | None: 

50 """Returns the request policy OID.""" 

51 

52 @property 

53 @abc.abstractmethod 

54 def cert_req(self) -> bool: 

55 """Is the certificate request present.""" 

56 

57 @property 

58 @abc.abstractmethod 

59 def message_imprint(self) -> MessageImprint: 

60 """Returns the Timestamp Request Message Imprint.""" 

61 

62 @abc.abstractmethod 

63 def as_bytes(self) -> bytes: 

64 """Returns the Timestamp Request as bytes.""" 

65 

66 

67TimeStampRequest.register(_rust.TimeStampReq) 

68 

69 

70class PKIStatus(enum.IntEnum): 

71 """Response status.""" 

72 

73 GRANTED = 0 

74 GRANTED_WITH_MODS = 1 

75 REJECTION = 2 

76 WAITING = 3 

77 REVOCATION_WARNING = 4 

78 REVOCATION_NOTIFICATION = 5 

79 

80 

81class TimeStampResponse(metaclass=abc.ABCMeta): 

82 """Timestamp response (per RFC 3161).""" 

83 

84 @property 

85 @abc.abstractmethod 

86 def status(self) -> int: 

87 """Returns the status of the Timestamp Response.""" 

88 

89 @property 

90 @abc.abstractmethod 

91 def status_string(self) -> list[str]: 

92 """Returns the status string.""" 

93 

94 @property 

95 @abc.abstractmethod 

96 def tst_info(self) -> TimeStampTokenInfo: 

97 """Returns the Timestamp Token Info.""" 

98 

99 @property 

100 @abc.abstractmethod 

101 def signed_data(self) -> SignedData: 

102 """Returns the Signed Data.""" 

103 

104 @abc.abstractmethod 

105 def time_stamp_token(self) -> bytes: 

106 """Return the bytes of the TimestampToken field.""" 

107 

108 @abc.abstractmethod 

109 def as_bytes(self) -> bytes: 

110 """Returns the Timestamp Response as bytes.""" 

111 

112 

113TimeStampResponse.register(_rust.TimeStampResp) 

114 

115 

116class Accuracy(metaclass=abc.ABCMeta): 

117 """Accuracy of the timestamp response.""" 

118 

119 @property 

120 @abc.abstractmethod 

121 def seconds(self) -> int: 

122 """Returns the seconds.""" 

123 

124 @property 

125 @abc.abstractmethod 

126 def millis(self) -> int | None: 

127 """Returns the seconds.""" 

128 

129 @property 

130 @abc.abstractmethod 

131 def micros(self) -> int | None: 

132 """Returns the seconds.""" 

133 

134 

135Accuracy.register(_rust.Accuracy) 

136 

137 

138class TimeStampTokenInfo(metaclass=abc.ABCMeta): 

139 """Timestamp token info (per RFC 3161).""" 

140 

141 @property 

142 @abc.abstractmethod 

143 def version(self) -> int: 

144 """Returns the version.""" 

145 

146 @property 

147 @abc.abstractmethod 

148 def policy(self) -> cryptography.x509.ObjectIdentifier: 

149 """Returns the policy OID.""" 

150 

151 @property 

152 @abc.abstractmethod 

153 def message_imprint(self) -> MessageImprint: 

154 """Returns the Message Imprint.""" 

155 

156 @property 

157 @abc.abstractmethod 

158 def serial_number(self) -> int: 

159 """Returns the Serial Number.""" 

160 

161 @property 

162 @abc.abstractmethod 

163 def gen_time(self) -> datetime.datetime: 

164 """Returns the policy OID.""" 

165 

166 @property 

167 @abc.abstractmethod 

168 def accuracy(self) -> Accuracy: 

169 """Returns the Accuracy.""" 

170 

171 @property 

172 @abc.abstractmethod 

173 def ordering(self) -> bool: 

174 """Returns the ordering.""" 

175 

176 @property 

177 @abc.abstractmethod 

178 def nonce(self) -> int: 

179 """Returns the nonce.""" 

180 

181 @property 

182 @abc.abstractmethod 

183 def name(self) -> cryptography.x509.GeneralName: 

184 """Returns the name.""" 

185 

186 

187TimeStampTokenInfo.register(_rust.PyTSTInfo) 

188 

189 

190class SignedData(metaclass=abc.ABCMeta): 

191 """Signed data (CMS - RFC 2630)""" 

192 

193 @property 

194 @abc.abstractmethod 

195 def version(self) -> int: 

196 """Returns the version.""" 

197 

198 @property 

199 @abc.abstractmethod 

200 def digest_algorithms(self) -> set[cryptography.x509.ObjectIdentifier]: 

201 """Returns the set of digest algorithms.""" 

202 

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 """ 

209 

210 @property 

211 @abc.abstractmethod 

212 def signer_infos(self) -> set[SignerInfo]: 

213 """Returns the signers infos.""" 

214 

215 

216SignedData.register(_rust.SignedData) 

217 

218 

219class SignerInfo(metaclass=abc.ABCMeta): 

220 """Signer info (RFC 2634).""" 

221 

222 @property 

223 @abc.abstractmethod 

224 def version(self) -> int: 

225 """Returns the version.""" 

226 

227 

228SignerInfo.register(_rust.SignerInfo)