@@ -1145,4 +1145,64 @@ do_test cipher-options-before-keys {
11451145db close
11461146file delete -force test.db
11471147
1148+ # open a 1.1.8 database (no HMAC), then
1149+ # try to open another 1.1.8 database. The
1150+ # attached database should have the same hmac
1151+ # setting as the original
1152+ do_test default-use-hmac-attach {
1153+ file copy -force sqlcipher-1.1.8-testkey.db test.db
1154+ sqlite_orig db test.db
1155+ execsql {
1156+ PRAGMA cipher_default_use_hmac = OFF;
1157+ PRAGMA key = 'testkey';
1158+ SELECT count(*) FROM t1;
1159+ ATTACH 'sqlcipher-1.1.8-testkey.db' AS db2;
1160+ SELECT count(*) from db2.t1;
1161+ PRAGMA cipher_default_use_hmac = ON;
1162+ }
1163+ } {4 4}
1164+ db close
1165+ file delete -force test.db
1166+
1167+ # open a 2.0 database (with HMAC), then
1168+ # try to a 1.1.8 database. this should
1169+ # fail because the hmac setting for the
1170+ # attached database is not compatible
1171+ do_test attach-1.1.8-database-from-2.0-fails {
1172+ sqlite_orig db test.db
1173+ catchsql {
1174+ PRAGMA key = 'testkey';
1175+ CREATE table t1(a,b);
1176+ ATTACH 'sqlcipher-1.1.8-testkey.db' AS db2;
1177+ }
1178+ } {1 {file is encrypted or is not a database}}
1179+ db close
1180+ file delete -force test.db
1181+
1182+ # open a 2.0 database (with HMAC), then
1183+ # set the default hmac setting to OFF.
1184+ # try to a 1.1.8 database. this should
1185+ # succeed now that hmac is off by default
1186+ # before the attach
1187+ do_test change-default-use-hmac-attach {
1188+ sqlite_orig db test.db
1189+ execsql {
1190+ PRAGMA key = 'testkey';
1191+ CREATE table t1(a,b);
1192+ INSERT INTO t1(a,b) VALUES (1,2);
1193+ }
1194+ db close
1195+ sqlite_orig db test.db
1196+ execsql {
1197+ PRAGMA key = 'testkey';
1198+ SELECT count(*) FROM t1;
1199+ PRAGMA cipher_default_use_hmac = OFF;
1200+ ATTACH 'sqlcipher-1.1.8-testkey.db' AS db2;
1201+ SELECT count(*) from db2.t1;
1202+ PRAGMA cipher_default_use_hmac = ON;
1203+ }
1204+ } {1 4}
1205+ db close
1206+ file delete -force test.db
1207+
11481208finish_test
0 commit comments