Skip to content

Commit 18c9819

Browse files
committed
Accept async_sequence<BufferSource> in crypto.subtle.digest
1 parent 37f41ce commit 18c9819

File tree

1 file changed

+173
-26
lines changed

1 file changed

+173
-26
lines changed

spec/Overview.html

Lines changed: 173 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ <h2>SubtleCrypto interface</h2>
12711271
);
12721272
Promise&lt;ArrayBuffer> digest(
12731273
AlgorithmIdentifier algorithm,
1274-
BufferSource data
1274+
(BufferSource or async_sequence&lt;BufferSource>) data
12751275
);
12761276

12771277
Promise&lt;(CryptoKey or CryptoKeyPair)> generateKey(
@@ -1845,9 +1845,7 @@ <h4>The digest method</h4>
18451845
</li>
18461846
<li>
18471847
<p>
1848-
Let |data| be the result of
1849-
[= get a copy of the buffer source |
1850-
getting a copy of the bytes held by =] the `data` parameter passed to the
1848+
Let |data| be the `data` parameter passed to the
18511849
{{SubtleCrypto/digest()}} method.
18521850
</p>
18531851
</li>
@@ -1865,6 +1863,133 @@ <h4>The digest method</h4>
18651863
|normalizedAlgorithm|.
18661864
</p>
18671865
</li>
1866+
<li>
1867+
<p>
1868+
Let |bytesPromise| be a new Promise.
1869+
</p>
1870+
</li>
1871+
<li>
1872+
<dl class="switch">
1873+
<dt>If |data| is a {{BufferSource}}:</dt>
1874+
<dd>
1875+
<ol>
1876+
<li>
1877+
<p>
1878+
Let |bytes| be the result of
1879+
[= get a copy of the buffer source |
1880+
getting a copy of the bytes held by =] |data|.
1881+
</p>
1882+
</li>
1883+
<li>
1884+
<p>
1885+
Resolve |bytesPromise| with |bytes|.
1886+
</p>
1887+
</li>
1888+
</dd>
1889+
<dt>
1890+
Otherwise:
1891+
</dt>
1892+
<dd>
1893+
<div class=note>
1894+
<p>
1895+
In this case, |data| is an [= async sequence type | async sequence =] of {{BufferSource}}s.
1896+
</p>
1897+
</div>
1898+
<ol>
1899+
<li>
1900+
<p>
1901+
Let |bytes| be an empty [= byte sequence =].
1902+
</p>
1903+
</li>
1904+
<li>
1905+
<p>
1906+
Let |iterator| be the result of [= open an async sequence | opening =] |data|.
1907+
</p>
1908+
</li>
1909+
<li>
1910+
<p>
1911+
If an error occurred, reject |bytesPromise| with
1912+
|iterator| and terminate these steps.
1913+
</p>
1914+
</li>
1915+
<li>
1916+
<p>
1917+
Let |getValueSteps| be the following list of steps:
1918+
</p>
1919+
<ol>
1920+
<li>
1921+
<p>
1922+
Let |next| be the result of [= get an async iterator next value | getting the next value =] of |iterator|.
1923+
</p>
1924+
</li>
1925+
<li>
1926+
<p>
1927+
[= promise/React =] to |next|:
1928+
</p>
1929+
<dl class="switch">
1930+
<dt>If |next| was rejected with |reason|:</dt>
1931+
<dd>
1932+
<ol>
1933+
<li>
1934+
<p>
1935+
Reject |bytesPromise| with |reason|.
1936+
</p>
1937+
</li>
1938+
</ol>
1939+
</dd>
1940+
<dt>If |next| was fulfilled with |value|:</dt>
1941+
<dd>
1942+
<ol>
1943+
<li>
1944+
<p>
1945+
If |value| is [= end of iteration =],
1946+
resolve |bytesPromise| with |bytes|
1947+
and terminate these steps.
1948+
</p>
1949+
</li>
1950+
<li>
1951+
<p>
1952+
Append the result of [= get a copy of the buffer source |
1953+
getting a copy of the bytes held by =] |value|
1954+
to |bytes|.
1955+
</p>
1956+
</li>
1957+
<li>
1958+
<p>
1959+
Perform |getValueSteps|.
1960+
</p>
1961+
</li>
1962+
</ol>
1963+
</dd>
1964+
</dl>
1965+
</li>
1966+
</ol>
1967+
</li>
1968+
<li>
1969+
<p>
1970+
[= Queue a microtask =] to perform |getValueSteps|.
1971+
</p>
1972+
</li>
1973+
</ol>
1974+
<div class=note>
1975+
<p>
1976+
The implementation may wish to compute the hash digest
1977+
incrementally, instead of waiting until all data is
1978+
available, in order to conserve memory.
1979+
</p>
1980+
<p>
1981+
Additionally, if the |iterator| returned by
1982+
[= open an async sequence | opening =] |data|
1983+
is the iterator defined by <a data-cite="streams#readablestream">`ReadableStream`</a>,
1984+
the implementation may wish to optimize the steps
1985+
above, for example by reading the stream directly,
1986+
and/or <a data-cite="streams#transferrable-streams">transferring</a>
1987+
the stream to the [= in parallel | parallel =] steps below.
1988+
</p>
1989+
</div>
1990+
</dd>
1991+
</dl>
1992+
</li>
18681993
<li>
18691994
<p>
18701995
Let |realm| be the [= relevant realm =] of [= this =].
@@ -1892,29 +2017,51 @@ <h4>The digest method</h4>
18922017
</li>
18932018
<li>
18942019
<p>
1895-
Let |digest| be the result of performing the digest
1896-
operation specified by |normalizedAlgorithm| using
1897-
|algorithm|, with |data|
1898-
as |message|.
1899-
</p>
1900-
</li>
1901-
<li>
1902-
<p>
1903-
[= Queue a global task =] on the [= crypto task source =],
1904-
given |realm|'s global object, to perform the remaining steps.
1905-
</p>
1906-
</li>
1907-
<li>
1908-
<p>
1909-
Let |result| be the result of [= ArrayBuffer/create | creating =] an {{ArrayBuffer}}
1910-
in |realm|, containing |digest|.
1911-
</p>
1912-
</li>
1913-
<li>
1914-
<p>
1915-
Resolve |promise| with
1916-
|result|.
2020+
[= promise/React =] to |bytesPromise|:
19172021
</p>
2022+
<dl class="switch">
2023+
<dt>If |bytesPromise| was rejected with |reason|:</dt>
2024+
<dd>
2025+
<ol>
2026+
<li>
2027+
<p>
2028+
[= exception/Throw =] |reason|.
2029+
</p>
2030+
</li>
2031+
</ol>
2032+
</dd>
2033+
<dt>If |bytesPromise| was fulfilled with value |bytes|:</dt>
2034+
<dd>
2035+
<ol>
2036+
<li>
2037+
<p>
2038+
Let |digest| be the result of performing the digest
2039+
operation specified by |normalizedAlgorithm| using
2040+
|algorithm|, with |bytes|
2041+
as |message|.
2042+
</p>
2043+
</li>
2044+
<li>
2045+
<p>
2046+
[= Queue a global task =] on the [= crypto task source =],
2047+
given |realm|'s global object, to perform the remaining steps.
2048+
</p>
2049+
</li>
2050+
<li>
2051+
<p>
2052+
Let |result| be the result of [= ArrayBuffer/create | creating =] an {{ArrayBuffer}}
2053+
in |realm|, containing |digest|.
2054+
</p>
2055+
</li>
2056+
<li>
2057+
<p>
2058+
Resolve |promise| with
2059+
|result|.
2060+
</p>
2061+
</li>
2062+
</ol>
2063+
</dd>
2064+
</dl>
19182065
</li>
19192066
</ol>
19202067
</section>

0 commit comments

Comments
 (0)