Skip to content

Commit

Permalink
Update toBufferSource() to take in a std::span
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271356

Reviewed by Darin Adler.

* Source/WebCore/bindings/js/BufferSource.h:
(WebCore::toBufferSource):
* Tools/TestWebKitAPI/Tests/WebCore/CtapRequestTest.cpp:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WebCore/U2fCommandConstructorTest.cpp:
(TestWebKitAPI::constructMakeCredentialRequest):
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/276480@main
  • Loading branch information
cdumez committed Mar 21, 2024
1 parent c448798 commit 893e0c7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Source/WebCore/bindings/js/BufferSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class BufferSource {
VariantType m_variant;
};

inline BufferSource toBufferSource(const uint8_t* data, size_t length)
inline BufferSource toBufferSource(std::span<const uint8_t> data)
{
return BufferSource(JSC::ArrayBuffer::tryCreate(data, length));
return BufferSource(JSC::ArrayBuffer::tryCreate(data));
}

#if PLATFORM(COCOA) && defined(__OBJC__)
Expand Down
48 changes: 24 additions & 24 deletions Tools/TestWebKitAPI/Tests/WebCore/CtapRequestTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ TEST(CTAPRequestTest, TestConstructMakeCredentialRequestParam)
PublicKeyCredentialCreationOptions::UserEntity user;
user.name = "johnpsmith@example.com"_s;
user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png"_s;
user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
user.id = WebCore::toBufferSource(TestData::kUserId);
user.displayName = "John P. Smith"_s;

Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
Expand All @@ -80,7 +80,7 @@ TEST(CTAPRequestTest, TestConstructMakeCredentialRequestParamNoUVNoRK)
PublicKeyCredentialCreationOptions::UserEntity user;
user.name = "johnpsmith@example.com"_s;
user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png"_s;
user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
user.id = WebCore::toBufferSource(TestData::kUserId);
user.displayName = "John P. Smith"_s;

Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
Expand All @@ -104,7 +104,7 @@ TEST(CTAPRequestTest, TestConstructMakeCredentialRequestParamUVRequiredButNotSup
PublicKeyCredentialCreationOptions::UserEntity user;
user.name = "johnpsmith@example.com"_s;
user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png"_s;
user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
user.id = WebCore::toBufferSource(TestData::kUserId);
user.displayName = "John P. Smith"_s;

Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
Expand All @@ -128,7 +128,7 @@ TEST(CTAPRequestTest, TestConstructMakeCredentialRequestParamWithPin)
PublicKeyCredentialCreationOptions::UserEntity user;
user.name = "johnpsmith@example.com"_s;
user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png"_s;
user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
user.id = WebCore::toBufferSource(TestData::kUserId);
user.displayName = "John P. Smith"_s;

Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
Expand Down Expand Up @@ -156,7 +156,7 @@ TEST(CTAPRequestTest, TestConstructMakeCredentialRequestRKPreferred)
PublicKeyCredentialCreationOptions::UserEntity user;
user.name = "johnpsmith@example.com"_s;
user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png"_s;
user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
user.id = WebCore::toBufferSource(TestData::kUserId);
user.displayName = "John P. Smith"_s;

Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
Expand Down Expand Up @@ -184,7 +184,7 @@ TEST(CTAPRequestTest, TestConstructMakeCredentialRequestRKPreferredNotSupported)
PublicKeyCredentialCreationOptions::UserEntity user;
user.name = "johnpsmith@example.com"_s;
user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png"_s;
user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
user.id = WebCore::toBufferSource(TestData::kUserId);
user.displayName = "John P. Smith"_s;

Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
Expand All @@ -208,7 +208,7 @@ TEST(CTAPRequestTest, TestConstructMakeCredentialRequestRKDiscouraged)
PublicKeyCredentialCreationOptions::UserEntity user;
user.name = "johnpsmith@example.com"_s;
user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png"_s;
user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
user.id = WebCore::toBufferSource(TestData::kUserId);
user.displayName = "John P. Smith"_s;

Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
Expand All @@ -232,7 +232,7 @@ TEST(CTAPRequestTest, TestConstructMakeCredentialRequestWithLargeBlob)
PublicKeyCredentialCreationOptions::UserEntity user;
user.name = "johnpsmith@example.com"_s;
user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png"_s;
user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
user.id = WebCore::toBufferSource(TestData::kUserId);
user.displayName = "John P. Smith"_s;

Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
Expand Down Expand Up @@ -261,7 +261,7 @@ TEST(CTAPRequestTest, TestConstructMakeCredentialRequestWithUnsupportedLargeBlob
PublicKeyCredentialCreationOptions::UserEntity user;
user.name = "johnpsmith@example.com"_s;
user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png"_s;
user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
user.id = WebCore::toBufferSource(TestData::kUserId);
user.displayName = "John P. Smith"_s;

Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
Expand Down Expand Up @@ -295,7 +295,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequest)
0x34, 0x85, 0x8a, 0xc7, 0x5b, 0xed, 0x3f, 0xd5, 0x80, 0xbf, 0x98,
0x08, 0xd9, 0x4f, 0xcb, 0xee, 0x82, 0xb9, 0xb2, 0xef, 0x66, 0x77,
0xaf, 0x0a, 0xdc, 0xc3, 0x58, 0x52, 0xea, 0x6b, 0x9e };
descriptor1.id = WebCore::toBufferSource(id1, sizeof(id1));
descriptor1.id = WebCore::toBufferSource(id1);
options.allowCredentials.append(descriptor1);

