1717
1818#include < stdexcept>
1919
20- using namespace std ;
2120using namespace duckdb_mbedtls ;
2221using CipherType = duckdb::EncryptionTypes::CipherType;
2322using EncryptionVersion = duckdb::EncryptionTypes::EncryptionVersion;
@@ -45,13 +44,13 @@ void MbedTlsWrapper::ComputeSha256Hash(const char *in, size_t in_len, char *out)
4544 if (mbedtls_sha256_starts (&sha_context, false ) ||
4645 mbedtls_sha256_update (&sha_context, reinterpret_cast <const unsigned char *>(in), in_len) ||
4746 mbedtls_sha256_finish (&sha_context, reinterpret_cast <unsigned char *>(out))) {
48- throw runtime_error (" SHA256 Error" );
47+ throw std:: runtime_error (" SHA256 Error" );
4948 }
5049 mbedtls_sha256_free (&sha_context);
5150}
5251
53- string MbedTlsWrapper::ComputeSha256Hash (const string &file_content) {
54- string hash;
52+ std:: string MbedTlsWrapper::ComputeSha256Hash (const std:: string &file_content) {
53+ std:: string hash;
5554 hash.resize (MbedTlsWrapper::SHA256_HASH_LENGTH_BYTES );
5655 ComputeSha256Hash (file_content.data (), file_content.size (), (char *)hash.data ());
5756 return hash;
@@ -62,16 +61,16 @@ bool MbedTlsWrapper::IsValidSha256Signature(const std::string &pubkey, const std
6261
6362 if (signature.size () != 256 || sha256_hash.size () != 32 ) {
6463 throw std::runtime_error (" Invalid input lengths, expected signature length 256, got " +
65- to_string (signature.size ()) + " , hash length 32, got " +
66- to_string (sha256_hash.size ()));
64+ std:: to_string (signature.size ()) + " , hash length 32, got " +
65+ std:: to_string (sha256_hash.size ()));
6766 }
6867
6968 mbedtls_pk_context pk_context;
7069 mbedtls_pk_init (&pk_context);
7170
7271 if (mbedtls_pk_parse_public_key (&pk_context, reinterpret_cast <const unsigned char *>(pubkey.c_str ()),
7372 pubkey.size () + 1 )) {
74- throw runtime_error (" RSA public key import error" );
73+ throw std:: runtime_error (" RSA public key import error" );
7574 }
7675
7776 // actually verify
@@ -88,14 +87,14 @@ void MbedTlsWrapper::Hmac256(const char *key, size_t key_len, const char *messag
8887 mbedtls_md_context_t hmac_ctx;
8988 const mbedtls_md_info_t *md_type = mbedtls_md_info_from_type (MBEDTLS_MD_SHA256 );
9089 if (!md_type) {
91- throw runtime_error (" failed to init hmac" );
90+ throw std:: runtime_error (" failed to init hmac" );
9291 }
9392
9493 if (mbedtls_md_setup (&hmac_ctx, md_type, 1 ) ||
9594 mbedtls_md_hmac_starts (&hmac_ctx, reinterpret_cast <const unsigned char *>(key), key_len) ||
9695 mbedtls_md_hmac_update (&hmac_ctx, reinterpret_cast <const unsigned char *>(message), message_len) ||
9796 mbedtls_md_hmac_finish (&hmac_ctx, reinterpret_cast <unsigned char *>(out))) {
98- throw runtime_error (" HMAC256 Error" );
97+ throw std:: runtime_error (" HMAC256 Error" );
9998 }
10099 mbedtls_md_free (&hmac_ctx);
101100}
@@ -163,7 +162,7 @@ void MbedTlsWrapper::SHA256State::FinalizeDerivedKey(duckdb::data_ptr_t hash) {
163162std::string MbedTlsWrapper::SHA256State::Finalize () {
164163 auto context = reinterpret_cast <mbedtls_sha256_context *>(sha_context);
165164
166- string hash;
165+ std:: string hash;
167166 hash.resize (MbedTlsWrapper::SHA256_HASH_LENGTH_BYTES );
168167
169168 if (mbedtls_sha256_finish (context, (unsigned char *)hash.data ())) {
@@ -176,7 +175,7 @@ std::string MbedTlsWrapper::SHA256State::Finalize() {
176175void MbedTlsWrapper::SHA256State::FinishHex (char *out) {
177176 auto context = reinterpret_cast <mbedtls_sha256_context *>(sha_context);
178177
179- string hash;
178+ std:: string hash;
180179 hash.resize (MbedTlsWrapper::SHA256_HASH_LENGTH_BYTES );
181180
182181 if (mbedtls_sha256_finish (context, (unsigned char *)hash.data ())) {
@@ -212,7 +211,7 @@ void MbedTlsWrapper::SHA1State::AddString(const std::string &str) {
212211std::string MbedTlsWrapper::SHA1State::Finalize () {
213212 auto context = reinterpret_cast <mbedtls_sha1_context *>(sha_context);
214213
215- string hash;
214+ std:: string hash;
216215 hash.resize (MbedTlsWrapper::SHA1_HASH_LENGTH_BYTES );
217216
218217 if (mbedtls_sha1_finish (context, (unsigned char *)hash.data ())) {
@@ -225,7 +224,7 @@ std::string MbedTlsWrapper::SHA1State::Finalize() {
225224void MbedTlsWrapper::SHA1State::FinishHex (char *out) {
226225 auto context = reinterpret_cast <mbedtls_sha1_context *>(sha_context);
227226
228- string hash;
227+ std:: string hash;
229228 hash.resize (MbedTlsWrapper::SHA1_HASH_LENGTH_BYTES );
230229
231230 if (mbedtls_sha1_finish (context, (unsigned char *)hash.data ())) {
@@ -246,7 +245,7 @@ const mbedtls_cipher_info_t *MbedTlsWrapper::AESStateMBEDTLS::GetCipher(){
246245 case 32 :
247246 return mbedtls_cipher_info_from_type (MBEDTLS_CIPHER_AES_256_GCM );
248247 default :
249- throw runtime_error (" Invalid AES key length for GCM" );
248+ throw std:: runtime_error (" Invalid AES key length for GCM" );
250249 }
251250 case CipherType::CTR :
252251 switch (metadata->GetKeyLen ()) {
@@ -257,7 +256,7 @@ const mbedtls_cipher_info_t *MbedTlsWrapper::AESStateMBEDTLS::GetCipher(){
257256 case 32 :
258257 return mbedtls_cipher_info_from_type (MBEDTLS_CIPHER_AES_256_CTR );
259258 default :
260- throw runtime_error (" Invalid AES key length for CTR" );
259+ throw std:: runtime_error (" Invalid AES key length for CTR" );
261260 }
262261 case CipherType::CBC :
263262 switch (metadata->GetKeyLen ()) {
@@ -268,7 +267,7 @@ const mbedtls_cipher_info_t *MbedTlsWrapper::AESStateMBEDTLS::GetCipher(){
268267 case 32 :
269268 return mbedtls_cipher_info_from_type (MBEDTLS_CIPHER_AES_256_CBC );
270269 default :
271- throw runtime_error (" Invalid AES key length for CBC" );
270+ throw std:: runtime_error (" Invalid AES key length for CBC" );
272271 }
273272 default :
274273 throw duckdb::InternalException (" Invalid Encryption/Decryption Cipher: %s" , duckdb::EncryptionTypes::CipherToString (metadata->GetCipher ()));
@@ -285,15 +284,15 @@ MbedTlsWrapper::AESStateMBEDTLS::AESStateMBEDTLS(duckdb::unique_ptr<duckdb::Encr
285284 auto cipher_info = GetCipher ();
286285
287286 if (!cipher_info) {
288- throw runtime_error (" Failed to get Cipher" );
287+ throw std:: runtime_error (" Failed to get Cipher" );
289288 }
290289
291290 if (mbedtls_cipher_setup (context.get (), cipher_info)) {
292- throw runtime_error (" Failed to initialize cipher context" );
291+ throw std:: runtime_error (" Failed to initialize cipher context" );
293292 }
294293
295294 if (metadata->GetCipher () == duckdb::EncryptionTypes::CBC && mbedtls_cipher_set_padding_mode (context.get (), MBEDTLS_PADDING_PKCS7 )) {
296- throw runtime_error (" Failed to set CBC padding" );
295+ throw std:: runtime_error (" Failed to set CBC padding" );
297296
298297 }
299298}
@@ -330,7 +329,7 @@ void MbedTlsWrapper::AESStateMBEDTLS::GenerateRandomData(duckdb::data_ptr_t data
330329
331330void MbedTlsWrapper::AESStateMBEDTLS::InitializeInternal (duckdb::EncryptionNonce &nonce, duckdb::const_data_ptr_t aad, duckdb::idx_t aad_len){
332331 if (mbedtls_cipher_set_iv (context.get (), nonce.data (), nonce.total_size ())) {
333- throw runtime_error (" Failed to set IV for encryption" );
332+ throw std:: runtime_error (" Failed to set IV for encryption" );
334333 }
335334
336335 if (aad_len > 0 ) {
@@ -344,7 +343,7 @@ void MbedTlsWrapper::AESStateMBEDTLS::InitializeEncryption(duckdb::EncryptionNon
344343 mode = duckdb::EncryptionTypes::ENCRYPT ;
345344
346345 if (mbedtls_cipher_setkey (context.get (), key, metadata->GetKeyLen () * 8 , MBEDTLS_ENCRYPT ) != 0 ) {
347- runtime_error (" Failed to set AES key for encryption" );
346+ throw std:: runtime_error (" Failed to set AES key for encryption" );
348347 }
349348
350349 InitializeInternal (nonce, aad, aad_len);
@@ -354,7 +353,7 @@ void MbedTlsWrapper::AESStateMBEDTLS::InitializeDecryption(duckdb::EncryptionNon
354353 mode = duckdb::EncryptionTypes::DECRYPT ;
355354
356355 if (mbedtls_cipher_setkey (context.get (), key, metadata->GetKeyLen () * 8 , MBEDTLS_DECRYPT )) {
357- throw runtime_error (" Failed to set AES key for encryption" );
356+ throw std:: runtime_error (" Failed to set AES key for encryption" );
358357 }
359358
360359 InitializeInternal (nonce, aad, aad_len);
@@ -376,7 +375,7 @@ size_t MbedTlsWrapper::AESStateMBEDTLS::Process(duckdb::const_data_ptr_t in, duc
376375 size_t out_len_res = duckdb::NumericCast<size_t >(out_len);
377376 if (mbedtls_cipher_update (context.get (), reinterpret_cast <const unsigned char *>(in), in_len, out_ptr,
378377 &out_len_res)) {
379- throw runtime_error (" Encryption or Decryption failed at Process" );
378+ throw std:: runtime_error (" Encryption or Decryption failed at Process" );
380379 };
381380
382381 if (use_out_copy) {
@@ -391,7 +390,7 @@ void MbedTlsWrapper::AESStateMBEDTLS::FinalizeGCM(duckdb::data_ptr_t tag, duckdb
391390
392391 case duckdb::EncryptionTypes::ENCRYPT : {
393392 if (mbedtls_cipher_write_tag (context.get (), tag, tag_len)) {
394- throw runtime_error (" Writing tag failed" );
393+ throw std:: runtime_error (" Writing tag failed" );
395394 }
396395 break ;
397396 }
@@ -413,7 +412,7 @@ size_t MbedTlsWrapper::AESStateMBEDTLS::Finalize(duckdb::data_ptr_t out, duckdb:
413412 duckdb::idx_t tag_len) {
414413 size_t result = out_len;
415414 if (mbedtls_cipher_finish (context.get (), out, &result)) {
416- throw runtime_error (" Encryption or Decryption failed at Finalize" );
415+ throw std:: runtime_error (" Encryption or Decryption failed at Finalize" );
417416 }
418417 if (metadata->GetCipher () == duckdb::EncryptionTypes::GCM ) {
419418 FinalizeGCM (tag, tag_len);
0 commit comments