I’m working on improving the SubtleCrypto docs, and had a question. The API defines a number of methods: sign()
, encrypt()
and so on, that take an algorithm
argument. This is (typically) a dictionary object, and the contents of the object differs according to the algorithm chosen. For example:
-
if you want to encrypt with
AES-CTR
you need to supply an object containing{name, counter, length}
(in the spec this is called anAesCtrParams
object) -
if you want to encrypt with
AES-GCM
you need to supply an object containing{name, iv, additionalData, tagLength}
(in the spec this is called anAesGcmParams
object).
There are quite a few of these objects:
// sign/verify
Algorithm {name}
RsaPssParams {name, saltLength}
EcdsaParams {name, hash}
// encrypt/decrypt/wrapKey/unwrapKey
RsaOaepParams {name, label?}
AesCtrParams {name, counter, length}
AesCbcParams {name, iv}
AesGcmParams {name, iv, additionalData, tagLength}
// generateKey
RsaHashedKeyGenParams {name, modulusLength, publicExponent, hash}
EcKeyGenParams {name, namedCurve}
HmacKeyGenParams {name, hash, length?}
AesKeyGenParams {name, length}
// deriveKey/deriveBits
EcdhKeyDeriveParams {name, public}
HkdfParams {name, hash, salt, info}
Pbkdf2Params {name, salt, iterations, hash}
// importKey
RsaHashedImportParams {name, hash}
EcKeyImportParams {name, namedCurve}
HmacImportParams {name, hash, length}
Also, the properties of these dictionaries have constraints: for example hash
is a string that must be one of various values, and tagLength
must be 0-128.
So the documentation for the algorithm
argument, in all these methods, can get quite complex. The SubtleCrypto
docs seem to deal with this inconsistently.
-
Sometimes they list the different objects inline, as in the page for
encrypt()
. This is a problem because it’s duplicated (the objects listed there are used in three other methods) but also because it’s cramped and hard to read, even though it omits important details. -
Sometimes, as in the page for
sign()
it just saysalgorithm
“is an object” without saying what its properties are at all, which seems terribly unhelpful.
What I would like to do is have a single page for each of these dictionary objects where I can properly describe the properties and constraints on them in one place, then link to them from the method page, like:
- to encrypt with
AES-CTR
pass anAesCtrParams
object here - to encrypt with
AES-GCM
pass anAesGcmParams
object here
Questions: what “sort of page” is this AesCtrParams
page? It seems like a “dictionary” (as opposed to “event”, “method”, property") page. Are there good examples of other docs that follow this pattern, that I ought to try to follow?
I know Sheppy previously brought this up, but IIUC his suggestion was to model “dictionary” pages after interface pages, which seems like overkill (i.e. to have a separate page for AesGcmParams.iv
). I don’t think we should do that. But I couldn’t find any documentation for a page like this, for example at https://developer.mozilla.org/en-US/docs/MDN/Contribute/Structures/Page_types#API_reference_subpage.