PublicKeyCredentialDescriptor descriptor2;
Expand All @@ -306,7 +306,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequest)
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
descriptor2.id = WebCore::toBufferSource(id2, sizeof(id2));
descriptor2.id = WebCore::toBufferSource(id2);
options.allowCredentials.append(descriptor2);

options.userVerification = UserVerificationRequirement::Required;
Expand All @@ -333,7 +333,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequestNoUV)
0x34, 0x85, 0x8a, 0xc7, 0x5b, 0xed, 0x3f, 0xd5, 0x80, 0xbf, 0x98,
0x08, 0xd9, 0x4f, 0xcb, 0xee, 0x82, 0xb9, 0xb2, 0xef, 0x66, 0x77,
0xaf, 0x0a, 0xdc, 0xc3, 0x58, 0x52, 0xea, 0x6b, 0x9e };
descriptor1.id = WebCore::toBufferSource(id1, sizeof(id1));
descriptor1.id = WebCore::toBufferSource(id1);
options.allowCredentials.append(descriptor1);

PublicKeyCredentialDescriptor descriptor2;
Expand All @@ -344,7 +344,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequestNoUV)
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
descriptor2.id = WebCore::toBufferSource(id2, sizeof(id2));
descriptor2.id = WebCore::toBufferSource(id2);
options.allowCredentials.append(descriptor2);

options.userVerification = UserVerificationRequirement::Discouraged;
Expand All @@ -371,7 +371,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequestUVRequiredButNotSupported)
0x34, 0x85, 0x8a, 0xc7, 0x5b, 0xed, 0x3f, 0xd5, 0x80, 0xbf, 0x98,
0x08, 0xd9, 0x4f, 0xcb, 0xee, 0x82, 0xb9, 0xb2, 0xef, 0x66, 0x77,
0xaf, 0x0a, 0xdc, 0xc3, 0x58, 0x52, 0xea, 0x6b, 0x9e };
descriptor1.id = WebCore::toBufferSource(id1, sizeof(id1));
descriptor1.id = WebCore::toBufferSource(id1);
options.allowCredentials.append(descriptor1);

PublicKeyCredentialDescriptor descriptor2;
Expand All @@ -382,7 +382,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequestUVRequiredButNotSupported)
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
descriptor2.id = WebCore::toBufferSource(id2, sizeof(id2));
descriptor2.id = WebCore::toBufferSource(id2);
options.allowCredentials.append(descriptor2);

options.userVerification = UserVerificationRequirement::Required;
Expand All @@ -409,7 +409,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequestWithPin)
0x34, 0x85, 0x8a, 0xc7, 0x5b, 0xed, 0x3f, 0xd5, 0x80, 0xbf, 0x98,
0x08, 0xd9, 0x4f, 0xcb, 0xee, 0x82, 0xb9, 0xb2, 0xef, 0x66, 0x77,
0xaf, 0x0a, 0xdc, 0xc3, 0x58, 0x52, 0xea, 0x6b, 0x9e };
descriptor1.id = WebCore::toBufferSource(id1, sizeof(id1));
descriptor1.id = WebCore::toBufferSource(id1);
options.allowCredentials.append(descriptor1);

PublicKeyCredentialDescriptor descriptor2;
Expand All @@ -420,7 +420,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequestWithPin)
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
descriptor2.id = WebCore::toBufferSource(id2, sizeof(id2));
descriptor2.id = WebCore::toBufferSource(id2);
options.allowCredentials.append(descriptor2);

