Many WebCrypto algorithms have nested algorithms, like hash in HMAC. We need to expose that as CryptoKey.algorithm.
Created attachment 215415 [details]
Comment on attachment 215415 [details]
View in context: https://bugs.webkit.org/attachment.cgi?id=215415&action=review
> + return std::unique_ptr<CryptoAlgorithmDescriptionBuilder>(new JSCryptoAlgorithmBuilder(m_exec));
We should use make_unique here.
> + const JSCryptoAlgorithmBuilder* jsBuilder = static_cast<const JSCryptoAlgorithmBuilder*>(nestedBuilder);
What guarantees this is a good cast?
> + virtual void add(const char*, const CryptoAlgorithmDescriptionBuilder*) OVERRIDE;
Why is this a pointer, not a reference?
> What guarantees this is a good cast?
Not much. The code that clones a builder and code that adds it back will be all in one function, so it's very unlikely that a foreign builder will be passed to add(). And if a mistake like that was made, the code would just crash, so it would be discovered even by most cursory testing.
Is there a better pattern for this kind of thing?
Here is how a call site looks like:
void CryptoKeyHMAC::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& builder) const
builder.add("hash", hashDescriptionBuilder.get()); // will add a star when add() takes a reference as you suggested