Skip to content

Commit 451003b

Browse files
authored
remove Certificate abc (#11989)
1 parent 7a246af commit 451003b

File tree

2 files changed

+52
-163
lines changed

2 files changed

+52
-163
lines changed

src/cryptography/hazmat/bindings/_rust/x509.pyi

+51-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import datetime
66
import typing
77

88
from cryptography import x509
9-
from cryptography.hazmat.primitives import hashes
9+
from cryptography.hazmat.primitives import hashes, serialization
10+
from cryptography.hazmat.primitives.asymmetric.ec import ECDSA
1011
from cryptography.hazmat.primitives.asymmetric.padding import PSS, PKCS1v15
11-
from cryptography.hazmat.primitives.asymmetric.types import PrivateKeyTypes
12+
from cryptography.hazmat.primitives.asymmetric.types import (
13+
CertificatePublicKeyTypes,
14+
PrivateKeyTypes,
15+
)
1216

1317
def load_pem_x509_certificate(
1418
data: bytes, backend: typing.Any = None
@@ -53,7 +57,51 @@ def create_x509_crl(
5357
) -> x509.CertificateRevocationList: ...
5458

5559
class Sct: ...
56-
class Certificate: ...
60+
61+
class Certificate:
62+
def fingerprint(self, algorithm: hashes.HashAlgorithm) -> bytes: ...
63+
@property
64+
def serial_number(self) -> int: ...
65+
@property
66+
def version(self) -> x509.Version: ...
67+
def public_key(self) -> CertificatePublicKeyTypes: ...
68+
@property
69+
def public_key_algorithm_oid(self) -> x509.ObjectIdentifier: ...
70+
@property
71+
def not_valid_before(self) -> datetime.datetime: ...
72+
@property
73+
def not_valid_before_utc(self) -> datetime.datetime: ...
74+
@property
75+
def not_valid_after(self) -> datetime.datetime: ...
76+
@property
77+
def not_valid_after_utc(self) -> datetime.datetime: ...
78+
@property
79+
def issuer(self) -> x509.Name: ...
80+
@property
81+
def subject(self) -> x509.Name: ...
82+
@property
83+
def signature_hash_algorithm(
84+
self,
85+
) -> hashes.HashAlgorithm | None: ...
86+
@property
87+
def signature_algorithm_oid(self) -> x509.ObjectIdentifier: ...
88+
@property
89+
def signature_algorithm_parameters(
90+
self,
91+
) -> None | PSS | PKCS1v15 | ECDSA: ...
92+
@property
93+
def extensions(self) -> x509.Extensions: ...
94+
@property
95+
def signature(self) -> bytes: ...
96+
@property
97+
def tbs_certificate_bytes(self) -> bytes: ...
98+
@property
99+
def tbs_precertificate_bytes(self) -> bytes: ...
100+
def __eq__(self, other: object) -> bool: ...
101+
def __hash__(self) -> int: ...
102+
def public_bytes(self, encoding: serialization.Encoding) -> bytes: ...
103+
def verify_directly_issued_by(self, issuer: Certificate) -> None: ...
104+
57105
class RevokedCertificate: ...
58106
class CertificateRevocationList: ...
59107
class CertificateSigningRequest: ...

src/cryptography/x509/base.py

+1-160
Original file line numberDiff line numberDiff line change
@@ -160,166 +160,7 @@ def __init__(self, msg: str, parsed_version: int) -> None:
160160
self.parsed_version = parsed_version
161161

162162

163-
class Certificate(metaclass=abc.ABCMeta):
164-
@abc.abstractmethod
165-
def fingerprint(self, algorithm: hashes.HashAlgorithm) -> bytes:
166-
"""
167-
Returns bytes using digest passed.
168-
"""
169-
170-
@property
171-
@abc.abstractmethod
172-
def serial_number(self) -> int:
173-
"""
174-
Returns certificate serial number
175-
"""
176-
177-
@property
178-
@abc.abstractmethod
179-
def version(self) -> Version:
180-
"""
181-
Returns the certificate version
182-
"""
183-
184-
@abc.abstractmethod
185-
def public_key(self) -> CertificatePublicKeyTypes:
186-
"""
187-
Returns the public key
188-
"""
189-
190-
@property
191-
@abc.abstractmethod
192-
def public_key_algorithm_oid(self) -> ObjectIdentifier:
193-
"""
194-
Returns the ObjectIdentifier of the public key.
195-
"""
196-
197-
@property
198-
@abc.abstractmethod
199-
def not_valid_before(self) -> datetime.datetime:
200-
"""
201-
Not before time (represented as UTC datetime)
202-
"""
203-
204-
@property
205-
@abc.abstractmethod
206-
def not_valid_before_utc(self) -> datetime.datetime:
207-
"""
208-
Not before time (represented as a non-naive UTC datetime)
209-
"""
210-
211-
@property
212-
@abc.abstractmethod
213-
def not_valid_after(self) -> datetime.datetime:
214-
"""
215-
Not after time (represented as UTC datetime)
216-
"""
217-
218-
@property
219-
@abc.abstractmethod
220-
def not_valid_after_utc(self) -> datetime.datetime:
221-
"""
222-
Not after time (represented as a non-naive UTC datetime)
223-
"""
224-
225-
@property
226-
@abc.abstractmethod
227-
def issuer(self) -> Name:
228-
"""
229-
Returns the issuer name object.
230-
"""
231-
232-
@property
233-
@abc.abstractmethod
234-
def subject(self) -> Name:
235-
"""
236-
Returns the subject name object.
237-
"""
238-
239-
@property
240-
@abc.abstractmethod
241-
def signature_hash_algorithm(
242-
self,
243-
) -> hashes.HashAlgorithm | None:
244-
"""
245-
Returns a HashAlgorithm corresponding to the type of the digest signed
246-
in the certificate.
247-
"""
248-
249-
@property
250-
@abc.abstractmethod
251-
def signature_algorithm_oid(self) -> ObjectIdentifier:
252-
"""
253-
Returns the ObjectIdentifier of the signature algorithm.
254-
"""
255-
256-
@property
257-
@abc.abstractmethod
258-
def signature_algorithm_parameters(
259-
self,
260-
) -> None | padding.PSS | padding.PKCS1v15 | ec.ECDSA:
261-
"""
262-
Returns the signature algorithm parameters.
263-
"""
264-
265-
@property
266-
@abc.abstractmethod
267-
def extensions(self) -> Extensions:
268-
"""
269-
Returns an Extensions object.
270-
"""
271-
272-
@property
273-
@abc.abstractmethod
274-
def signature(self) -> bytes:
275-
"""
276-
Returns the signature bytes.
277-
"""
278-
279-
@property
280-
@abc.abstractmethod
281-
def tbs_certificate_bytes(self) -> bytes:
282-
"""
283-
Returns the tbsCertificate payload bytes as defined in RFC 5280.
284-
"""
285-
286-
@property
287-
@abc.abstractmethod
288-
def tbs_precertificate_bytes(self) -> bytes:
289-
"""
290-
Returns the tbsCertificate payload bytes with the SCT list extension
291-
stripped.
292-
"""
293-
294-
@abc.abstractmethod
295-
def __eq__(self, other: object) -> bool:
296-
"""
297-
Checks equality.
298-
"""
299-
300-
@abc.abstractmethod
301-
def __hash__(self) -> int:
302-
"""
303-
Computes a hash.
304-
"""
305-
306-
@abc.abstractmethod
307-
def public_bytes(self, encoding: serialization.Encoding) -> bytes:
308-
"""
309-
Serializes the certificate to PEM or DER format.
310-
"""
311-
312-
@abc.abstractmethod
313-
def verify_directly_issued_by(self, issuer: Certificate) -> None:
314-
"""
315-
This method verifies that certificate issuer name matches the
316-
issuer subject name and that the certificate is signed by the
317-
issuer's private key. No other validation is performed.
318-
"""
319-
320-
321-
# Runtime isinstance checks need this since the rust class is not a subclass.
322-
Certificate.register(rust_x509.Certificate)
163+
Certificate = rust_x509.Certificate
323164

324165

325166
class RevokedCertificate(metaclass=abc.ABCMeta):

0 commit comments

Comments
 (0)