[CryptoService] Leverage browser native Crypto API to hash strings.#3850
Merged
lannka merged 6 commits intoampproject:masterfrom Jul 1, 2016
Merged
[CryptoService] Leverage browser native Crypto API to hash strings.#3850lannka merged 6 commits intoampproject:masterfrom
lannka merged 6 commits intoampproject:masterfrom
Conversation
…hen native API is not available or failed to execute.
| constructor(win) { | ||
| this.win = win; | ||
| if (win.crypto) { | ||
| this.subtle = win.crypto.subtle || win.crypto.webkitSubtle; |
Member
There was a problem hiding this comment.
Make private and @const and always set it (Possibly to null). Add type.
Member
There was a problem hiding this comment.
Closure externs should have webCrypto.SubtleCrypto as a type.
Contributor
Author
There was a problem hiding this comment.
How do I check that, are externs listed anywhere?
Didn't see here
Member
There was a problem hiding this comment.
I used Google's internal code search :)
Contributor
|
lgtm |
| return this.subtle.digest('SHA-384', str2ab(str)) | ||
| // [].slice.call(Unit8Array) is a shim for Array.from(Unit8Array) | ||
| .then(buffer => [].slice.call(new Uint8Array(buffer)), | ||
| () => lib.sha384(str)); |
Member
There was a problem hiding this comment.
dev.error?
Add comment about fallback.
Member
|
Nice! Excited about this. |
| sha384(str) { | ||
| if (this.subtle) { | ||
| try { | ||
| return this.subtle.digest('SHA-384', str2ab(str)) |
Contributor
There was a problem hiding this comment.
I believe these can take a UInt8Array, not just a ArrayBuffer.
| this.subtle = win.crypto.subtle || win.crypto.webkitSubtle; | ||
| } | ||
| /** @private @const {?SubtleCrypto} */ | ||
| this.subtle = getSubtle(win); |
Contributor
There was a problem hiding this comment.
Still need to append a _ it can be minified better.
| } | ||
|
|
||
| // A shim for TextEncoder | ||
| function str2ab(str) { |
Member
|
Woop woop! LGTM |
jonasmattsson1
added a commit
to widespace-os/amphtml
that referenced
this pull request
Jul 5, 2016
* master: (236 commits) trim all the columns (ampproject#3894) Refactoring: Turn private custom element methods into functions. (ampproject#3882) Lower the load priority of ad shaped iframes. (ampproject#3863) JsDoc fix (ampproject#3892) Add screenshots for Opera to AMP Validator extension. (ampproject#3866) Fix renaming of generated JSCompiler_prototypeAlias variable. (ampproject#3887) fix typo in amp-sidebar.md (ampproject#3833) Validator Roll-up (ampproject#3885) [CryptoService] Leverage browser native Crypto API to hash strings. (ampproject#3850) Size update (ampproject#3883) copy amp-ad docs to builtins (ampproject#3879) move doc to extension (ampproject#3878) [amp-experiment] Exposes isDismissed() method in AmpUserNotification (ampproject#3832) fix action-impl warning on dist (ampproject#3867) Add params for microad (ampproject#3827) Fixed some A4A tests. (ampproject#3859) Updates to colanalytics vendor config for amp-analytics. (ampproject#3849) Changes to implement A4A (AMP ads for AMP pages) (ampproject#3534) Addresses comment left over from PR#3841 (ampproject#3853) Expose submit event with on=submit:el.action syntax. (ampproject#3739) ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Highlights
This is the 2nd PR to address #3690