MCPcopy Create free account
hub / github.com/authlib/authlib / unwrap

Method unwrap

authlib/jose/drafts/_jwe_algorithms.py:183–209  ·  view source on GitHub ↗
(self, enc_alg, ek, headers, key, sender_key, tag=None)

Source from the content-addressed store, hash-verified

181 return {"ek": b"", "cek": dk, "header": h}
182
183 def unwrap(self, enc_alg, ek, headers, key, sender_key, tag=None):
184 if "epk" not in headers:
185 raise ValueError('Missing "epk" in headers')
186
187 if self.key_size is None:
188 bit_size = enc_alg.CEK_SIZE
189 else:
190 # Per draft-madden-jose-ecdh-1pu-04 §2.1, the key wrapping mode
191 # rejects content encryption algorithms other than
192 # AES_CBC_HMAC_SHA2.
193 if not isinstance(enc_alg, CBCHS2EncAlgorithm):
194 raise InvalidEncryptionAlgorithmForECDH1PUWithKeyWrappingError()
195
196 bit_size = self.key_size
197
198 sender_pubkey = sender_key.get_op_key("wrapKey")
199 epk = key.import_key(headers["epk"])
200 epk_pubkey = epk.get_op_key("wrapKey")
201 dk = self.deliver_at_recipient(
202 key, sender_pubkey, epk_pubkey, headers, bit_size, tag
203 )
204
205 if self.key_size is None:
206 return dk
207
208 kek = self.aeskw.prepare_key(dk)
209 return self.aeskw.unwrap(enc_alg, ek, headers, kek)
210
211
212JWE_DRAFT_ALG_ALGORITHMS = [

Callers

nothing calls this directly

Calls 5

deliver_at_recipientMethod · 0.95
get_op_keyMethod · 0.45
import_keyMethod · 0.45
prepare_keyMethod · 0.45

Tested by

no test coverage detected