options.userVerification = UserVerificationRequirement::Required;
Expand Down Expand Up @@ -470,7 +470,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequestLargeBlobRead)
0x34, 0x85, 0x8a, 0xc7, 0x5b, 0xed, 0x3f, 0xd5, 0x80, 0xbf, 0x98,
0x08, 0xd9, 0x4f, 0xcb, 0xee, 0x82, 0xb9, 0xb2, 0xef, 0x66, 0x77,
0xaf, 0x0a, 0xdc, 0xc3, 0x58, 0x52, 0xea, 0x6b, 0x9e };
descriptor1.id = WebCore::toBufferSource(id1, sizeof(id1));
descriptor1.id = WebCore::toBufferSource(id1);
options.allowCredentials.append(descriptor1);

PublicKeyCredentialDescriptor descriptor2;
Expand All @@ -481,7 +481,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequestLargeBlobRead)
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
descriptor2.id = WebCore::toBufferSource(id2, sizeof(id2));
descriptor2.id = WebCore::toBufferSource(id2);
options.allowCredentials.append(descriptor2);
options.extensions = AuthenticationExtensionsClientInputs {
.largeBlob = AuthenticationExtensionsClientInputs::LargeBlobInputs {
Expand Down Expand Up @@ -513,7 +513,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequestUnsupportedLargeBlobRead)
0x34, 0x85, 0x8a, 0xc7, 0x5b, 0xed, 0x3f, 0xd5, 0x80, 0xbf, 0x98,
0x08, 0xd9, 0x4f, 0xcb, 0xee, 0x82, 0xb9, 0xb2, 0xef, 0x66, 0x77,
0xaf, 0x0a, 0xdc, 0xc3, 0x58, 0x52, 0xea, 0x6b, 0x9e };
descriptor1.id = WebCore::toBufferSource(id1, sizeof(id1));
descriptor1.id = WebCore::toBufferSource(id1);
options.allowCredentials.append(descriptor1);

PublicKeyCredentialDescriptor descriptor2;
Expand All @@ -524,7 +524,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequestUnsupportedLargeBlobRead)
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
descriptor2.id = WebCore::toBufferSource(id2, sizeof(id2));
descriptor2.id = WebCore::toBufferSource(id2);
options.allowCredentials.append(descriptor2);
options.extensions = AuthenticationExtensionsClientInputs {
.largeBlob = AuthenticationExtensionsClientInputs::LargeBlobInputs {
Expand Down Expand Up @@ -556,7 +556,7 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequestLargeBlobWrite)
0x34, 0x85, 0x8a, 0xc7, 0x5b, 0xed, 0x3f, 0xd5, 0x80, 0xbf, 0x98,
0x08, 0xd9, 0x4f, 0xcb, 0xee, 0x82, 0xb9, 0xb2, 0xef, 0x66, 0x77,
0xaf, 0x0a, 0xdc, 0xc3, 0x58, 0x52, 0xea, 0x6b, 0x9e };
descriptor1.id = WebCore::toBufferSource(id1, sizeof(id1));
descriptor1.id = WebCore::toBufferSource(id1);
options.allowCredentials.append(descriptor1);

PublicKeyCredentialDescriptor descriptor2;
Expand All @@ -567,15 +567,15 @@ TEST(CTAPRequestTest, TestConstructGetAssertionRequestLargeBlobWrite)
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
descriptor2.id = WebCore::toBufferSource(id2, sizeof(id2));
descriptor2.id = WebCore::toBufferSource(id2);
options.allowCredentials.append(descriptor2);

const uint8_t blob[] = {
0xAB, 0xCD, 0xEF
};
options.extensions = AuthenticationExtensionsClientInputs {
.largeBlob = AuthenticationExtensionsClientInputs::LargeBlobInputs {
.write = WebCore::toBufferSource(blob, sizeof(blob)),
.write = WebCore::toBufferSource(blob),
}
};

Expand Down
2 changes: 1 addition & 1 deletion Tools/TestWebKitAPI/Tests/WebCore/CtapResponseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ Vector<uint8_t> getTestCorruptedSignResponse(size_t length)
// Return a key handle used for GetAssertion request.
BufferSource getTestCredentialRawIdBytes()
{
return WebCore::toBufferSource(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
return WebCore::toBufferSource(TestData::kU2fSignKeyHandle);
}

// Return a malformed U2fRegisterResponse.
Expand Down
Loading

0 comments on commit 893e0c7

Please sign in to comment.