AK: Add XOR method to ByteBuffer
This commit is contained in:
parent
73a534494c
commit
3f1019b089
Notes:
sideshowbarker
2024-07-17 06:00:02 +09:00
Author: https://github.com/stelar7 Commit: https://github.com/SerenityOS/serenity/commit/3f1019b089 Pull-request: https://github.com/SerenityOS/serenity/pull/23879 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/nico Reviewed-by: https://github.com/tcl3
1 changed files with 15 additions and 0 deletions
|
@ -92,6 +92,21 @@ public:
|
|||
return copy(bytes.data(), bytes.size());
|
||||
}
|
||||
|
||||
[[nodiscard]] static ErrorOr<ByteBuffer> xor_buffers(ReadonlyBytes first, ReadonlyBytes second)
|
||||
{
|
||||
if (first.size() != second.size())
|
||||
return Error::from_errno(EINVAL);
|
||||
|
||||
auto buffer = TRY(create_uninitialized(first.size()));
|
||||
auto buffer_data = buffer.data();
|
||||
auto first_data = first.data();
|
||||
auto second_data = second.data();
|
||||
for (size_t i = 0; i < first.size(); ++i)
|
||||
buffer_data[i] = first_data[i] ^ second_data[i];
|
||||
|
||||
return { move(buffer) };
|
||||
}
|
||||
|
||||
template<size_t other_inline_capacity>
|
||||
bool operator==(ByteBuffer<other_inline_capacity> const& other) const
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue