Bug 123461 - CryptoAlgorithmDescriptionBuilder should support producing nested algorithms
Summary: CryptoAlgorithmDescriptionBuilder should support producing nested algorithms
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alexey Proskuryakov
Depends on:
Blocks: 122679
  Show dependency treegraph
Reported: 2013-10-29 13:23 PDT by Alexey Proskuryakov
Modified: 2013-10-31 09:26 PDT (History)
2 users (show)

See Also:

proposed patch (4.31 KB, patch)
2013-10-29 13:25 PDT, Alexey Proskuryakov
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Proskuryakov 2013-10-29 13:23:03 PDT
Many WebCrypto algorithms have nested algorithms, like hash in HMAC. We need to expose that as CryptoKey.algorithm.
Comment 1 Alexey Proskuryakov 2013-10-29 13:25:49 PDT
Created attachment 215415 [details]
proposed patch
Comment 2 Darin Adler 2013-10-29 14:57:38 PDT
Comment on attachment 215415 [details]
proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=215415&action=review

> Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.cpp:49
> +    return std::unique_ptr<CryptoAlgorithmDescriptionBuilder>(new JSCryptoAlgorithmBuilder(m_exec));

We should use make_unique here.

> Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.cpp:70
> +    const JSCryptoAlgorithmBuilder* jsBuilder = static_cast<const JSCryptoAlgorithmBuilder*>(nestedBuilder);

What guarantees this is a good cast?

> Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.h:51
> +    virtual void add(const char*, const CryptoAlgorithmDescriptionBuilder*) OVERRIDE;

Why is this a pointer, not a reference?
Comment 3 Alexey Proskuryakov 2013-10-29 15:11:45 PDT
> 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

    std::unique_ptr<CryptoAlgorithmDescriptionBuilder> hashDescriptionBuilder(builder.createEmptyClone());
    hashDescriptionBuilder->add("name", CryptoAlgorithmRegistry::shared().nameForIdentifier(m_hash));
    builder.add("hash", hashDescriptionBuilder.get()); // will add a star when add() takes a reference as you suggested

    builder.add("length", m_key.size());
Comment 4 Alexey Proskuryakov 2013-10-31 09:26:46 PDT
Committed <http://trac.webkit.org/r158361>.