@@ -645,6 +645,11 @@ sqlite3mcConfigureFromUri(sqlite3* db, const char *zDbName, int configDefault)
645645 cipherParams = (strlen (globalCodecParameterTable [j ].m_name ) > 0 ) ? globalCodecParameterTable [j ].m_params : NULL ;
646646 if (cipherParams != NULL )
647647 {
648+ /*
649+ ** Flag whether to skip the legacy parameter
650+ ** Currently enabled only in case of the SQLCipher scheme
651+ */
652+ int skipLegacy = 0 ;
648653 /* Set global parameters (cipher and hmac_check) */
649654 int hmacCheck = sqlite3_uri_boolean (dbFileName , "hmac_check" , 1 );
650655 if (configDefault )
@@ -666,13 +671,17 @@ sqlite3mcConfigureFromUri(sqlite3* db, const char *zDbName, int configDefault)
666671 int legacy = (int ) sqlite3_uri_int64 (dbFileName , "legacy" , 0 );
667672 if (legacy > 0 && legacy <= SQLCIPHER_VERSION_MAX )
668673 {
669- sqlite3mcConfigureSQLCipherVersion (db , configDefault , legacy );
674+ char * param = (configDefault ) ? "default:legacy" : "legacy" ;
675+ sqlite3mc_config_cipher (db , cipherName , param , legacy );
676+ skipLegacy = 1 ;
670677 }
671678 }
672679
673680 /* Check all cipher specific parameters */
674681 for (j = 0 ; strlen (cipherParams [j ].m_name ) > 0 ; ++ j )
675682 {
683+ if (skipLegacy && sqlite3_stricmp (cipherParams [j ].m_name , "legacy" ) == 0 ) continue ;
684+
676685 int value = (int ) sqlite3_uri_int64 (dbFileName , cipherParams [j ].m_name , -1 );
677686 if (value >= 0 )
678687 {
@@ -816,56 +825,28 @@ sqlite3mcFileControlPragma(sqlite3* db, const char* zDbName, int op, void* pArg)
816825 if (cipherParams != NULL )
817826 {
818827 const char * cipherName = globalCodecParameterTable [j ].m_name ;
819- if ((cipher == CODEC_TYPE_SQLCIPHER ) && (sqlite3StrICmp (pragmaName , "legacy" ) == 0 ))
828+ int j ;
829+ for (j = 0 ; strlen (cipherParams [j ].m_name ) > 0 ; ++ j )
820830 {
821- /* Special handling for SQLCipher */
822- int legacy = (isIntValue ) ? intValue : -1 ;
823- if (legacy > 0 && legacy <= SQLCIPHER_VERSION_MAX )
824- {
825- sqlite3mcConfigureSQLCipherVersion (db , configDefault , legacy );
826- ((char * * )pArg )[0 ] = sqlite3_mprintf ("%d" , legacy );
827- rc = SQLITE_OK ;
828- }
829- else
831+ if (sqlite3_stricmp (pragmaName , cipherParams [j ].m_name ) == 0 ) break ;
832+ }
833+ if (strlen (cipherParams [j ].m_name ) > 0 )
834+ {
835+ char * param = (configDefault ) ? sqlite3_mprintf ("default:%s" , pragmaName ) : pragmaName ;
836+ if (isIntValue )
830837 {
831- int value ;
832- if (configDefault )
833- {
834- value = sqlite3mc_config_cipher (db , "sqlcipher" , "default:legacy" , legacy );
835- }
836- else
837- {
838- value = sqlite3mc_config_cipher (db , "sqlcipher" , "legacy" , legacy );
839- }
838+ int value = sqlite3mc_config_cipher (db , cipherName , param , intValue );
840839 ((char * * )pArg )[0 ] = sqlite3_mprintf ("%d" , value );
841840 rc = SQLITE_OK ;
842841 }
843- }
844- else
845- {
846- int j ;
847- for (j = 0 ; strlen (cipherParams [j ].m_name ) > 0 ; ++ j )
842+ else
848843 {
849- if (sqlite3_stricmp (pragmaName , cipherParams [j ].m_name ) == 0 ) break ;
844+ ((char * * ) pArg )[0 ] = sqlite3_mprintf ("Malformed integer value '%s'." , pragmaValue );
845+ rc = SQLITE_ERROR ;
850846 }
851- if (strlen ( cipherParams [ j ]. m_name ) > 0 )
847+ if (configDefault )
852848 {
853- char * param = (configDefault ) ? sqlite3_mprintf ("default:%s" , pragmaName ) : pragmaName ;
854- if (isIntValue )
855- {
856- int value = sqlite3mc_config_cipher (db , cipherName , param , intValue );
857- ((char * * )pArg )[0 ] = sqlite3_mprintf ("%d" , value );
858- rc = SQLITE_OK ;
859- }
860- else
861- {
862- ((char * * ) pArg )[0 ] = sqlite3_mprintf ("Malformed integer value '%s'." , pragmaValue );
863- rc = SQLITE_ERROR ;
864- }
865- if (configDefault )
866- {
867- sqlite3_free (param );
868- }
849+ sqlite3_free (param );
869850 }
870851 }
871852 }
0 commit comments