diff options
author | asynts <asynts@gmail.com> | 2020-08-15 18:38:24 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-15 21:21:18 +0200 |
commit | fff581cd725db6b9cc1e1fd25503c68ec2d044d3 (patch) | |
tree | 0c0a510f5cbd1c2c6c1613b11209655624eda893 /Userland | |
parent | 525d51bbb526912946c491e502b57cf439ab3906 (diff) | |
download | serenity-fff581cd725db6b9cc1e1fd25503c68ec2d044d3.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/base64.cpp | 2 | ||||
-rw-r--r-- | Userland/test-crypto.cpp | 26 |
2 files changed, 14 insertions, 14 deletions
diff --git a/Userland/base64.cpp b/Userland/base64.cpp index a91275a0c8..0af7a684a4 100644 --- a/Userland/base64.cpp +++ b/Userland/base64.cpp @@ -75,6 +75,6 @@ int main(int argc, char** argv) return 0; } - auto encoded = encode_base64(buffer.span()); + auto encoded = encode_base64(buffer); printf("%s\n", encoded.characters()); } diff --git a/Userland/test-crypto.cpp b/Userland/test-crypto.cpp index 25359f93d0..972713329b 100644 --- a/Userland/test-crypto.cpp +++ b/Userland/test-crypto.cpp @@ -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; } |