Skip to content

Commit

Permalink
Add py.typed marker
Browse files Browse the repository at this point in the history
  • Loading branch information
rkoopmans committed Oct 24, 2023
1 parent 42ab9ae commit c90ebde
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
7 changes: 4 additions & 3 deletions cert_chain_resolver/models.py
Expand Up @@ -9,6 +9,7 @@

try:
from typing import List, Union, Optional, Type, Iterator, TYPE_CHECKING

if TYPE_CHECKING:
import datetime
except ImportError:
Expand Down Expand Up @@ -184,16 +185,16 @@ def get_fingerprint(self, _hash=hashes.SHA256):

def export(self, encoding=Encoding.PEM):
# type: (Encoding) -> str
"""Export the :py:class:`cryptography.x509.Certificate` object"
"""Export the :py:class:`cryptography.x509.Certificate` object" as text
Args:
encoding (:py:class:`cryptography.hazmat.primitives.serialization.Encoding`, optional): The output format. Defaults to Encoding.PEM.
Returns:
ascii formatted
"""
encoded = unicode(self._x509.public_bytes(encoding), "ascii")
return encoded
encoded = self._x509.public_bytes(encoding)
return encoded.decode(encoding="ascii")

@classmethod
def load(cls, bytes_input):
Expand Down
9 changes: 3 additions & 6 deletions cert_chain_resolver/utils.py
Expand Up @@ -14,8 +14,7 @@

def load_ascii_to_x509(bytes_input):
# type: (bytes) -> x509.Certificate
""" Converts ASCII PKCS7 or Certificate to a :py:class:`cryptography.x509.Certificate` object
"""
"""Converts ASCII PKCS7 or Certificate to a :py:class:`cryptography.x509.Certificate` object"""
first_line = bytes_input.decode("ascii").splitlines()[0]
if first_line == "-----BEGIN PKCS7-----":
return pkcs7.load_pem_pkcs7_certificates(bytes_input)[0]
Expand All @@ -26,8 +25,7 @@ def load_ascii_to_x509(bytes_input):

def load_der_to_x509(bytes_input):
# type: (bytes) -> x509.Certificate
""" Converts bytes formatted DER (PKCS7 or Cert) to :py:class:`cryptography.x509.Certificate` object
"""
"""Converts bytes formatted DER (PKCS7 or Cert) to :py:class:`cryptography.x509.Certificate` object"""
try:
return x509.load_der_x509_certificate(bytes_input)
except ValueError:
Expand All @@ -36,8 +34,7 @@ def load_der_to_x509(bytes_input):

def load_bytes_to_x509(bytes_input):
# type: (bytes) -> x509.Certificate
""" Converts Certificate / PKCS7 in ASCII or DER to :py:class:`cryptography.x509.Certificate` object
"""
"""Converts Certificate / PKCS7 in ASCII or DER to :py:class:`cryptography.x509.Certificate` object"""
try:
return load_ascii_to_x509(bytes_input)
except UnicodeDecodeError:
Expand Down
Empty file added py.typed
Empty file.
9 changes: 6 additions & 3 deletions setup.py
Expand Up @@ -21,10 +21,13 @@
long_description_content_type="text/markdown",
url="https://github.com/rkoopmans/python-certificate-chain-resolver",
packages=setuptools.find_packages(),
package_data={"cert_chain_resolver": ["py.typed"]},
install_requires=reqs,
entry_points={"console_scripts": ["cert-chain-resolver = cert_chain_resolver.cli:main"]},
license='MIT',
license_file='LICENSE.txt',
entry_points={
"console_scripts": ["cert-chain-resolver = cert_chain_resolver.cli:main"]
},
license="MIT",
license_file="LICENSE.txt",
classifiers=[
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
Expand Down

0 comments on commit c90ebde

Please sign in to comment.