mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-07 05:43:06 +00:00
Code refactoring (#889)
* Add __all__ to all module and plugin utils. * Convert quite a few positional args to keyword args. * Avoid Python 3.8+ syntax.
This commit is contained in:
@@ -93,7 +93,12 @@ def serialize_asn1_string_as_der(value: str) -> bytes:
|
||||
|
||||
# We should only do a universal type tag if not IMPLICITLY tagged or the tag class is not universal.
|
||||
if not tag_type or (tag_type == "EXPLICIT" and tag_class != "U"):
|
||||
b_value = pack_asn1(TagClass.universal, False, TagNumber.utf8_string, b_value)
|
||||
b_value = pack_asn1(
|
||||
tag_class=TagClass.universal,
|
||||
constructed=False,
|
||||
tag_number=TagNumber.utf8_string,
|
||||
b_data=b_value,
|
||||
)
|
||||
|
||||
if tag_type:
|
||||
tag_class_enum = {
|
||||
@@ -105,13 +110,22 @@ def serialize_asn1_string_as_der(value: str) -> bytes:
|
||||
|
||||
# When adding support for more types this should be looked into further. For now it works with UTF8Strings.
|
||||
constructed = tag_type == "EXPLICIT" and tag_class_enum != TagClass.universal
|
||||
b_value = pack_asn1(tag_class_enum, constructed, int(tag_number), b_value)
|
||||
b_value = pack_asn1(
|
||||
tag_class=tag_class_enum,
|
||||
constructed=constructed,
|
||||
tag_number=int(tag_number),
|
||||
b_data=b_value,
|
||||
)
|
||||
|
||||
return b_value
|
||||
|
||||
|
||||
def pack_asn1(
|
||||
tag_class: TagClass, constructed: bool, tag_number: TagNumber | int, b_data: bytes
|
||||
*,
|
||||
tag_class: TagClass,
|
||||
constructed: bool,
|
||||
tag_number: TagNumber | int,
|
||||
b_data: bytes,
|
||||
) -> bytes:
|
||||
"""Pack the value into an ASN.1 data structure.
|
||||
|
||||
@@ -159,3 +173,6 @@ def pack_asn1(
|
||||
b_asn1_data.extend(length_octets)
|
||||
|
||||
return bytes(b_asn1_data) + b_data
|
||||
|
||||
|
||||
__all__ = ("TagClass", "TagNumber", "serialize_asn1_string_as_der", "pack_asn1")
|
||||
|
||||
Reference in New Issue
Block a user