def get_header_alg(self, header): if 'alg' not in header: raise MissingAlgorithmError() alg = header['alg'] if self._algorithms and alg not in self._algorithms: raise UnsupportedAlgorithmError() if alg not in self.ALG_REGISTRY: raise UnsupportedAlgorithmError() return self.ALG_REGISTRY[alg]
def _validate_header(self, header): if 'alg' not in header: raise MissingAlgorithmError() alg = header['alg'] if alg not in self._algorithms: raise UnsupportedAlgorithmError() names = self.REGISTERED_HEADER_PARAMETER_NAMES.copy() if self._private_headers: names = names.union(self._private_headers) for k in header: if k not in names: raise InvalidHeaderParameterName(k)
def _prepare_algorithm_key(self, header, payload, key): if 'alg' not in header: raise MissingAlgorithmError() alg = header['alg'] if self._algorithms and alg not in self._algorithms: raise UnsupportedAlgorithmError() if alg not in self.ALGORITHMS_REGISTRY: raise UnsupportedAlgorithmError() algorithm = self.ALGORITHMS_REGISTRY[alg] if callable(key): key = key(header, payload) elif 'jwk' in header: key = header['jwk'] key = algorithm.prepare_key(key) return algorithm, key
def _validate_header(self, header): if 'alg' not in header: raise MissingAlgorithmError() alg = header['alg'] if alg not in self._algorithms: raise UnsupportedAlgorithmError() # only validate private headers when developers set # private headers explicitly if self._private_headers is not None: names = self.REGISTERED_HEADER_PARAMETER_NAMES.copy() names = names.union(self._private_headers) for k in header: if k not in names: raise InvalidHeaderParameterName(k)
def _pre_validate_header(self, header): if 'alg' not in header: raise MissingAlgorithmError() alg = header['alg'] if alg not in self._alg_algorithms: raise UnsupportedAlgorithmError() if 'enc' not in header: raise MissingEncryptionAlgorithmError() enc = header['enc'] if enc not in self._enc_algorithms: raise UnsupportedEncryptionAlgorithmError() zip = header.get('zip') if zip and zip not in self._zip_algorithms: raise UnsupportedCompressionAlgorithmError()