@@ -29,8 +29,10 @@ static CipherParams commonParams[] =
2929 CIPHER_PARAMS_SENTINEL
3030};
3131
32- static CodecParameter globalCommonParams = { "global" , CODEC_TYPE_UNKNOWN , commonParams };
33- static CodecParameter globalSentinelParams = { "" , CODEC_TYPE_UNKNOWN , NULL };
32+ #define CIPHER_NAME_GLOBAL "global"
33+
34+ static CodecParameter globalCommonParams = { CIPHER_NAME_GLOBAL , CODEC_TYPE_UNKNOWN , commonParams };
35+ static CodecParameter globalSentinelParams = { "" , CODEC_TYPE_UNKNOWN , NULL };
3436
3537SQLITE_PRIVATE int
3638sqlite3mcGetCipherParameter (CipherParams * cipherParams , const char * paramName )
@@ -157,19 +159,20 @@ sqlite3mcGetCipherType(sqlite3* db)
157159}
158160
159161SQLITE_PRIVATE CipherParams *
160- sqlite3mcGetCipherParams (sqlite3 * db , int cypherType )
162+ sqlite3mcGetCipherParams (sqlite3 * db , const char * cipherName )
161163{
162164 int j = 0 ;
165+ int cipherType = sqlite3mc_cipher_index (cipherName );
163166 CodecParameter * codecParams = (db != NULL ) ? sqlite3mcGetCodecParams (db ) : globalCodecParameterTable ;
164167 if (codecParams == NULL )
165168 {
166169 codecParams = globalCodecParameterTable ;
167170 }
168- if (cypherType > 0 )
171+ if (cipherType > 0 )
169172 {
170173 for (j = 1 ; codecParams [j ].m_id > 0 ; ++ j )
171174 {
172- if (cypherType == codecParams [j ].m_id ) break ;
175+ if (cipherType == codecParams [j ].m_id ) break ;
173176 }
174177 }
175178 CipherParams * cipherParamTable = codecParams [j ].m_params ;
@@ -241,7 +244,7 @@ SQLITE_PRIVATE int
241244sqlite3mcCodecSetup (Codec * codec , int cipherType , char * userPassword , int passwordLength )
242245{
243246 int rc = SQLITE_OK ;
244- CipherParams * globalParams = sqlite3mcGetCipherParams (codec -> m_db , 0 );
247+ CipherParams * globalParams = sqlite3mcGetCipherParams (codec -> m_db , CIPHER_NAME_GLOBAL );
245248 codec -> m_isEncrypted = 1 ;
246249 codec -> m_hmacCheck = sqlite3mcGetCipherParameter (globalParams , "hmac_check" );
247250 codec -> m_walLegacy = sqlite3mcGetCipherParameter (globalParams , "mc_legacy_wal" );
@@ -266,7 +269,7 @@ SQLITE_PRIVATE int
266269sqlite3mcSetupWriteCipher (Codec * codec , int cipherType , char * userPassword , int passwordLength )
267270{
268271 int rc = SQLITE_OK ;
269- CipherParams * globalParams = sqlite3mcGetCipherParams (codec -> m_db , 0 );
272+ CipherParams * globalParams = sqlite3mcGetCipherParams (codec -> m_db , CIPHER_NAME_GLOBAL );
270273 if (codec -> m_writeCipher != NULL )
271274 {
272275 globalCodecDescriptorTable [codec -> m_writeCipherType - 1 ].m_freeCipher (codec -> m_writeCipher );
0 commit comments