Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to block_decrypt with a different key returns a FunctionClauseError #56

Open
Qqwy opened this issue Jul 16, 2018 · 1 comment

Comments

@Qqwy
Copy link

Qqwy commented Jul 16, 2018

Given the following example, where a non-matching key is used for decryption:

encryption_key = JOSE.JWK.from_oct(<<0::128>>)
different_key = JOSE.JWK.from_oct(<<1::128>>)

encrypted_a128gcmkw = JOSE.JWE.block_encrypt(encryption_key, "{}", %{ "alg" => "A128GCMKW", "enc" => "A128GCM" }) |> JOSE.JWE.compact |> elem(1)
JOSE.JWE.block_decrypt(different_key, encrypted_a128gcmkw) |> elem(0)

Expected Result

Some descriptive error message, stating that a non-matching key was used.

Actual Result

** (FunctionClauseError) no function clause matching in :jose_jwe_enc_aes.block_decrypt/4

Improving this would be great, because in a system where multiple remote parties connect to each-other using JOSE, implementers need good feedback to know where implementation mistakes are happening (malformed key? malformed cyphertext? malformed plain text after decoding?).

It would be even nicer if you can alter the signature of the decryption functions to return ok/error-tuples, and provide versions with bangs that throw.

@Qqwy
Copy link
Author

Qqwy commented Aug 16, 2018

If someone can point me a little bit to what causes this error, I would be willing to contribute a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To do
Development

No branches or pull requests

1 participant