1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:17:35 +00:00

Refactor: Expose const_cast by removing ByteBuffer::warp(const void*, size_t)

This function did a const_cast internally which made the call side look
"safe". This method is removed completely and call sites are replaced
with ByteBuffer::wrap(const_cast<void*>(data), size) which makes the
behaviour obvious.
This commit is contained in:
asynts 2020-08-05 14:09:38 +02:00 committed by Andreas Kling
parent ac9f6fd1f8
commit b3d1a05261
15 changed files with 42 additions and 36 deletions

View file

@ -189,12 +189,15 @@ void tls(const char* message, size_t len)
void aes_cbc(const char* message, size_t len)
{
auto buffer = ByteBuffer::wrap(message, len);
auto buffer = ByteBuffer::wrap(const_cast<char*>(message), len);
// FIXME: Take iv as an optional parameter
auto iv = ByteBuffer::create_zeroed(Crypto::Cipher::AESCipher::block_size());
if (encrypting) {
Crypto::Cipher::AESCipher::CBCMode cipher(ByteBuffer::wrap(secret_key, strlen(secret_key)), key_bits, Crypto::Cipher::Intent::Encryption);
Crypto::Cipher::AESCipher::CBCMode cipher(
ByteBuffer::wrap(const_cast<char*>(secret_key), strlen(secret_key)),
key_bits,
Crypto::Cipher::Intent::Encryption);
auto enc = cipher.create_aligned_buffer(buffer.size());
(void)cipher.encrypt(buffer, enc, iv);
@ -204,7 +207,10 @@ void aes_cbc(const char* message, size_t len)
else
print_buffer(enc, Crypto::Cipher::AESCipher::block_size());
} else {
Crypto::Cipher::AESCipher::CBCMode cipher(ByteBuffer::wrap(secret_key, strlen(secret_key)), key_bits, Crypto::Cipher::Intent::Decryption);
Crypto::Cipher::AESCipher::CBCMode cipher(
ByteBuffer::wrap(const_cast<char*>(secret_key), strlen(secret_key)),
key_bits,
Crypto::Cipher::Intent::Decryption);
auto dec = cipher.create_aligned_buffer(buffer.size());
cipher.decrypt(buffer, dec, iv);
printf("%.*s\n", (int)dec.size(), dec.data());