File: jws_eddsa.py

package info (click to toggle)
python-authlib 1.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,016 kB
  • sloc: python: 26,998; makefile: 53; sh: 14
file content (28 lines) | stat: -rw-r--r-- 717 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from cryptography.exceptions import InvalidSignature

from ..rfc7515 import JWSAlgorithm
from .okp_key import OKPKey


class EdDSAAlgorithm(JWSAlgorithm):
    name = "EdDSA"
    description = "Edwards-curve Digital Signature Algorithm for JWS"

    def prepare_key(self, raw_data):
        return OKPKey.import_key(raw_data)

    def sign(self, msg, key):
        op_key = key.get_op_key("sign")
        return op_key.sign(msg)

    def verify(self, msg, sig, key):
        op_key = key.get_op_key("verify")
        try:
            op_key.verify(sig, msg)
            return True
        except InvalidSignature:
            return False


def register_jws_rfc8037(cls):
    cls.register_algorithm(EdDSAAlgorithm())