w3c / webcrypto

The W3C Web Cryptography API
https://w3c.github.io/webcrypto/
Other
267 stars 56 forks source link

Ambiguity of the Web Crypto API Doc #310

Open ShiqiHe000 opened 2 years ago

ShiqiHe000 commented 2 years ago

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":

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 commented 2 years ago

Hey :wave: 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.