Skip to content

Conversation

@JakeChampion
Copy link
Contributor

@JakeChampion JakeChampion commented Jan 13, 2023

This pull-request is the start towards full SubtleCrypto support in the runtime.

I've implemented the SubtleCrypto class but with only one method so far, SubtleCrypto.prototype.digest.

I've made globalThis.crypto become an instance of Crypto and have added an instance of SubtleCrypto as a getter on Crypto.prototype.subtle as per the WebIDL specification:

partial interface mixin WindowOrWorkerGlobalScope {
  [SameObject] readonly attribute Crypto crypto;
};

[Exposed]
interface Crypto {
  [SecureContext] readonly attribute SubtleCrypto subtle;
  ArrayBufferView getRandomValues(ArrayBufferView array);
  [SecureContext] DOMString randomUUID();
};

Remaining parts to add in this pull-request:

  • Update documentation for globalThis.crypto to include the new subtle property.
  • New Documentation for SubtleCrypto
  • New Documentation for SubtleCrypto.prototype.digest
  • Type definitions for all the above

@JakeChampion JakeChampion requested a review from elliottt January 13, 2023 15:24
@JakeChampion JakeChampion force-pushed the jake/subtlecrypto-digest branch 3 times, most recently from 6c474f9 to 73bdfb6 Compare January 13, 2023 17:55
@JakeChampion JakeChampion marked this pull request as ready for review January 13, 2023 17:55
@JakeChampion JakeChampion force-pushed the jake/subtlecrypto-digest branch 2 times, most recently from 23fdbf5 to 25c1078 Compare January 13, 2023 18:08
Copy link
Contributor

@elliottt elliottt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just a few comments about avoiding copies when possible.

@JakeChampion JakeChampion force-pushed the jake/subtlecrypto-digest branch 4 times, most recently from c07ebc9 to 0a3d5dc Compare January 23, 2023 16:34
@JakeChampion JakeChampion requested a review from elliottt January 23, 2023 16:34
@JakeChampion JakeChampion force-pushed the jake/subtlecrypto-digest branch from 0a3d5dc to 8eee88f Compare January 23, 2023 16:37
Copy link
Contributor

@elliottt elliottt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I just had one suggestion for removing an unused vector.

builtins::CryptoAlgorithmIdentifier::AES_KW, builtins::CryptoAlgorithmIdentifier::HMAC,
builtins::CryptoAlgorithmIdentifier::HKDF, builtins::CryptoAlgorithmIdentifier::PBKDF2};
} // namespace
namespace builtins {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change this, but it's totally fine to nest anonymous namespaces within another -- it would have been fine to leave the definition of the builtins namespace on line 25.

Jake Champion added 3 commits January 24, 2023 10:19
This commit is the start towards full SubtleCrypto support in the runtime.

I've implemented the `SubtleCrypto` class but with only one method so far, `SubtleCrypto.prototype.digest`.

I've made `globalThis.crypto` become an instance of `Crypto` and have added an instance of `SubtleCrypto` as a getter on `Crypto.prototype.subtle` as per the [WebIDL specification](https://w3c.github.io/webcrypto/#webidl-1120328020):
```webidl
partial interface mixin WindowOrWorkerGlobalScope {
  [SameObject] readonly attribute Crypto crypto;
};

[Exposed]
interface Crypto {
  [SecureContext] readonly attribute SubtleCrypto subtle;
  ArrayBufferView getRandomValues(ArrayBufferView array);
  [SecureContext] DOMString randomUUID();
};
```

Currently 76 out of 80 of the Web Platform Tests pass for `SubtleCrypto.prototype.digest`, the ones which fail are to do with providing a large `data` parameter and altering the `data` parameter's buffer after calling `SubtleCrypto.prototype.digest`. I'm not sure yet as to why these tests are failing, it is confusing for me as the same test but with a smaller `data` parameter does pass as expected.
@JakeChampion JakeChampion force-pushed the jake/subtlecrypto-digest branch 2 times, most recently from 416e575 to f86b3d8 Compare January 24, 2023 16:23
@JakeChampion JakeChampion force-pushed the jake/subtlecrypto-digest branch from f86b3d8 to bfbadb3 Compare January 24, 2023 16:31
@JakeChampion JakeChampion merged commit bbe1754 into main Jan 24, 2023
@JakeChampion JakeChampion deleted the jake/subtlecrypto-digest branch January 24, 2023 17:57
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

Successfully merging this pull request may close these issues.

3 participants