MCPcopy
hub / github.com/authlib/authlib / unwrap

Method unwrap

authlib/jose/rfc7518/jwe_algs.py:169–189  ·  view source on GitHub ↗
(self, enc_alg, ek, headers, key)

Source from the content-addressed store, hash-verified

167 return {"ek": ek, "cek": cek, "header": h}
168
169 def unwrap(self, enc_alg, ek, headers, key):
170 op_key = key.get_op_key("unwrapKey")
171 self._check_key(op_key)
172
173 iv = headers.get("iv")
174 if not iv:
175 raise ValueError('Missing "iv" in headers')
176
177 tag = headers.get("tag")
178 if not tag:
179 raise ValueError('Missing "tag" in headers')
180
181 iv = urlsafe_b64decode(to_bytes(iv))
182 tag = urlsafe_b64decode(to_bytes(tag))
183
184 cipher = Cipher(AES(op_key), GCM(iv, tag), backend=default_backend())
185 d = cipher.decryptor()
186 cek = d.update(ek) + d.finalize()
187 if len(cek) * 8 != enc_alg.CEK_SIZE:
188 cek = secrets.token_bytes(enc_alg.CEK_SIZE // 8)
189 return cek
190
191
192class ECDHESAlgorithm(JWEAlgorithm):

Callers

nothing calls this directly

Calls 5

_check_keyMethod · 0.95
urlsafe_b64decodeFunction · 0.90
to_bytesFunction · 0.90
get_op_keyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected