27
27
github: "https://github.com/w3c/webcrypto",
28
28
shortName: "WebCryptoAPI",
29
29
group: "webappsec",
30
- xref: ['html', 'dom', 'webidl', 'infra', 'encoding'],
30
+ xref: ['html', 'dom', 'webidl', 'infra', 'encoding', 'streams' ],
31
31
localBiblio: {
32
32
"JWA": {
33
33
aliasOf: "RFC7518"
@@ -1220,6 +1220,19 @@ <h3>Serialization and deserialization steps</h3>
1220
1220
</section>
1221
1221
</section>
1222
1222
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
+
1223
1236
<section id="subtlecrypto-interface">
1224
1237
<h2>SubtleCrypto interface</h2>
1225
1238
<p>
@@ -1254,7 +1267,7 @@ <h2>SubtleCrypto interface</h2>
1254
1267
);
1255
1268
Promise<ArrayBuffer> digest(
1256
1269
AlgorithmIdentifier algorithm,
1257
- BufferSource data
1270
+ ( BufferSource or IterableOfBufferSources or AsyncIterableOfBufferSources) data
1258
1271
);
1259
1272
1260
1273
Promise<(CryptoKey or CryptoKeyPair)> generateKey(
@@ -1828,9 +1841,7 @@ <h4>The digest method</h4>
1828
1841
</li>
1829
1842
<li>
1830
1843
<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
1834
1845
{{SubtleCrypto/digest()}} method.
1835
1846
</p>
1836
1847
</li>
@@ -1858,6 +1869,112 @@ <h4>The digest method</h4>
1858
1869
Let |promise| be a new Promise.
1859
1870
</p>
1860
1871
</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>
1861
1978
<li>
1862
1979
<p>
1863
1980
Return |promise| and perform the remaining steps [= in parallel =].
@@ -1873,11 +1990,29 @@ <h4>The digest method</h4>
1873
1990
and then [= terminate the algorithm =].
1874
1991
</p>
1875
1992
</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>
1876
2011
<li>
1877
2012
<p>
1878
2013
Let |digest| be the result of performing the digest
1879
2014
operation specified by |normalizedAlgorithm| using
1880
- |algorithm|, with |data |
2015
+ |algorithm|, with |bytes |
1881
2016
as |message|.
1882
2017
</p>
1883
2018
</li>
0 commit comments