Skip to content

Commit d124b53

Browse files
committed
Accept (async) iterables in crypto.subtle.digest
1 parent 0ac8c1b commit d124b53

File tree

1 file changed

+141
-6
lines changed

1 file changed

+141
-6
lines changed

spec/Overview.html

Lines changed: 141 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
github: "https://github.com/w3c/webcrypto",
2828
shortName: "WebCryptoAPI",
2929
group: "webappsec",
30-
xref: ['html', 'dom', 'webidl', 'infra', 'encoding'],
30+
xref: ['html', 'dom', 'webidl', 'infra', 'encoding', 'streams'],
3131
localBiblio: {
3232
"JWA": {
3333
aliasOf: "RFC7518"
@@ -1220,6 +1220,19 @@ <h3>Serialization and deserialization steps</h3>
12201220
</section>
12211221
</section>
12221222

1223+
<section id="iterable-interfaces">
1224+
<h2>Iterable interfaces</h2>
1225+
<p>
1226+
The <dfn id="dfn-IterableOfBufferSources">IterableOfBufferSources</dfn> type represents objects that conform to the <a data-cite="ECMAScript/control-abstraction-objects.html#sec-iterable-interface">iterable interface</a>, and produce {{BufferSource}} values when iterated over.
1227+
The <dfn id="dfn-AsyncIterableOfBufferSources">AsyncIterableOfBufferSources</dfn> type represents objects that conform to the <a data-cite="ECMAScript/control-abstraction-objects.html#sec-asynciterable-interface">async iterable interface</a>, and produce {{BufferSource}} values when asynchronously iterated over.
1228+
This is checked by the calling functions rather than by Web IDL.
1229+
</p>
1230+
<pre class=idl>
1231+
typedef object IterableOfBufferSources;
1232+
typedef object AsyncIterableOfBufferSources;
1233+
</pre>
1234+
</section>
1235+
12231236
<section id="subtlecrypto-interface">
12241237
<h2>SubtleCrypto interface</h2>
12251238
<p>
@@ -1254,7 +1267,7 @@ <h2>SubtleCrypto interface</h2>
12541267
);
12551268
Promise&lt;ArrayBuffer> digest(
12561269
AlgorithmIdentifier algorithm,
1257-
BufferSource data
1270+
(BufferSource or IterableOfBufferSources or AsyncIterableOfBufferSources) data
12581271
);
12591272

12601273
Promise&lt;(CryptoKey or CryptoKeyPair)> generateKey(
@@ -1828,9 +1841,7 @@ <h4>The digest method</h4>
18281841
</li>
18291842
<li>
18301843
<p>
1831-
Let |data| be the result of
1832-
[= get a copy of the buffer source |
1833-
getting a copy of the bytes held by =] the `data` parameter passed to the
1844+
Let |data| be the `data` parameter passed to the
18341845
{{SubtleCrypto/digest()}} method.
18351846
</p>
18361847
</li>
@@ -1858,6 +1869,112 @@ <h4>The digest method</h4>
18581869
Let |promise| be a new Promise.
18591870
</p>
18601871
</li>
1872+
<li>
1873+
<dl class="switch">
1874+
<dt>If |data| is a {{BufferSource}}:</dt>
1875+
<dd>
1876+
<p>
1877+
Let |bytes| be the result of
1878+
[= get a copy of the buffer source |
1879+
getting a copy of the bytes held by =] |data|.
1880+
</p>
1881+
</dd>
1882+
<dt>
1883+
Otherwise, if |data| conforms to the
1884+
<a data-cite="ECMAScript/control-abstraction-objects.html#sec-iterable-interface">iterable interface</a> or
1885+
<a data-cite="ECMAScript/control-abstraction-objects.html#sec-asynciterable-interface">async iterable interface</a>:
1886+
</dt>
1887+
<dd>
1888+
<ol>
1889+
<li>
1890+
<p>
1891+
Let |bytes| be an empty [= byte sequence =].
1892+
</p>
1893+
</li>
1894+
<li>
1895+
<p>
1896+
Let |iterator| be the result of calling
1897+
<code><a data-cite="ECMAScript/abstract-operations.html#sec-getiterator">GetIterator</a>(|data|, ASYNC)</code>.
1898+
</p>
1899+
</li>
1900+
<li>
1901+
<p>
1902+
If an error occurred, return a Promise rejected with
1903+
|iterator|.
1904+
</p>
1905+
</li>
1906+
<li>
1907+
<p>
1908+
[= Queue a microtask =] to perform the remaining steps.
1909+
</p>
1910+
</li>
1911+
<li>
1912+
<p>
1913+
While <code>|iterator|.[[\Done]]</code> is false:
1914+
</p>
1915+
<ol>
1916+
<li>
1917+
<p>
1918+
Let |value| be the result of calling
1919+
<code><a data-cite="ECMAScript/abstract-operations.html#sec-iteratorstepvalue">IteratorStepValue</a>(|iterator|)</code>.
1920+
</p>
1921+
</li>
1922+
<li>
1923+
<p>
1924+
If an error occurred, reject |promise| with
1925+
|value| and then terminate these steps.
1926+
</p>
1927+
</li>
1928+
<li>
1929+
<p>
1930+
Let |value| be the result of calling
1931+
<code><a data-cite="ECMAScript/control-abstraction-objects.html#await">Await</a>(|value|)</code>.
1932+
</p>
1933+
</li>
1934+
<li>
1935+
<p>
1936+
If an error occurred, reject |promise| with
1937+
|value| and then terminate these steps.
1938+
</p>
1939+
</li>
1940+
<li>
1941+
<p>
1942+
If |value| is not a {{BufferSource}},
1943+
reject |promise| with the result of calling
1944+
<code><a data-cite="ECMAScript/abstract-operations.html#sec-asynciteratorclose">AsyncIteratorClose</a></code>
1945+
with |iterator| and a {{TypeError}},
1946+
and then terminate these steps.
1947+
</p>
1948+
</li>
1949+
<li>
1950+
<p>
1951+
Append the result of [= get a copy of the buffer source |
1952+
getting a copy of the bytes held by =] |value|
1953+
to |bytes|.
1954+
</p>
1955+
</li>
1956+
</ol>
1957+
</li>
1958+
</ol>
1959+
<div class=note>
1960+
<p>
1961+
If the |iterator| returned by <code>GetIterator(|data|, ASYNC)</code>
1962+
is the iterator defined by {{ReadableStream}},
1963+
the implementation may wish to optimize the steps
1964+
above, for example by reading the stream directly,
1965+
and/or <a data-cite="streams#transferrable-streams">transferring</a>
1966+
the stream to the [= in parallel | parallel =] steps below.
1967+
</p>
1968+
</div>
1969+
</dd>
1970+
<dt>Otherwise:</dt>
1971+
<dd>
1972+
<p>
1973+
Return a Promise rejected with a {{TypeError}}.
1974+
</p>
1975+
</dd>
1976+
</dl>
1977+
</li>
18611978
<li>
18621979
<p>
18631980
Return |promise| and perform the remaining steps [= in parallel =].
@@ -1873,11 +1990,29 @@ <h4>The digest method</h4>
18731990
and then [= terminate the algorithm =].
18741991
</p>
18751992
</li>
1993+
<li>
1994+
<p>
1995+
Wait until the microtask queued above (if any) completes.
1996+
</p>
1997+
<div class=note>
1998+
<p>
1999+
The implementation may wish to compute the hash digest
2000+
incrementally, instead of waiting until all data is
2001+
available, in order to conserve memory.
2002+
</p>
2003+
</div>
2004+
</li>
2005+
<li>
2006+
<p>
2007+
If |promise| was rejected with an error,
2008+
[= terminate the algorithm =].
2009+
</p>
2010+
</li>
18762011
<li>
18772012
<p>
18782013
Let |digest| be the result of performing the digest
18792014
operation specified by |normalizedAlgorithm| using
1880-
|algorithm|, with |data|
2015+
|algorithm|, with |bytes|
18812016
as |message|.
18822017
</p>
18832018
</li>

0 commit comments

Comments
 (0)