Create digest-stream.md#4919
Conversation
After dropping this as a comment here: w3c/webcrypto#73 (comment), I thought might be worth turning it into an example for the docs as well? Feel free to update this.
|
BTW |
|
I would recommend using sha512 in the example with a comment that it's faster than sha1 (it is). It's also faster than sha256 for longer messages but slightly slower/the same for shorter ones. processBody should have an implementation I think so that the example is copyable without doing anything. I believe all our docs are currently JS unfortunately so we should probably remain consistent until we get UI elements to dynamically switch between languages. Might not be a bad idea to return the ETag in the response header (don't forget to put quotes around it - etags in HTTP have double quotes). |
| const encoder = new TextEncoder(); | ||
|
|
||
| const etagStream = new crypto.DigestStream('SHA-1'); | ||
| const { readable, writable } = new TransformStream(); |
There was a problem hiding this comment.
Better to use new IdentityTransformStream() here.
There was a problem hiding this comment.
Sorry it's been too long, looking at this again now. Can you explain the difference, please?
There was a problem hiding this comment.
This code is using the TransformStream essentially as an identity passthrough. It is not actually transforming any bytes. This is the exact use case for IdentityTransformStream. Soon, the default implementation of new TransformStream() is going to change to be more spec compliant. It will still be an identity passthrough by default but the underlying implementation is a bit more complex. To maintain the very simple use case you have here, IdentityTransformStream is the right choice.
| const { readable, writable } = new TransformStream(); | ||
|
|
||
| const etagWriter = etagStream.getWriter(); | ||
| const resultWriter = writable.getWriter(); |
There was a problem hiding this comment.
An alternative approach here is to tee the streams.
const { writable, readable } = new IdentityTransformStream();
const [ branch1, branch2 ] = readable.tee();
env.KV.put('result', branch1);
async getDigest(readable) {
const etagStream = new crypto.DigestStream('SHA-1');
await readable.pipeTo(etagStream);
return etagStream.digest;
}
const writer = writable.getWriter();
writer.write('hello');
writer.close();
const etag = await getDigest(branch2);
// ...
|
| GitGuardian id | Secret | Commit | Filename | |
|---|---|---|---|---|
| - | Generic High Entropy Secret | 7d3d958 | config.toml | View secret |
| - | Generic High Entropy Secret | 58b6333 | products/ddos-protection/docs-config.js | View secret |
| - | Generic High Entropy Secret | f5ad72d | products/ddos-protection/docs-config.js | View secret |
| 3543783 | Generic High Entropy Secret | 51cbbad | products/ruleset-engine/docs-config.js | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Our GitHub checks need improvements? Share your feedbacks!
|
Hi @simonhaenisch , is this ready for merge? Could you please look through and accept or resolve James' suggestions? |
|
Hey sorry haven't gotten around to it, so no not yet (let me convert it to draft PR). I'll try to get to it asap. |
|
Hi @simonhaenisch , would you still like to work on this? Let me know, and thank you |
|
Hey sorry don't really have to time to finish it currently... can close it for now, and it would still be here as reference i guess. |
|
Closing per the last comment - can reopen at a later date. |
|
Disnei Mabong Wilfred Sigie shared a calendar\n\nDisnei Mabong Wilfred
Sigie ***@***.***> has invited you to see all event details on
the calendar: "Disnei Mabong Wilfred Sigie".\n\nAccept the invite to join
this shared calendar. You can still choose to hide or remove the calendar
whenever you want.\n\nTo join shared calendar click
https://calendar.google.com/calendar/r?cid=ZGlzbmVpb3Bwb0BnbWFpbC5jb20&ctok=cmVwbHkrYXJtZHdjZ25ybmRrbW94aGlvbnJ6eXdibHo1dzVldmJuaGhlemE0NWZxQHJlcGx5LmdpdGh1Yi5jb20&es=3\n\nLearn
more about shared calendars by visiting
https://support.google.com/a/answer/1626902.
|
After dropping this as a comment here: w3c/webcrypto#73 (comment), I thought might be worth turning it into an example for the docs as well?
Feel free to update this (i've allowed edits by maintainers to the branch in my fork).