mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:27:35 +00:00
AK: Rename span() to bytes() when appropriate.
I originally defined the bytes() method for the String class, because it made it obvious that it's a span of bytes instead of span of characters. This commit makes this more consistent by defining a bytes() method when the type of the span is known to be u8. Additionaly, the cast operator to Bytes is overloaded for ByteBuffer and such.
This commit is contained in:
parent
525d51bbb5
commit
fff581cd72
18 changed files with 51 additions and 45 deletions
|
@ -201,8 +201,8 @@ static void aes_cbc(const char* message, size_t len)
|
|||
Crypto::Cipher::Intent::Encryption);
|
||||
|
||||
auto enc = cipher.create_aligned_buffer(buffer.size());
|
||||
auto enc_span = enc.span();
|
||||
cipher.encrypt(buffer.span(), enc_span, iv.span());
|
||||
auto enc_span = enc.bytes();
|
||||
cipher.encrypt(buffer, enc_span, iv);
|
||||
|
||||
if (binary)
|
||||
printf("%.*s", (int)enc_span.size(), enc_span.data());
|
||||
|
@ -214,8 +214,8 @@ static void aes_cbc(const char* message, size_t len)
|
|||
key_bits,
|
||||
Crypto::Cipher::Intent::Decryption);
|
||||
auto dec = cipher.create_aligned_buffer(buffer.size());
|
||||
auto dec_span = dec.span();
|
||||
cipher.decrypt(buffer.span(), dec_span, iv.span());
|
||||
auto dec_span = dec.bytes();
|
||||
cipher.decrypt(buffer, dec_span, iv);
|
||||
printf("%.*s\n", (int)dec_span.size(), dec_span.data());
|
||||
}
|
||||
}
|
||||
|
@ -588,8 +588,8 @@ static void aes_cbc_test_encrypt()
|
|||
auto in = "This is a test! This is another test!"_b;
|
||||
auto out = cipher.create_aligned_buffer(in.size());
|
||||
auto iv = ByteBuffer::create_zeroed(Crypto::Cipher::AESCipher::block_size());
|
||||
auto out_span = out.span();
|
||||
cipher.encrypt(in.span(), out_span, iv.span());
|
||||
auto out_span = out.bytes();
|
||||
cipher.encrypt(in, out_span, iv);
|
||||
if (out.size() != sizeof(result))
|
||||
FAIL(size mismatch);
|
||||
else if (memcmp(out_span.data(), result, out_span.size()) != 0) {
|
||||
|
@ -652,8 +652,8 @@ static void aes_cbc_test_decrypt()
|
|||
auto in = ByteBuffer::copy(result, result_len);
|
||||
auto out = cipher.create_aligned_buffer(in.size());
|
||||
auto iv = ByteBuffer::create_zeroed(Crypto::Cipher::AESCipher::block_size());
|
||||
auto out_span = out.span();
|
||||
cipher.decrypt(in.span(), out_span, iv.span());
|
||||
auto out_span = out.bytes();
|
||||
cipher.decrypt(in, out_span, iv);
|
||||
if (out_span.size() != strlen(true_value)) {
|
||||
FAIL(size mismatch);
|
||||
printf("Expected %zu bytes but got %zu\n", strlen(true_value), out_span.size());
|
||||
|
@ -728,8 +728,8 @@ static void aes_ctr_test_encrypt()
|
|||
// nonce is already included in ivec.
|
||||
Crypto::Cipher::AESCipher::CTRMode cipher(key, 8 * key.size(), Crypto::Cipher::Intent::Encryption);
|
||||
ByteBuffer out_actual = ByteBuffer::create_zeroed(in.size());
|
||||
Bytes out_span = out_actual.span();
|
||||
cipher.encrypt(in.span(), out_span, ivec.span());
|
||||
Bytes out_span = out_actual.bytes();
|
||||
cipher.encrypt(in, out_span, ivec);
|
||||
if (out_expected.size() != out_actual.size()) {
|
||||
FAIL(size mismatch);
|
||||
printf("Expected %zu bytes but got %zu\n", out_expected.size(), out_span.size());
|
||||
|
@ -923,8 +923,8 @@ static void aes_ctr_test_decrypt()
|
|||
// nonce is already included in ivec.
|
||||
Crypto::Cipher::AESCipher::CTRMode cipher(key, 8 * key.size(), Crypto::Cipher::Intent::Decryption);
|
||||
ByteBuffer out_actual = ByteBuffer::create_zeroed(in.size());
|
||||
auto out_span = out_actual.span();
|
||||
cipher.decrypt(in.span(), out_span, ivec.span());
|
||||
auto out_span = out_actual.bytes();
|
||||
cipher.decrypt(in, out_span, ivec);
|
||||
if (out_expected.size() != out_span.size()) {
|
||||
FAIL(size mismatch);
|
||||
printf("Expected %zu bytes but got %zu\n", out_expected.size(), out_span.size());
|
||||
|
@ -1442,7 +1442,7 @@ static void rsa_test_encrypt()
|
|||
rsa.encrypt(data, buf);
|
||||
if (memcmp(result, buf.data(), buf.size())) {
|
||||
FAIL(Invalid encryption result);
|
||||
print_buffer(buf.span(), 16);
|
||||
print_buffer(buf, 16);
|
||||
} else {
|
||||
PASS;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue