diff --git a/src/Functions/FileEncryption.h b/src/Functions/FileEncryption.h index 3830e90bff5..fa056c9386e 100644 --- a/src/Functions/FileEncryption.h +++ b/src/Functions/FileEncryption.h @@ -38,10 +38,10 @@ class InitVector public: InitVector(String iv_) : iv(FromBigEndianString(iv_)) { } - const char * GetRef() const + const String & GetRef() const { local = ToBigEndianString(iv + counter); - return local.data(); + return local; } void Inc() { ++counter; } @@ -75,7 +75,7 @@ class EncryptionKey public: EncryptionKey(String key_) : key(key_) { } size_t Size() const { return key.size(); } - const char * GetRef() const { return key.data(); } + const String & GetRef() const { return key; } private: String key; @@ -238,8 +238,8 @@ private: throw DB::Exception("Failed to initialize encryption context with cipher", DB::ErrorCodes::DATA_ENCRYPTION_ERROR); if (EVP_EncryptInit_ex(evp_ctx, nullptr, nullptr, - reinterpret_cast(key.GetRef()), - reinterpret_cast(iv.GetRef())) != 1) + reinterpret_cast(key.GetRef().data()), + reinterpret_cast(iv.GetRef().data())) != 1) throw DB::Exception("Failed to set key and IV for encryption", DB::ErrorCodes::DATA_ENCRYPTION_ERROR); int output_len = 0; @@ -319,8 +319,8 @@ private: throw DB::Exception("Failed to initialize decryption context with cipher", DB::ErrorCodes::DATA_ENCRYPTION_ERROR); if (EVP_DecryptInit_ex(evp_ctx, nullptr, nullptr, - reinterpret_cast(key.GetRef()), - reinterpret_cast(iv.GetRef())) != 1) + reinterpret_cast(key.GetRef().data()), + reinterpret_cast(iv.GetRef().data())) != 1) throw DB::Exception("Failed to set key and IV for decryption", DB::ErrorCodes::DATA_ENCRYPTION_ERROR); int output_len = 0; diff --git a/src/Functions/tests/gtest_file_encryption.cpp b/src/Functions/tests/gtest_file_encryption.cpp index 965099fe999..79f03b1f405 100644 --- a/src/Functions/tests/gtest_file_encryption.cpp +++ b/src/Functions/tests/gtest_file_encryption.cpp @@ -1,3 +1,7 @@ +#if !defined(ARCADIA_BUILD) +#include +#endif + #if USE_SSL #include #include @@ -76,16 +80,16 @@ INSTANTIATE_TEST_SUITE_P(InitVectorInputs, 1024, string_ends_with(16, "\x1"), string_ends_with(16, "\x56"), - string_ends_with(16, "\x4\0"), + string_ends_with(16, String("\x4\0", 2)), }, { "Long init vector test", "\xa8\x65\x9c\x73\xf8\x5d\x83\xb4\x5c\xa6\x8c\x19\xf4\x77\x80\xe1", - UInt128(3349249125638641) * 1815701, + 3349249125638641, 1698923461902341, "\xa8\x65\x9c\x73\xf8\x5d\x83\xb4\x5c\xa6\x8c\x19\xf4\x77\x80\xe2", - "\xa8\x65\x9c\x73\xf8\x5d\x84\xfe\x06\xbd\x44\xb7\x0b\x0c\x76\x27", - "\xa8\x65\x9c\x73\xf8\x5d\x83\xb4\x5c\xac\x95\x43\x65\xea\x00\xe6", + "\xa8\x65\x9c\x73\xf8\x5d\x83\xb4\x5c\xb2\x72\x39\xc8\xdd\x62\xd3", + String("\xa8\x65\x9c\x73\xf8\x5d\x83\xb4\x5c\xac\x95\x43\x65\xea\x00\xe6", 16) }, }) );