Skip to content

Commit

Permalink
pyright lint for dnssecalgs
Browse files Browse the repository at this point in the history
  • Loading branch information
rthalley committed Oct 16, 2024
1 parent d8646c5 commit 971a7a2
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions dns/dnssecalgs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from typing import Dict, Optional, Tuple, Type, Union

import dns._features
import dns.name
from dns.dnssecalgs.base import GenericPrivateKey
from dns.dnssectypes import Algorithm
from dns.exception import UnsupportedAlgorithm
from dns.rdtypes.ANY.DNSKEY import DNSKEY

# pyright: reportPossiblyUnboundVariable=false

if dns._features.have("dnssec"):
from dns.dnssecalgs.dsa import PrivateDSA, PrivateDSANSEC3SHA1
from dns.dnssecalgs.ecdsa import PrivateECDSAP256SHA256, PrivateECDSAP384SHA384
Expand Down
2 changes: 1 addition & 1 deletion dns/dnssecalgs/cryptography.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def to_pem(self) -> bytes:
class CryptographyPrivateKey(GenericPrivateKey):
key: Any = None
key_cls: Any = None
public_cls: Type[CryptographyPublicKey]
public_cls: Type[CryptographyPublicKey] # pyright: ignore

def __init__(self, key: Any) -> None: # pylint: disable=super-init-not-called
if self.key_cls is None:
Expand Down
4 changes: 3 additions & 1 deletion dns/dnssecalgs/dsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def sign(
public_dsa_key = self.key.public_key()
if public_dsa_key.key_size > 1024:
raise ValueError("DSA key size overflow")
der_signature = self.key.sign(data, self.public_cls.chosen_hash)
der_signature = self.key.sign(
data, self.public_cls.chosen_hash # pyright: ignore
)
dsa_r, dsa_s = utils.decode_dss_signature(der_signature)
dsa_t = (public_dsa_key.key_size // 8 - 64) // 8
octets = 20
Expand Down
11 changes: 7 additions & 4 deletions dns/dnssecalgs/ecdsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ def sign(
) -> bytes:
"""Sign using a private key per RFC 6605, section 4."""
algorithm = ec.ECDSA(
self.public_cls.chosen_hash, deterministic_signing=deterministic
self.public_cls.chosen_hash, # pyright: ignore
deterministic_signing=deterministic,
)
der_signature = self.key.sign(data, algorithm)
dsa_r, dsa_s = utils.decode_dss_signature(der_signature)
signature = int.to_bytes(
dsa_r, length=self.public_cls.octets, byteorder="big"
) + int.to_bytes(dsa_s, length=self.public_cls.octets, byteorder="big")
dsa_r, length=self.public_cls.octets, byteorder="big" # pyright: ignore
) + int.to_bytes(
dsa_s, length=self.public_cls.octets, byteorder="big" # pyright: ignore
)
if verify:
self.public_key().verify(signature, data)
return signature
Expand All @@ -70,7 +73,7 @@ def sign(
def generate(cls) -> "PrivateECDSA":
return cls(
key=ec.generate_private_key(
curve=cls.public_cls.curve, backend=default_backend()
curve=cls.public_cls.curve, backend=default_backend() # pyright: ignore
),
)

Expand Down
2 changes: 1 addition & 1 deletion dns/dnssecalgs/eddsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def from_dnskey(cls, key: DNSKEY) -> "PublicEDDSA":


class PrivateEDDSA(CryptographyPrivateKey):
public_cls: Type[PublicEDDSA]
public_cls: Type[PublicEDDSA] # pyright: ignore

def sign(
self,
Expand Down
4 changes: 3 additions & 1 deletion dns/dnssecalgs/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def sign(
deterministic: bool = True,
) -> bytes:
"""Sign using a private key per RFC 3110, section 3."""
signature = self.key.sign(data, padding.PKCS1v15(), self.public_cls.chosen_hash)
signature = self.key.sign(
data, padding.PKCS1v15(), self.public_cls.chosen_hash # pyright: ignore
)
if verify:
self.public_key().verify(signature, data)
return signature
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ ignore_missing_imports = true
reportUnsupportedDunderAll = false
exclude = [
"dns/_*_backend.py",
"dns/dnssecalgs/*.py",
"dns/quic/*.py",
"examples/*.py",
"tests/*.py",
Expand Down

0 comments on commit 971a7a2

Please sign in to comment.