Exact JWS Compact Serialization, and validate with the given key. If key is not provided, the returned dict will contain the signature, and signing input values. Via `Section 7.1`_. :param s: text of JWS Compact Serialization :param key: key used to verify the signat
(self, s, key, decode=None)
| 79 | return b".".join([protected_segment, payload_segment, signature]) |
| 80 | |
| 81 | def deserialize_compact(self, s, key, decode=None): |
| 82 | """Exact JWS Compact Serialization, and validate with the given key. |
| 83 | If key is not provided, the returned dict will contain the signature, |
| 84 | and signing input values. Via `Section 7.1`_. |
| 85 | |
| 86 | :param s: text of JWS Compact Serialization |
| 87 | :param key: key used to verify the signature |
| 88 | :param decode: a function to decode payload data |
| 89 | :return: JWSObject |
| 90 | :raise: BadSignatureError |
| 91 | |
| 92 | .. _`Section 7.1`: https://tools.ietf.org/html/rfc7515#section-7.1 |
| 93 | """ |
| 94 | if len(s) > self.MAX_CONTENT_LENGTH: |
| 95 | raise ValueError("Serialization is too long.") |
| 96 | |
| 97 | try: |
| 98 | s = to_bytes(s) |
| 99 | signing_input, signature_segment = s.rsplit(b".", 1) |
| 100 | protected_segment, payload_segment = signing_input.split(b".", 1) |
| 101 | except ValueError as exc: |
| 102 | raise DecodeError("Not enough segments") from exc |
| 103 | |
| 104 | protected = _extract_header(protected_segment) |
| 105 | self._validate_crit_headers(protected) |
| 106 | jws_header = JWSHeader(protected, None) |
| 107 | |
| 108 | payload = _extract_payload(payload_segment) |
| 109 | if decode: |
| 110 | payload = decode(payload) |
| 111 | |
| 112 | signature = _extract_signature(signature_segment) |
| 113 | rv = JWSObject(jws_header, payload, "compact") |
| 114 | algorithm, key = self._prepare_algorithm_key(jws_header, payload, key) |
| 115 | if algorithm.verify(signing_input, signature, key): |
| 116 | return rv |
| 117 | raise BadSignatureError(rv) |
| 118 | |
| 119 | def serialize_json(self, header_obj, payload, key): |
| 120 | """Generate a JWS JSON Serialization. The JWS JSON Serialization |
no test coverage detected