[Bug] Fix aes_decrypt to handle null input correctly. (#6636)
This commit is contained in:
@ -33,7 +33,7 @@ void EncryptionFunctions::init() {}
|
||||
|
||||
StringVal EncryptionFunctions::aes_encrypt(FunctionContext* ctx, const StringVal& src,
|
||||
const StringVal& key) {
|
||||
if (src.len == 0) {
|
||||
if (src.len == 0 || src.is_null) {
|
||||
return StringVal::null();
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ StringVal EncryptionFunctions::aes_encrypt(FunctionContext* ctx, const StringVal
|
||||
|
||||
StringVal EncryptionFunctions::aes_decrypt(FunctionContext* ctx, const StringVal& src,
|
||||
const StringVal& key) {
|
||||
if (src.len == 0) {
|
||||
if (src.len == 0 || src.is_null) {
|
||||
return StringVal::null();
|
||||
}
|
||||
|
||||
|
||||
@ -76,6 +76,28 @@ TEST_F(EncryptionFunctionsTest, to_base64) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(EncryptionFunctionsTest, aes_decrypt) {
|
||||
std::unique_ptr<doris_udf::FunctionContext> context(new doris_udf::FunctionContext());
|
||||
{
|
||||
StringVal encryptWord = EncryptionFunctions::aes_encrypt(context.get(), doris_udf::StringVal("hello"),
|
||||
doris_udf::StringVal("key"));
|
||||
StringVal result = EncryptionFunctions::aes_decrypt(context.get(), encryptWord,
|
||||
doris_udf::StringVal("key"));
|
||||
StringVal expected = doris_udf::StringVal("hello");
|
||||
ASSERT_EQ(expected, result);
|
||||
}
|
||||
{
|
||||
StringVal encryptWord = EncryptionFunctions::aes_encrypt(context.get(), doris_udf::StringVal("hello"),
|
||||
doris_udf::StringVal("key"));
|
||||
encryptWord.is_null = true;
|
||||
StringVal result = EncryptionFunctions::aes_decrypt(context.get(), encryptWord,
|
||||
doris_udf::StringVal("key"));
|
||||
StringVal expected = doris_udf::StringVal::null();
|
||||
ASSERT_EQ(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace doris
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
@ -86,4 +108,4 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user