-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Progress to making signify fully typed and use black
- Loading branch information
Showing
21 changed files
with
930 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[mypy] | ||
python_version = 3.7 | ||
disallow_incomplete_defs = True | ||
|
||
[mypy-asn1crypto.*] | ||
ignore_missing_imports = True | ||
[mypy-certvalidator.*] | ||
ignore_missing_imports = True | ||
[mypy-oscrypto.*] | ||
ignore_missing_imports = True | ||
[mypy-pyasn1.*] | ||
ignore_missing_imports = True | ||
[mypy-pyasn1_modules.*] | ||
ignore_missing_imports = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ asn1crypto>=1.3,<2 | |
oscrypto>=1.1,<2 | ||
pyasn1-modules>=0.2.8 | ||
mscerts | ||
typing_extensions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import hashlib | ||
from typing import Callable, Tuple | ||
|
||
from typing_extensions import TypeAlias | ||
|
||
HashFunction: TypeAlias = Callable[[], "hashlib._Hash"] | ||
OidTuple: TypeAlias = Tuple[int, ...] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from __future__ import annotations | ||
|
||
import hashlib | ||
from typing import Iterable, cast | ||
|
||
from pyasn1.type import univ | ||
from pyasn1_modules import rfc5280 | ||
|
||
from signify import asn1, _print_type | ||
from signify._typing import HashFunction | ||
from signify.asn1 import guarded_ber_decode | ||
from signify.exceptions import ParseError | ||
|
||
# this list must be in the order of worst to best | ||
ACCEPTED_DIGEST_ALGORITHMS = (hashlib.md5, hashlib.sha1, hashlib.sha256, hashlib.sha384, hashlib.sha512) | ||
|
||
|
||
def _verify_empty_algorithm_parameters(algorithm: rfc5280.AlgorithmIdentifier, location: str) -> None: | ||
if "parameters" in algorithm and algorithm["parameters"].isValue: | ||
parameters = guarded_ber_decode(algorithm["parameters"]) | ||
if not isinstance(parameters, univ.Null): | ||
raise ParseError("%s has parameters set, which is unexpected" % (location,)) | ||
|
||
|
||
def _get_digest_algorithm( | ||
algorithm: rfc5280.AlgorithmIdentifier, | ||
location: str, | ||
acceptable: Iterable[HashFunction] = ACCEPTED_DIGEST_ALGORITHMS, | ||
) -> HashFunction: | ||
result = asn1.oids.get(algorithm["algorithm"], asn1.oids.OID_TO_HASH) | ||
if isinstance(result, tuple) or result not in acceptable: | ||
raise ParseError( | ||
"%s must be one of %s, not %s" % (location, [x().name for x in acceptable], _print_type(result)) | ||
) | ||
|
||
_verify_empty_algorithm_parameters(algorithm, location) | ||
|
||
return cast(HashFunction, result) | ||
|
||
|
||
def _get_encryption_algorithm(algorithm: univ.Sequence, location: str) -> str: | ||
result = asn1.oids.OID_TO_PUBKEY.get(algorithm["algorithm"]) | ||
if result is None: | ||
raise ParseError("%s: %s is not acceptable as encryption algorithm" % (location, algorithm["algorithm"])) | ||
|
||
_verify_empty_algorithm_parameters(algorithm, location) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.