Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py : 50%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is dual licensed under the terms of the Apache License, Version
2# 2.0, and the BSD License. See the LICENSE file in the root of this repository
3# for complete details.
6import typing
8from cryptography import utils
9from cryptography.hazmat._der import (
10 DERReader,
11 INTEGER,
12 SEQUENCE,
13 encode_der,
14 encode_der_integer,
15)
16from cryptography.hazmat.primitives import hashes
19def decode_dss_signature(signature: bytes) -> typing.Tuple[int, int]:
20 with DERReader(signature).read_single_element(SEQUENCE) as seq:
21 r = seq.read_element(INTEGER).as_integer()
22 s = seq.read_element(INTEGER).as_integer()
23 return r, s
26def encode_dss_signature(r: int, s: int) -> bytes:
27 return encode_der(
28 SEQUENCE,
29 encode_der(INTEGER, encode_der_integer(r)),
30 encode_der(INTEGER, encode_der_integer(s)),
31 )
34class Prehashed(object):
35 def __init__(self, algorithm: hashes.HashAlgorithm):
36 if not isinstance(algorithm, hashes.HashAlgorithm):
37 raise TypeError("Expected instance of HashAlgorithm.")
39 self._algorithm = algorithm
40 self._digest_size = algorithm.digest_size
42 digest_size = utils.read_only_property("_digest_size")