Skip to content

Bad error message when key type and algorithm type are incompatible #363

@mrvanes

Description

@mrvanes

When importing an EC private key from pem and using that to add_signature to a jws token, cryptography ECPrivateKey complains that the sign method only takes 2 positional arguments but 3 were given:

    jwstoken.add_signature(key, None,
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
                           json_encode({"alg": "RS256"}),
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                           json_encode({"kid": key.thumbprint()}))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Tools/venv/lib/python3.13/site-packages/jwcrypto/jws.py", line 545, in add_signature
    sig = c.sign()
  File "/Tools/venv/lib/python3.13/site-packages/jwcrypto/jws.py", line 152, in sign
    signature = self.engine.sign(self.key, sigin)
  File "/Tools/venv/lib/python3.13/site-packages/jwcrypto/jwa.py", line 133, in sign
    return skey.sign(payload, self.padfn, self.hashfn)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ECPrivateKey.sign() takes 2 positional arguments but 3 were given

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions