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

Ambiguity of the Web Crypto API Doc #310

Open
ShiqiHe000 opened this issue Mar 7, 2022 · 1 comment
Open

Ambiguity of the Web Crypto API Doc #310

ShiqiHe000 opened this issue Mar 7, 2022 · 1 comment

Comments

@ShiqiHe000
Copy link

Hi! I was reading the web crypto API spec and I found an unmatched implementation.

Under the importKey() method spec:
Point 2. If format is equal to the string "jwk":

  1. If the keyData parameter passed to the importKey() method is not a JsonWebKey dictionary, throw a **TypeError**.

However, under the RSASSA-PKCS1-v1_5 algorithm section of importKey() method:
If format is "jwk":

  • If keyData is a JsonWebKey dictionary:
    Let jwk equal keyData.
  • Otherwise:
    Throw a **DataError**.

So if the format is "jwk" and keyData is not a JsonWebKey, the general importKey() spec throws a TypeError, but the algorithm-specific spec throws a DataError. It seems like the doc has some inconsistencies in the API Doc.

@twiss
Copy link
Member

twiss commented Nov 1, 2022

Hey 👋 Thanks for the report, and apologies for the delay.

I would say that the text is not necessarily ambiguous, since the first check comes strictly before the second one, so a TypeError should be thrown if importKey('jwk', nonJsonWebKey, ...) is called. The "Import Key" steps can be reached from one other place, namely the unwrapKey method, but also there, it's not possible to end up in the import key steps with format == "jwk" and keyData being anything other than a JsonWebKey.

So, I think the second check (and identical checks for the other algorithms) can simply be removed.

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

No branches or pull requests

2 participants