Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c011038
webcrypto: match Node v26.3.0 error semantics and KeyUsage ordering
cirospaciari Jul 17, 2026
0100ab7
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 17, 2026
0ac6582
webcrypto: report Node's import and derive errors, drop the non-stand…
cirospaciari Jul 17, 2026
19a7b0d
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 17, 2026
18aadc0
test(fetch): fill body fixtures through a Uint8Array view
cirospaciari Jul 17, 2026
facf342
wasi: random_get should fill the requested window, not all of linear …
cirospaciari Jul 17, 2026
2ec69d0
wasi: random_get returns WASI_ESUCCESS, not bufLen
robobun Jul 17, 2026
968a771
Merge remote-tracking branch 'origin/main' into claude/webcrypto-node…
robobun Jul 17, 2026
31add41
style: trim two new comments to 3 lines
robobun Jul 17, 2026
2a5f4d7
webcrypto: check the throw scope after normalizeCryptoAlgorithmParame…
robobun Jun 28, 2026
a6ce715
webcrypto: hold a RefPtr across remove-then-reject in the wrapKey cal…
robobun Jun 28, 2026
39645f9
test: trim exception-scope describe comment to 3 lines
robobun Jul 17, 2026
cd10a4a
webcrypto: report key-type mismatch for OKP cross-curve imports
robobun Jul 17, 2026
22ec506
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 17, 2026
f2d7540
webcrypto: carry Node's empty-usages message to sibling sites, report…
robobun Jul 17, 2026
5e68bc0
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 17, 2026
4082e03
webcrypto: carry ECDH's 'key algorithm mismatch' to X25519 deriveBits
robobun Jul 17, 2026
a5e6385
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 17, 2026
9cb0754
webcrypto: carry 'Unsupported key usage' to RSA importKey, fix RSAES …
robobun Jul 17, 2026
066c563
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 17, 2026
781f06f
webcrypto: use 'an' before ECDSA/ECDH/Ed25519/X25519 in usage messages
robobun Jul 17, 2026
e239db7
webcrypto: add ChaCha20-Poly1305 and the raw-secret key format
cirospaciari Jul 20, 2026
a0e449c
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 20, 2026
06eb822
webcrypto: vendor test-webcrypto-cryptokey-hidden-slots from Node v26…
cirospaciari Jul 18, 2026
ad82e7a
test: quarantine worker-terminate ASAN crashes, matching main
cirospaciari Jul 20, 2026
cd20e69
test: widen mimalloc page-count bound for JSC heap noise, matching main
cirospaciari Jul 20, 2026
a47bc95
webcrypto: add ML-DSA and ML-KEM, the v26 SubtleCrypto surface, and K…
cirospaciari Jul 21, 2026
62fb33f
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 21, 2026
1cde5be
crypto: avoid bssl::ScopedCBB in marshalAsymmetricKey
cirospaciari Jul 21, 2026
ba2e030
crypto: replace remaining bssl::ScopedCBB uses with a shared marshal …
cirospaciari Jul 21, 2026
33d186e
Merge remote-tracking branch 'origin/main' into wt-conflicts-34838
cirospaciari Jul 21, 2026
722e53a
webcrypto: address review findings across the ChaCha20-Poly1305 and A…
cirospaciari Jul 22, 2026
72f1824
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 22, 2026
897b1aa
webcrypto: drain the AKP error queue in unwrapKey's inner import; mak…
cirospaciari Jul 23, 2026
167c012
webcrypto: dedupe the AKP import/export flows and finish the review r…
cirospaciari Jul 23, 2026
13e9164
webcrypto: share the usage-bitmap mapping with KeyObject; cover every…
cirospaciari Jul 23, 2026
5ce0b8c
webcrypto: test structuredClone DataCloneError and encapsulate result…
cirospaciari Jul 23, 2026
0754ddb
webcrypto: clone-guard test also covers ML-KEM keys
cirospaciari Jul 23, 2026
8c0eca6
webcrypto: node's type error for object keyData; coerce format once
cirospaciari Jul 23, 2026
5a38a32
webcrypto: single-pass HMAC JWK validation with node's member errors
cirospaciari Jul 23, 2026
78d9af6
webcrypto: drop the null-alg arms from the HMAC alg matcher
cirospaciari Jul 23, 2026
18d22af
webcrypto: order wrapKey's extractable check first; node's raw-import…
cirospaciari Jul 23, 2026
2a6b128
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 23, 2026
0447528
webcrypto: reject duplicate JWK key_ops for ChaCha20 and HMAC
cirospaciari Jul 23, 2026
031b0e2
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 23, 2026
7d33045
webcrypto: pick the importKey keyData converter by format
cirospaciari Jul 23, 2026
2bd652e
webcrypto: structured clone for ChaCha20-Poly1305 and ML-DSA/ML-KEM keys
cirospaciari Jul 23, 2026
731b81c
webcrypto: clear the BoringSSL queue when deserializing a corrupt AKP…
cirospaciari Jul 23, 2026
d894781
webcrypto: pin the undersized-decrypt message for AES-GCM too
cirospaciari Jul 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/js/node/wasi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1847,8 +1847,11 @@ var require_wasi = __commonJS({
},
random_get: (bufPtr, bufLen) => {
this.refreshMemory();
crypto.getRandomValues(this.memory.buffer, bufPtr, bufLen);
return bufLen;
// getRandomValues takes one integer-typed view and ignores any further
// arguments, so a bare `buffer, bufPtr, bufLen` randomized all of linear
// memory rather than the requested window.
crypto.getRandomValues(new Uint8Array(this.memory.buffer, bufPtr, bufLen));
return constants_1.WASI_ESUCCESS;
},
sched_yield() {
return constants_1.WASI_ESUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/jsc/BuildMessage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Default for BuildMessage {
impl BuildMessage {
// `#[JsClass]` emits `BuildMessageClass__construct` calling this.
pub fn constructor(global: &JSGlobalObject, _frame: &CallFrame) -> JsResult<*mut BuildMessage> {
Err(global.throw_illegal_constructor("BuildMessage"))
Err(global.throw_illegal_constructor())
}

#[crate::host_fn(getter)]
Expand Down
9 changes: 4 additions & 5 deletions src/jsc/JSGlobalObject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,20 @@ impl JSGlobalObject {
self.throw_value(err)
}

/// Throw `TypeError: <name> is not constructable` with
/// Throw `TypeError: Illegal constructor` with
/// `.code = "ERR_ILLEGAL_CONSTRUCTOR"`.
///
/// Canonical body for hand-written `pub fn constructor` stubs whose
/// `.classes.ts` entry has `construct: true` but the class is not
/// user-instantiable. Matches the C++ default
/// (`JSDOMConstructorNotConstructable`, ErrorCode.cpp:2428) and Node.js.
/// (`JSDOMConstructorNotConstructable`) and Node.js.
///
/// NOTE: do NOT add a stub that calls this when `.classes.ts` declares
/// `noConstructor: true` / `construct: false` — codegen omits the
/// `${T}Class__construct` thunk entirely, so the stub would be dead code.
#[cold]
pub fn throw_illegal_constructor(&self, name: &str) -> JsError {
crate::ErrorCode::ILLEGAL_CONSTRUCTOR
.throw(self, format_args!("{name} is not constructable"))
pub fn throw_illegal_constructor(&self) -> JsError {
crate::ErrorCode::ILLEGAL_CONSTRUCTOR.throw(self, format_args!("Illegal constructor"))
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/jsc/ResolveMessage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl ResolveMessage {
global: &JSGlobalObject,
_frame: &CallFrame,
) -> JsResult<*mut ResolveMessage> {
Err(global.throw_illegal_constructor("ResolveMessage"))
Err(global.throw_illegal_constructor())
}

#[crate::host_fn(getter)]
Expand Down
1 change: 1 addition & 0 deletions src/jsc/bindings/AsymmetricKeyValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ AsymmetricKeyValue::AsymmetricKeyValue(WebCore::CryptoKey& cryptoKey)
case CryptoAlgorithmIdentifier::SHA3_512:
case CryptoAlgorithmIdentifier::HKDF:
case CryptoAlgorithmIdentifier::PBKDF2:
case CryptoAlgorithmIdentifier::ChaCha20_Poly1305:
case CryptoAlgorithmIdentifier::None:
key = nullptr;
break;
Expand Down
10 changes: 9 additions & 1 deletion src/jsc/bindings/JSDOMExceptionHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,15 @@ void throwAttributeTypeError(JSC::JSGlobalObject& lexicalGlobalObject, JSC::Thro

JSC::EncodedJSValue throwRequiredMemberTypeError(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, ASCIILiteral memberName, ASCIILiteral dictionaryName, ASCIILiteral expectedType)
{
return Bun::throwError(&lexicalGlobalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, makeString("Member "_s, dictionaryName, '.', memberName, " is required and must be an instance of "_s, expectedType));
// Only reached when a required member is absent, which Node reports as
// ERR_MISSING_OPTION; a member that is present but ill-typed throws from the
// converter with ERR_INVALID_ARG_TYPE instead.
return Bun::throwError(&lexicalGlobalObject, scope, Bun::ErrorCode::ERR_MISSING_OPTION, makeString("Member "_s, dictionaryName, '.', memberName, " is required and must be an instance of "_s, expectedType));
}

JSC::EncodedJSValue throwDictionaryMemberTypeError(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, ASCIILiteral memberName, ASCIILiteral dictionaryName, ASCIILiteral expectedType)
{
return Bun::throwError(&lexicalGlobalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE, makeString("Member "_s, dictionaryName, '.', memberName, " must be an instance of "_s, expectedType));
}

JSC::EncodedJSValue throwConstructorScriptExecutionContextUnavailableError(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, ASCIILiteral interfaceName)
Expand Down
1 change: 1 addition & 0 deletions src/jsc/bindings/JSDOMExceptionHandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ WEBCORE_EXPORT JSC::EncodedJSValue throwArgumentMustBeFunctionError(JSC::JSGloba
WEBCORE_EXPORT JSC::EncodedJSValue throwArgumentMustBeObjectError(JSC::JSGlobalObject&, JSC::ThrowScope&, unsigned argumentIndex, ASCIILiteral argumentName, ASCIILiteral functionInterfaceName, ASCIILiteral functionName);
WEBCORE_EXPORT JSC::EncodedJSValue throwArgumentTypeError(JSC::JSGlobalObject&, JSC::ThrowScope&, unsigned argumentIndex, ASCIILiteral argumentName, ASCIILiteral functionInterfaceName, ASCIILiteral functionName, ASCIILiteral expectedType);
WEBCORE_EXPORT JSC::EncodedJSValue throwRequiredMemberTypeError(JSC::JSGlobalObject&, JSC::ThrowScope&, ASCIILiteral memberName, ASCIILiteral dictionaryName, ASCIILiteral expectedType);
WEBCORE_EXPORT JSC::EncodedJSValue throwDictionaryMemberTypeError(JSC::JSGlobalObject&, JSC::ThrowScope&, ASCIILiteral memberName, ASCIILiteral dictionaryName, ASCIILiteral expectedType);
JSC::EncodedJSValue throwConstructorScriptExecutionContextUnavailableError(JSC::JSGlobalObject&, JSC::ThrowScope&, ASCIILiteral interfaceName);

String makeThisTypeErrorMessage(ASCIILiteral interfaceName, ASCIILiteral functionName);
Expand Down
16 changes: 16 additions & 0 deletions src/jsc/bindings/webcore/JSDOMConstructorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ JSC_DEFINE_HOST_FUNCTION(callThrowTypeErrorForJSDOMConstructor, (JSGlobalObject
return {};
}

JSC_DEFINE_HOST_FUNCTION(throwTypeErrorForJSDOMConstructorNotConstructable, (JSGlobalObject * globalObject, CallFrame* callframe))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto* callee = callframe->jsCallee();
auto* constructor = dynamicDowncast<JSDOMConstructorBase>(callee);
// The message belongs to the error code: interfaces opting into a non-default
// code (MessagePort -> ERR_CONSTRUCT_CALL_INVALID) carry Node's wording for it.
auto errorCode = constructor->errorCode();
auto message = errorCode == Bun::ErrorCode::ERR_CONSTRUCT_CALL_INVALID
? "Constructor cannot be called"_s
: "Illegal constructor"_s;
Bun::throwError(globalObject, scope, errorCode, message);
return {};
}

JSC::GCClient::IsoSubspace* JSDOMConstructorBase::subspaceForImpl(JSC::VM& vm)
{
return &static_cast<JSVMClientData*>(vm.clientData)->domConstructorSpace();
Expand Down
4 changes: 4 additions & 0 deletions src/jsc/bindings/webcore/JSDOMConstructorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
namespace WebCore {

JSC_DECLARE_HOST_FUNCTION(callThrowTypeErrorForJSDOMConstructor);
// Interfaces that cannot be constructed at all report "Illegal constructor" for
// both call and construct; the message above only makes sense for a constructable
// interface invoked without `new`.
JSC_DECLARE_HOST_FUNCTION(throwTypeErrorForJSDOMConstructorNotConstructable);

// Base class for all callable constructor objects in the JSC bindings.
class JSDOMConstructorBase : public JSC::InternalFunction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class JSDOMConstructorNotConstructable final : public JSDOMConstructorBase {

private:
JSDOMConstructorNotConstructable(JSC::VM& vm, JSC::Structure* structure)
: Base(vm, structure, nullptr, nullptr, templateErrorCode)
: Base(vm, structure, throwTypeErrorForJSDOMConstructorNotConstructable, throwTypeErrorForJSDOMConstructorNotConstructable, templateErrorCode)
{
}

Expand Down
1 change: 1 addition & 0 deletions src/jsc/bindings/webcore/SerializedScriptValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2547,9 +2547,10 @@
case CryptoAlgorithmIdentifier::X25519:
write(CryptoAlgorithmIdentifierTag::X25519);
break;
case CryptoAlgorithmIdentifier::ChaCha20_Poly1305:
case CryptoAlgorithmIdentifier::None: {
RELEASE_ASSERT_NOT_REACHED();
break;

Check failure on line 2553 in src/jsc/bindings/webcore/SerializedScriptValue.cpp

View check run for this annotation

Claude / Claude Code Review

structuredClone on ChaCha20-Poly1305 CryptoKey aborts the process

`structuredClone()` or `worker.postMessage()` on a ChaCha20-Poly1305 `CryptoKey` aborts the process: the key is a `CryptoKeyRaw`, so the `CryptoKeyClass::Raw` serialize arm (line 2664) calls `write(key->algorithmIdentifier())`, which now hits this `RELEASE_ASSERT_NOT_REACHED()`. It needs its own `CryptoAlgorithmIdentifierTag` (write + read case) like HKDF/PBKDF2 have — and note `readRawKey` (line 4322) also needs to receive/pass `extractable` to `CryptoKeyRaw::create`, or an extractable ChaCha20
Comment thread
claude[bot] marked this conversation as resolved.
Resolved
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/jsc/bindings/webcore/streams/WebStreamsInspectCustom.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// WebStreamsInspectCustom.h — the one shared helper every Web Streams prototype's
// [Symbol.for("nodejs.util.inspect.custom")] host function routes through, so
// `console.log(stream)` matches Node's output shape: `ClassName { field: value, ... }`.
// The shared helper a prototype's [Symbol.for("nodejs.util.inspect.custom")] routes
// through so `console.log(x)` matches Node's `ClassName { field: value, ... }` shape.
// Named for its Web Streams origin; CryptoKey uses it too.
#pragma once

#include "root.h"
Expand Down
35 changes: 35 additions & 0 deletions src/jsc/bindings/webcrypto/AeadParams.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Copyright (C) 2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

[
Conditional=WEB_CRYPTO,
ImplementedAs=CryptoAlgorithmAeadParams
] dictionary AeadParams : CryptoAlgorithmParameters {
// The initialization vector to use. May be up to 2^64-1 bytes long.
required BufferSource iv;
// The additional authentication data to include.
BufferSource additionalData;
// The desired length of the authentication tag. May be 0 - 128.
[EnforceRange] octet tagLength;
};
2 changes: 2 additions & 0 deletions src/jsc/bindings/webcrypto/CryptoAlgorithmAES_CBC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void CryptoAlgorithmAES_CBC::importKey(CryptoKeyFormat format, KeyData&& data, c

RefPtr<CryptoKeyAES> result;
switch (format) {
case CryptoKeyFormat::RawSecret:
case CryptoKeyFormat::Raw:
result = CryptoKeyAES::importRaw(parameters.identifier, WTF::move(std::get<Vector<uint8_t>>(data)), extractable, usages);
break;
Expand Down Expand Up @@ -160,6 +161,7 @@ void CryptoAlgorithmAES_CBC::exportKey(CryptoKeyFormat format, Ref<CryptoKey>&&

KeyData result;
switch (format) {
case CryptoKeyFormat::RawSecret:
case CryptoKeyFormat::Raw:
result = Vector<uint8_t>(aesKey.key());
break;
Expand Down
2 changes: 2 additions & 0 deletions src/jsc/bindings/webcrypto/CryptoAlgorithmAES_CFB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void CryptoAlgorithmAES_CFB::importKey(CryptoKeyFormat format, KeyData&& data, c

RefPtr<CryptoKeyAES> result;
switch (format) {
case CryptoKeyFormat::RawSecret:
case CryptoKeyFormat::Raw:
result = CryptoKeyAES::importRaw(parameters.identifier, WTF::move(std::get<Vector<uint8_t>>(data)), extractable, usages);
break;
Expand Down Expand Up @@ -160,6 +161,7 @@ void CryptoAlgorithmAES_CFB::exportKey(CryptoKeyFormat format, Ref<CryptoKey>&&

KeyData result;
switch (format) {
case CryptoKeyFormat::RawSecret:
case CryptoKeyFormat::Raw:
result = Vector<uint8_t>(aesKey.key());
break;
Expand Down
2 changes: 2 additions & 0 deletions src/jsc/bindings/webcrypto/CryptoAlgorithmAES_CTR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void CryptoAlgorithmAES_CTR::importKey(CryptoKeyFormat format, KeyData&& data, c

RefPtr<CryptoKeyAES> result;
switch (format) {
case CryptoKeyFormat::RawSecret:
case CryptoKeyFormat::Raw:
result = CryptoKeyAES::importRaw(parameters.identifier, WTF::move(std::get<Vector<uint8_t>>(data)), extractable, usages);
break;
Expand Down Expand Up @@ -169,6 +170,7 @@ void CryptoAlgorithmAES_CTR::exportKey(CryptoKeyFormat format, Ref<CryptoKey>&&

KeyData result;
switch (format) {
case CryptoKeyFormat::RawSecret:
case CryptoKeyFormat::Raw:
result = Vector<uint8_t>(aesKey.key());
break;
Expand Down
2 changes: 2 additions & 0 deletions src/jsc/bindings/webcrypto/CryptoAlgorithmAES_GCM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ void CryptoAlgorithmAES_GCM::importKey(CryptoKeyFormat format, KeyData&& data, c

RefPtr<CryptoKeyAES> result;
switch (format) {
case CryptoKeyFormat::RawSecret:
case CryptoKeyFormat::Raw:
result = CryptoKeyAES::importRaw(parameters.identifier, WTF::move(std::get<Vector<uint8_t>>(data)), extractable, usages);
break;
Expand Down Expand Up @@ -208,6 +209,7 @@ void CryptoAlgorithmAES_GCM::exportKey(CryptoKeyFormat format, Ref<CryptoKey>&&

KeyData result;
switch (format) {
case CryptoKeyFormat::RawSecret:
case CryptoKeyFormat::Raw:
result = Vector<uint8_t>(aesKey.key());
break;
Expand Down
2 changes: 2 additions & 0 deletions src/jsc/bindings/webcrypto/CryptoAlgorithmAES_KW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void CryptoAlgorithmAES_KW::importKey(CryptoKeyFormat format, KeyData&& data, co

RefPtr<CryptoKeyAES> result;
switch (format) {
case CryptoKeyFormat::RawSecret:
case CryptoKeyFormat::Raw:
result = CryptoKeyAES::importRaw(parameters.identifier, WTF::move(std::get<Vector<uint8_t>>(data)), extractable, usages);
break;
Expand Down Expand Up @@ -123,6 +124,7 @@ void CryptoAlgorithmAES_KW::exportKey(CryptoKeyFormat format, Ref<CryptoKey>&& k

KeyData result;
switch (format) {
case CryptoKeyFormat::RawSecret:
case CryptoKeyFormat::Raw:
result = Vector<uint8_t>(aesKey.key());
break;
Expand Down
88 changes: 88 additions & 0 deletions src/jsc/bindings/webcrypto/CryptoAlgorithmAeadParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "BufferSource.h"
#include "CryptoAlgorithmParameters.h"
#include <wtf/Vector.h>

#if ENABLE(WEB_CRYPTO)

namespace WebCore {

class CryptoAlgorithmAeadParams final : public CryptoAlgorithmParameters {
public:
BufferSource iv;
// Use additionalDataVector() instead of additionalData. The label will be gone once additionalDataVector() is called.
mutable std::optional<BufferSource::VariantType> additionalData;
mutable std::optional<uint8_t> tagLength;

Class parametersClass() const final { return Class::AeadParams; }

const Vector<uint8_t>& ivVector() const
{
if (!m_ivVector.isEmpty() || !iv.length())
return m_ivVector;

m_ivVector.append(std::span { iv.data(), iv.length() });
return m_ivVector;
}

const Vector<uint8_t>& additionalDataVector() const
{
if (!m_additionalDataVector.isEmpty() || !additionalData)
return m_additionalDataVector;

BufferSource additionalDataBuffer = WTF::move(*additionalData);
additionalData = std::nullopt;
if (!additionalDataBuffer.length())
return m_additionalDataVector;

m_additionalDataVector.append(std::span { additionalDataBuffer.data(), additionalDataBuffer.length() });
return m_additionalDataVector;
}

CryptoAlgorithmAeadParams isolatedCopy() const
{
CryptoAlgorithmAeadParams result;
result.identifier = identifier;
result.m_ivVector = ivVector();
result.m_additionalDataVector = additionalDataVector();
result.tagLength = tagLength;

return result;
}

private:
mutable Vector<uint8_t> m_ivVector;
mutable Vector<uint8_t> m_additionalDataVector;
};

} // namespace WebCore

SPECIALIZE_TYPE_TRAITS_CRYPTO_ALGORITHM_PARAMETERS(AeadParams)

#endif // ENABLE(WEB_CRYPTO)
Loading
Loading