Skip to content

Commit

Permalink
chore: improve for mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Jul 27, 2023
1 parent 3ef18b2 commit bfd7d1f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/joserfc/drafts/jwe_ecdh_1pu.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, key_wrapping: t.Optional[JWEKeyWrapping]):
self.key_size = key_wrapping.key_size
self.key_wrapping = key_wrapping

def _check_enc(self, enc: JWEEncModel):
def _check_enc(self, enc: JWEEncModel) -> None:
if self.key_wrapping and not isinstance(enc, CBCHS2EncModel):
description = (
'In key agreement with key wrapping mode ECDH-1PU algorithm '
Expand Down
18 changes: 9 additions & 9 deletions src/joserfc/jwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@ class JWKRegistry(_JWKRegistry):
}


class GuestProtocol(t.Protocol): # pragma: no cover
def headers(self) -> Header:
...

def set_kid(self, kid: str):
...


Key = t.Union[OctKey, RSAKey, ECKey, OKPKey]
KeyCallable = t.Callable[[t.Any], Key]
KeyCallable = t.Callable[[GuestProtocol], Key]


class KeySet(_KeySet):
Expand All @@ -71,14 +79,6 @@ class KeySet(_KeySet):
KeyFlexible = t.Union[t.AnyStr, Key, KeySet, KeyCallable]


class GuestProtocol(t.Protocol): # pragma: no cover
def headers(self) -> Header:
...

def set_kid(self, kid: str):
...


def guess_key(key: KeyFlexible, obj: GuestProtocol) -> Key:
"""Guess key from a various sources.
Expand Down
8 changes: 5 additions & 3 deletions src/joserfc/jws.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@


# register supported alg models
def __register():
def __register() -> None:
# register alg in RFC7518
for _alg in JWS_ALGORITHMS:
JWSRegistry.register(_alg)
Expand Down Expand Up @@ -193,7 +193,8 @@ def serialize_json(
payload: t.AnyStr,
private_key: KeyFlexible,
algorithms: t.Optional[t.List[str]] = None,
registry: t.Optional[JWSRegistry] = None):
registry: t.Optional[JWSRegistry] = None,
) -> t.Union[GeneralJSONSerialization, FlattenedJSONSerialization]:
"""Generate a JWS JSON Serialization (in dict). The JWS JSON Serialization
represents digitally signed or MACed content as a JSON object. This representation
is neither optimized for compactness nor URL-safe.
Expand Down Expand Up @@ -251,7 +252,8 @@ def deserialize_json(
value: t.Union[GeneralJSONSerialization, FlattenedJSONSerialization],
public_key: KeyFlexible,
algorithms: t.Optional[t.List[str]] = None,
registry: t.Optional[JWSRegistry] = None):
registry: t.Optional[JWSRegistry] = None,
) -> t.Union[GeneralJSONSignature, FlattenedJSONSignature]:
"""Extract and validate the JWS (in string) with the given key.
:param value: a dict of the JSON signature
Expand Down
4 changes: 2 additions & 2 deletions src/joserfc/rfc7518/derive_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def derive_key_for_concat_kdf(
header: Header,
cek_size: int,
key_size: t.Optional[int],
tag: t.Optional[bytes] = None):
tag: t.Optional[bytes] = None) -> bytes:
# PartyUInfo
apu_info = u32be_len_input(header.get("apu"), True)
# PartyVInfo
Expand Down Expand Up @@ -48,7 +48,7 @@ def derive_key_for_concat_kdf(
return ckdf.derive(shared_key)


def u32be_len_input(s, use_base64=False):
def u32be_len_input(s, use_base64=False) -> bytes:
if not s:
return b"\x00\x00\x00\x00"
if use_base64:
Expand Down

0 comments on commit bfd7d1f

Please sign in to comment.