Repository: IdentityPython/JWTConnect-Python-CryptoJWT

Issue:
Wrong type in JWE_EC.dec_setup
Hello cryptojwt team,
Thanks for your work, it usually works like a charm.
I found an issue in `cryptojwt.jwe.jwe_ec.JWE_EC.dec_setup`.

https://github.com/IdentityPython/JWTConnect-Python-CryptoJWT/blob/727bb9bff122a67e4e270330d990a7c1a1199664/src/cryptojwt/jwe/jwe_ec.py#L147

`apu` and `apv` are assigned `""` when they are declared. When there is no other value in the header for them subsequently `ecdh_derive_key` crashes because it's trying to concatenate these strings with bytes. I guess they should be assigned a `b""`.

As I know your time also doesn't grow on trees let me know if I can help you with providing a PR for that.

Discussion:
@jschlyter: Please create a PR and I'll process it swiftly.

Solution patch:
diff --git a/src/cryptojwt/jwe/jwe_ec.py b/src/cryptojwt/jwe/jwe_ec.py
index 8c6c616..ff36ff2 100644
--- a/src/cryptojwt/jwe/jwe_ec.py
+++ b/src/cryptojwt/jwe/jwe_ec.py
@@ -138,7 +138,7 @@ class JWE_EC(JWEKey):
             raise Exception("Ephemeral Public Key Missing in ECDH-ES Computation")
 
         epubkey = ECKey(**self.headers["epk"])
-        apu = apv = ""
+        apu = apv = b""
         if "apu" in self.headers:
             apu = b64d(self.headers["apu"].encode())
         if "apv" in self.headers:
diff --git a/src/cryptojwt/utils.py b/src/cryptojwt/utils.py
index 535c776..db41d64 100644
--- a/src/cryptojwt/utils.py
+++ b/src/cryptojwt/utils.py
@@ -126,12 +126,12 @@ def b64d(b):
     return base64.urlsafe_b64decode(b)
 
 
-def b64e_enc_dec(str, encode="utf-8", decode="ascii"):
-    return b64e(str.encode(encode)).decode(decode)
+def b64e_enc_dec(datastr, encode="utf-8", decode="ascii"):
+    return b64e(datastr.encode(encode)).decode(decode)
 
 
-def b64d_enc_dec(str, encode="ascii", decode="utf-8"):
-    return b64d(str.encode(encode)).decode(decode)
+def b64d_enc_dec(datastr, encode="ascii", decode="utf-8"):
+    return b64d(datastr.encode(encode)).decode(decode)
 
 
 def as_bytes(s):


Test patch:
diff --git a/tests/test_07_jwe.py b/tests/test_07_jwe.py
index ac855d0..a83cf9d 100644
--- a/tests/test_07_jwe.py
+++ b/tests/test_07_jwe.py
@@ -443,6 +443,32 @@ def test_ecdh_encrypt_decrypt_direct_key():
     assert msg == plain
 
 
+def test_ecdh_encrypt_decrypt_direct_key_wo_apu_apv():
+    # Alice starts of
+    jwenc = JWE_EC(plain, alg="ECDH-ES", enc="A128GCM")
+
+    # Don't supply agreement party information.
+    cek, encrypted_key, iv, params, ret_epk = jwenc.enc_setup(plain, key=eck_bob, apu=b"", apv=b"")
+    # Assert they are not randomized
+    assert params["apv"] == b""
+    assert params["apu"] == b""
+
+    # Delete agreement party information
+    del params["apv"]
+    del params["apu"]
+
+    kwargs = {"params": params, "cek": cek, "iv": iv, "encrypted_key": encrypted_key}
+    jwt = jwenc.encrypt(**kwargs)
+
+    # Bob decrypts
+    ret_jwe = factory(jwt, alg="ECDH-ES", enc="A128GCM")
+    jwdec = JWE_EC()
+    jwdec.dec_setup(ret_jwe.jwt, key=bob)
+    msg = jwdec.decrypt(ret_jwe.jwt)
+
+    assert msg == plain
+
+
 def test_ecdh_encrypt_decrypt_keywrapped_key():
     jwenc = JWE_EC(plain, alg="ECDH-ES+A128KW", enc="A128GCM")
     cek, encrypted_key, iv, params, ret_epk = jwenc.enc_setup(plain, key=eck_bob)