|
14 | 14 |
|
15 | 15 | from .exceptions import InvalidSignature, InvalidDigest, InvalidInput, InvalidCertificate # noqa |
16 | 16 | from .util import (bytes_to_long, long_to_bytes, strip_pem_header, add_pem_header, ensure_bytes, ensure_str, Namespace, |
17 | | - XMLProcessor, iterate_pem, verify_x509_cert_chain) |
| 17 | + XMLProcessor, iterate_pem, verify_x509_cert_chain, bits_to_bytes_unit) |
18 | 18 | from collections import namedtuple |
19 | 19 |
|
20 | 20 | methods = Enum("Methods", "enveloped enveloping detached") |
@@ -382,7 +382,7 @@ def sign(self, data, key=None, passphrase=None, cert=None, reference_uri=None, k |
382 | 382 | if self.sign_alg.startswith("dsa-") or self.sign_alg.startswith("ecdsa-"): |
383 | 383 | # Note: The output of the DSA and ECDSA signers is a DER-encoded ASN.1 sequence of two DER integers. |
384 | 384 | (r, s) = utils.decode_dss_signature(signature) |
385 | | - int_len = key.key_size // 8 |
| 385 | + int_len = bits_to_bytes_unit(key.key_size) |
386 | 386 | signature = long_to_bytes(r, blocksize=int_len) + long_to_bytes(s, blocksize=int_len) |
387 | 387 |
|
388 | 388 | signature_value_element.text = ensure_str(b64encode(signature)) |
@@ -585,7 +585,7 @@ def _verify_signature_with_pubkey(self, signed_info_c14n, raw_signature, key_val |
585 | 585 | raise NotImplementedError() |
586 | 586 |
|
587 | 587 | def _encode_dss_signature(self, raw_signature, key_size_bits): |
588 | | - want_raw_signature_len = key_size_bits // 8 * 2 |
| 588 | + want_raw_signature_len = bits_to_bytes_unit(key_size_bits) * 2 |
589 | 589 | if len(raw_signature) != want_raw_signature_len: |
590 | 590 | raise InvalidSignature( |
591 | 591 | "Expected %d byte SignatureValue, got %d" |
|
0 commit comments