Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tabVersion committed Jan 29, 2024
1 parent 0adbe89 commit 1dbce01
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
26 changes: 26 additions & 0 deletions e2e_test/streaming/encrypt.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
query T
SELECT encrypt('\x00112233445566778899aabbccddeeff','\x000102030405060708090a0b0c0d0e0f','aes-ecb/pad:none')
----
\x69c4e0d86a7b0430d8cdb78070b4c55a

query T
SELECT encrypt('\x00112233445566778899aabbccddeeff','\x000102030405060708090a0b0c0d0e0f1011121314151617','aes-ecb/pad:none');
----
\xdda97ca4864cdfe06eaf70a0ec0d7191

query T
SELECT encrypt('\x00112233445566778899aabbccddeeff','\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f','aes-ecb/pad:none')
----
\x8ea2b7ca516745bfeafc49904b496089

query T
SELECT encrypt('\x00112233445566778899aabbccddeeff','\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f','aes-cbc/pad:none')
----
\x8ea2b7ca516745bfeafc49904b496089

# input not multiple of block size when not allowing padding
statement error
SELECT encrypt('\x00112233445566778899aabbccddeeff00','\x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f','aes-cbc/pad:none')



10 changes: 3 additions & 7 deletions src/expr/impl/src/scalar/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,16 @@ mod test {
let config = CipherConfig::parse_cipher_config(key, mode)?;
decrypt(data, &config)
};
let key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f";

let encrypted = encrypt_wrapper(
b"\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff",
b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
key,
"aes-ecb/pad:none",
)
.unwrap();

let decrypted = decrypt_wrapper(
&encrypted,
b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0e",
"aes-ecb/pad:none",
)
.unwrap();
let decrypted = decrypt_wrapper(&encrypted, key, "aes-ecb/pad:none").unwrap();
assert_eq!(
decrypted,
(*b"\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff").into()
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/binder/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,8 @@ impl Binder {
("sha256", raw_call(ExprType::Sha256)),
("sha384", raw_call(ExprType::Sha384)),
("sha512", raw_call(ExprType::Sha512)),
("encrypt", raw_call(ExprType::Encrypt)),
("decrypt", raw_call(ExprType::Decrypt)),
("left", raw_call(ExprType::Left)),
("right", raw_call(ExprType::Right)),
("int8send", raw_call(ExprType::PgwireSend)),
Expand Down

0 comments on commit 1dbce01

Please sign in to comment.