mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-06 21:33:00 +00:00
Add pylint (#892)
* Move mypy/flake8/isort config files to more 'natural' places. * Add pylint. * Look at no-member. * Look at pointless-* and unnecessary-pass. * Look at useless-*. * Lint.
This commit is contained in:
@@ -13,23 +13,21 @@ import re
|
||||
from ansible.module_utils.common.text.converters import to_bytes
|
||||
|
||||
|
||||
"""
|
||||
An ASN.1 serialized as a string in the OpenSSL format:
|
||||
[modifier,]type[:value]
|
||||
|
||||
modifier:
|
||||
The modifier can be 'IMPLICIT:<tag_number><tag_class>,' or 'EXPLICIT:<tag_number><tag_class>' where IMPLICIT
|
||||
changes the tag of the universal value to encode and EXPLICIT prefixes its tag to the existing universal value.
|
||||
The tag_number must be set while the tag_class can be 'U', 'A', 'P', or 'C" for 'Universal', 'Application',
|
||||
'Private', or 'Context Specific' with C being the default.
|
||||
|
||||
type:
|
||||
The underlying ASN.1 type of the value specified. Currently only the following have been implemented:
|
||||
UTF8: The value must be a UTF-8 encoded string.
|
||||
|
||||
value:
|
||||
The value to encode, the format of this value depends on the <type> specified.
|
||||
"""
|
||||
# An ASN.1 serialized as a string in the OpenSSL format:
|
||||
# [modifier,]type[:value]
|
||||
#
|
||||
# 'modifier':
|
||||
# The modifier can be 'IMPLICIT:<tag_number><tag_class>,' or 'EXPLICIT:<tag_number><tag_class>' where IMPLICIT
|
||||
# changes the tag of the universal value to encode and EXPLICIT prefixes its tag to the existing universal value.
|
||||
# The tag_number must be set while the tag_class can be 'U', 'A', 'P', or 'C" for 'Universal', 'Application',
|
||||
# 'Private', or 'Context Specific' with C being the default.
|
||||
#
|
||||
# 'type':
|
||||
# The underlying ASN.1 type of the value specified. Currently only the following have been implemented:
|
||||
# UTF8: The value must be a UTF-8 encoded string.
|
||||
#
|
||||
# 'value':
|
||||
# The value to encode, the format of this value depends on the <type> specified.
|
||||
ASN1_STRING_REGEX = re.compile(
|
||||
r"^((?P<tag_type>IMPLICIT|EXPLICIT):(?P<tag_number>\d+)(?P<tag_class>U|A|P|C)?,)?"
|
||||
r"(?P<value_type>[\w\d]+):(?P<value>.*)"
|
||||
|
||||
@@ -40,9 +40,8 @@ try:
|
||||
|
||||
_HAS_CRYPTOGRAPHY = True
|
||||
except ImportError:
|
||||
_HAS_CRYPTOGRAPHY = False
|
||||
# Error handled in the calling module.
|
||||
pass
|
||||
_HAS_CRYPTOGRAPHY = False
|
||||
|
||||
try:
|
||||
import cryptography.hazmat.primitives.asymmetric.dh
|
||||
@@ -906,12 +905,13 @@ def _parse_pkcs12_35_0_0(
|
||||
# Since load_key_and_certificates succeeded, it should not fail.
|
||||
pkcs12 = backend._ffi.gc(
|
||||
backend._lib.d2i_PKCS12_bio(
|
||||
backend._bytes_to_bio(pkcs12_bytes).bio, backend._ffi.NULL
|
||||
backend._bytes_to_bio(pkcs12_bytes).bio, # pylint: disable=no-member
|
||||
backend._ffi.NULL,
|
||||
),
|
||||
backend._lib.PKCS12_free,
|
||||
)
|
||||
certificate_x509_ptr = backend._ffi.new("X509 **")
|
||||
with backend._zeroed_null_terminated_buf(
|
||||
with backend._zeroed_null_terminated_buf( # pylint: disable=no-member
|
||||
to_bytes(passphrase) if passphrase is not None else None
|
||||
) as passphrase_buffer:
|
||||
backend._lib.PKCS12_parse(
|
||||
|
||||
@@ -114,12 +114,10 @@ class CertificateBackend(metaclass=abc.ABCMeta):
|
||||
@abc.abstractmethod
|
||||
def generate_certificate(self) -> None:
|
||||
"""(Re-)Generate certificate."""
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_certificate_data(self) -> bytes:
|
||||
"""Return bytes for self.cert."""
|
||||
pass
|
||||
|
||||
def set_existing(self, certificate_bytes: bytes | None) -> None:
|
||||
"""Set existing certificate bytes. None indicates that the key does not exist."""
|
||||
|
||||
@@ -140,7 +140,9 @@ class EntrustCertificateBackend(CertificateBackend):
|
||||
}
|
||||
|
||||
try:
|
||||
result = self.ecs_client.NewCertRequest(Body=body)
|
||||
result = self.ecs_client.NewCertRequest( # pylint: disable=no-member
|
||||
Body=body
|
||||
)
|
||||
self.trackingId = result.get("trackingId")
|
||||
except RestOperationException as e:
|
||||
self.module.fail_json(
|
||||
@@ -204,9 +206,11 @@ class EntrustCertificateBackend(CertificateBackend):
|
||||
# If a trackingId is not already defined (from the result of a generate)
|
||||
# use the serial number to identify the tracking Id
|
||||
if self.trackingId is None and serial_number is not None:
|
||||
cert_results = self.ecs_client.GetCertificates(
|
||||
serialNumber=serial_number
|
||||
).get("certificates", {})
|
||||
cert_results = (
|
||||
self.ecs_client.GetCertificates( # pylint: disable=no-member
|
||||
serialNumber=serial_number
|
||||
).get("certificates", {})
|
||||
)
|
||||
|
||||
# Finding 0 or more than 1 result is a very unlikely use case, it simply means we cannot perform additional checks
|
||||
# on the 'state' as returned by Entrust Certificate Services (ECS). The general certificate validity is
|
||||
@@ -216,7 +220,9 @@ class EntrustCertificateBackend(CertificateBackend):
|
||||
|
||||
if self.trackingId is not None:
|
||||
cert_details.update(
|
||||
self.ecs_client.GetCertificate(trackingId=self.trackingId)
|
||||
self.ecs_client.GetCertificate( # pylint: disable=no-member
|
||||
trackingId=self.trackingId
|
||||
)
|
||||
)
|
||||
|
||||
return cert_details
|
||||
|
||||
@@ -132,7 +132,6 @@ class PrivateKeyBackend(metaclass=abc.ABCMeta):
|
||||
@abc.abstractmethod
|
||||
def generate_private_key(self) -> None:
|
||||
"""(Re-)Generate private key."""
|
||||
pass
|
||||
|
||||
def convert_private_key(self) -> None:
|
||||
"""Convert existing private key (self.existing_private_key) to new private key (self.private_key).
|
||||
|
||||
@@ -91,7 +91,6 @@ class PrivateKeyConvertBackend(metaclass=abc.ABCMeta):
|
||||
@abc.abstractmethod
|
||||
def get_private_key_data(self) -> bytes:
|
||||
"""Return bytes for self.src_private_key in output format."""
|
||||
pass
|
||||
|
||||
def set_existing_destination(self, *, privatekey_bytes: bytes | None) -> None:
|
||||
"""Set existing private key bytes. None indicates that the key does not exist."""
|
||||
|
||||
Reference in New Issue
Block a user