From 361a9ad7d7bed1c96fba68f258bb11e2733bd75b Mon Sep 17 00:00:00 2001 From: Caleb Albritton Date: Fri, 1 Jun 2018 12:34:14 -0400 Subject: [PATCH 1/7] --with-sqlcipher flag --- ext/.DS_Store | Bin 0 -> 6148 bytes ext/sqlite3/extconf.rb | 7 ++++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 ext/.DS_Store diff --git a/ext/.DS_Store b/ext/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8c6c3d2ffe5042b8fccd5674086cca75a46bcc7b GIT binary patch literal 6148 zcmeHK!AiqG5S^`66GZGmsK;Cc4+<5<9z+OL58i}`9#k~3MFTObO={6v$!F*v`3HWE z&dhE_tsWJX8JK;O*_qw!+pwDf0M+O;7Xc~&;GhzgTx>oO>L(qNlJ$%rDjp+;7A$Qg z`Xow*qQ&tW8KAuzhYT(uff(NGpN_DHK8sb9$;E9eZ)n0F9xi;@D)cW(DG3)huzwbKL*~PW3?YspGL~@EczA;gV=+jOe&&DRkp-XCLR5rjq@!Q22DCB zTYM-xv$7S6;@NS0kHbOv2Bj4Sgn{=AQ0<3Oq5FUH>-wLAq!9*$f&a;XDsKcE4P2YO zTZdLjcddtdj7marg~8VpH25mUSh|X5P+8FLk%8!2EDWLtMScXB25E$WA7$VL(KTK} literal 0 HcmV?d00001 diff --git a/ext/sqlite3/extconf.rb b/ext/sqlite3/extconf.rb index 3fafa8d3..44890448 100644 --- a/ext/sqlite3/extconf.rb +++ b/ext/sqlite3/extconf.rb @@ -49,7 +49,12 @@ def asplode missing asplode('sqlite3.h') unless find_header 'sqlite3.h' find_library 'pthread', 'pthread_create' # 1.8 support. *shrug* -asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number' + +if with_config('sqlcipher') + asplode('sqlcipher') unless find_library 'sqlcipher', 'sqlite3_libversion_number' +else + asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number' +end # Functions defined in 1.9 but not 1.8 have_func('rb_proc_arity') From 25a2f40a3926aeceb19dde898379d361a30cac7a Mon Sep 17 00:00:00 2001 From: Caleb Albritton Date: Tue, 5 Jun 2018 22:36:22 -0400 Subject: [PATCH 2/7] semiworking --- ext/sqlite3/extconf.rb | 29 +++++++++++++++++++++-------- ext/sqlite3/sqlite3.c | 7 ++++++- test/test_sqlcipher.rb | 9 +++++++++ 3 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 test/test_sqlcipher.rb diff --git a/ext/sqlite3/extconf.rb b/ext/sqlite3/extconf.rb index 44890448..9a73d54d 100644 --- a/ext/sqlite3/extconf.rb +++ b/ext/sqlite3/extconf.rb @@ -6,15 +6,20 @@ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC'] - - ldflags = cppflags = nil if RbConfig::CONFIG["host_os"] =~ /darwin/ begin - brew_prefix = `brew --prefix sqlite3`.chomp - ldflags = "#{brew_prefix}/lib" - cppflags = "#{brew_prefix}/include" - pkg_conf = "#{brew_prefix}/lib/pkgconfig" + if with_config('sqlcipher') + brew_prefix = `brew --prefix sqlcipher`.chomp + ldflags = "#{brew_prefix}/lib" + cppflags = "#{brew_prefix}/include/sqlcipher" + pkg_conf = "#{brew_prefix}/lib/pkgconfig" + else + brew_prefix = `brew --prefix sqlite3`.chomp + ldflags = "#{brew_prefix}/lib" + cppflags = "#{brew_prefix}/include" + pkg_conf = "#{brew_prefix}/lib/pkgconfig" + end # pkg_config should be less error prone than parsing compiler # commandline options, but we need to set default ldflags and cpp flags @@ -24,10 +29,18 @@ end end -pkg_config("sqlite3") +if with_config('sqlcipher') + pkg_config("sqlcipher") +else + pkg_config("sqlite3") +end # --with-sqlite3-{dir,include,lib} -dir_config("sqlite3", cppflags, ldflags) +if with_config('sqlcipher') + dir_config("sqlcipher", cppflags, ldflags) +else + dir_config("sqlite3", cppflags, ldflags) +end if RbConfig::CONFIG["host_os"] =~ /mswin/ $CFLAGS << ' -W3' diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index dedfdf5d..e8999f60 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -65,6 +65,11 @@ static VALUE libversion(VALUE UNUSED(klass)) return INT2NUM(sqlite3_libversion_number()); } +static VALUE cipherversion(VALUE UNUSED(klass)) +{ + return rb_str_new2(codec_get_cipher_version()); +} + /* Returns the compile time setting of the SQLITE_THREADSAFE flag. * See: https://www.sqlite.org/c3ref/threadsafe.html */ @@ -144,7 +149,7 @@ void Init_sqlite3_native() #ifdef HAVE_SQLITE3_BACKUP_INIT init_sqlite3_backup(); #endif - + rb_define_singleton_method(mSqlite3, "cipherversion", cipherversion, 0); rb_define_singleton_method(mSqlite3, "libversion", libversion, 0); rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0); rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION)); diff --git a/test/test_sqlcipher.rb b/test/test_sqlcipher.rb new file mode 100644 index 00000000..18913b6d --- /dev/null +++ b/test/test_sqlcipher.rb @@ -0,0 +1,9 @@ +require 'helper' + +module SQLite3 + class TestSQLite3 < SQLite3::TestCase + def test_cypherversion + assert_not_nil SQLite3.cipherversion + end + end +end From f37ef3c3684a9459d75ab036919f2d6afa68c7f4 Mon Sep 17 00:00:00 2001 From: Caleb Albritton Date: Tue, 5 Jun 2018 22:39:52 -0400 Subject: [PATCH 3/7] check for a function in sqlcipher --- ext/sqlite3/extconf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/sqlite3/extconf.rb b/ext/sqlite3/extconf.rb index 9a73d54d..27e0f56c 100644 --- a/ext/sqlite3/extconf.rb +++ b/ext/sqlite3/extconf.rb @@ -64,7 +64,7 @@ def asplode missing find_library 'pthread', 'pthread_create' # 1.8 support. *shrug* if with_config('sqlcipher') - asplode('sqlcipher') unless find_library 'sqlcipher', 'sqlite3_libversion_number' + asplode('sqlcipher') unless find_library 'sqlcipher', 'codec_get_cipher_version' else asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number' end From 7c7be16af7f68961b0d592951919a178b3e264e4 Mon Sep 17 00:00:00 2001 From: Caleb Albritton Date: Tue, 5 Jun 2018 22:43:17 -0400 Subject: [PATCH 4/7] only add cipherversion if using sqlcipher --- ext/sqlite3/sqlite3.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index e8999f60..0007e4a0 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -65,10 +65,12 @@ static VALUE libversion(VALUE UNUSED(klass)) return INT2NUM(sqlite3_libversion_number()); } +#ifdef CIPHER_VERSION static VALUE cipherversion(VALUE UNUSED(klass)) { return rb_str_new2(codec_get_cipher_version()); } +#endif /* Returns the compile time setting of the SQLITE_THREADSAFE flag. * See: https://www.sqlite.org/c3ref/threadsafe.html @@ -149,7 +151,9 @@ void Init_sqlite3_native() #ifdef HAVE_SQLITE3_BACKUP_INIT init_sqlite3_backup(); #endif +#ifdef CIPHER_VERSION rb_define_singleton_method(mSqlite3, "cipherversion", cipherversion, 0); +#endif rb_define_singleton_method(mSqlite3, "libversion", libversion, 0); rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0); rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION)); From 3fd6dda1986dcd1e007772ecf860a365452adb0b Mon Sep 17 00:00:00 2001 From: Caleb Albritton Date: Tue, 5 Jun 2018 22:59:57 -0400 Subject: [PATCH 5/7] sqlcipher needs SQLITE_HAS_CODE and SQLITE_TEMP_STORE --- ext/sqlite3/extconf.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/sqlite3/extconf.rb b/ext/sqlite3/extconf.rb index 27e0f56c..b566a0ac 100644 --- a/ext/sqlite3/extconf.rb +++ b/ext/sqlite3/extconf.rb @@ -21,6 +21,8 @@ pkg_conf = "#{brew_prefix}/lib/pkgconfig" end + # SQLITE_HAS_CODEC + # pkg_config should be less error prone than parsing compiler # commandline options, but we need to set default ldflags and cpp flags # in case the user doesn't have pkg-config installed @@ -38,6 +40,7 @@ # --with-sqlite3-{dir,include,lib} if with_config('sqlcipher') dir_config("sqlcipher", cppflags, ldflags) + $CFLAGS << ' -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2' else dir_config("sqlite3", cppflags, ldflags) end From 16e4ee8775113d9a07c5a145c86dd98554430872 Mon Sep 17 00:00:00 2001 From: Caleb Albritton Date: Tue, 5 Jun 2018 23:51:58 -0400 Subject: [PATCH 6/7] added automatic support for and an eh? method for sqlcipher --- ext/sqlite3/extconf.rb | 4 ++-- ext/sqlite3/sqlite3.c | 14 +++++++------- test/test_sqlcipher.rb | 9 --------- 3 files changed, 9 insertions(+), 18 deletions(-) delete mode 100644 test/test_sqlcipher.rb diff --git a/ext/sqlite3/extconf.rb b/ext/sqlite3/extconf.rb index b566a0ac..59ddda90 100644 --- a/ext/sqlite3/extconf.rb +++ b/ext/sqlite3/extconf.rb @@ -39,8 +39,8 @@ # --with-sqlite3-{dir,include,lib} if with_config('sqlcipher') + $CFLAGS << ' -DUSING_SQLCIPHER' dir_config("sqlcipher", cppflags, ldflags) - $CFLAGS << ' -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2' else dir_config("sqlite3", cppflags, ldflags) end @@ -67,7 +67,7 @@ def asplode missing find_library 'pthread', 'pthread_create' # 1.8 support. *shrug* if with_config('sqlcipher') - asplode('sqlcipher') unless find_library 'sqlcipher', 'codec_get_cipher_version' + asplode('sqlcipher') unless find_library 'sqlcipher', 'sqlite3_libversion_number' else asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number' end diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 0007e4a0..ede81ea6 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -65,12 +65,14 @@ static VALUE libversion(VALUE UNUSED(klass)) return INT2NUM(sqlite3_libversion_number()); } -#ifdef CIPHER_VERSION -static VALUE cipherversion(VALUE UNUSED(klass)) +static VALUE using_sqlcipher(VALUE UNUSED(klass)) { - return rb_str_new2(codec_get_cipher_version()); -} +#ifdef USING_SQLCIPHER + return Qtrue; +#else + return Qfalse; #endif +} /* Returns the compile time setting of the SQLITE_THREADSAFE flag. * See: https://www.sqlite.org/c3ref/threadsafe.html @@ -151,9 +153,7 @@ void Init_sqlite3_native() #ifdef HAVE_SQLITE3_BACKUP_INIT init_sqlite3_backup(); #endif -#ifdef CIPHER_VERSION - rb_define_singleton_method(mSqlite3, "cipherversion", cipherversion, 0); -#endif + rb_define_singleton_method(mSqlite3, "sqlcipher?", using_sqlcipher, 0); rb_define_singleton_method(mSqlite3, "libversion", libversion, 0); rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0); rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION)); diff --git a/test/test_sqlcipher.rb b/test/test_sqlcipher.rb deleted file mode 100644 index 18913b6d..00000000 --- a/test/test_sqlcipher.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'helper' - -module SQLite3 - class TestSQLite3 < SQLite3::TestCase - def test_cypherversion - assert_not_nil SQLite3.cipherversion - end - end -end From 75aaafedf1b78c92f110b33b37c3297f1c6dbe3f Mon Sep 17 00:00:00 2001 From: Caleb Albritton Date: Tue, 5 Jun 2018 23:55:52 -0400 Subject: [PATCH 7/7] extraneous comment --- ext/sqlite3/extconf.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/ext/sqlite3/extconf.rb b/ext/sqlite3/extconf.rb index 59ddda90..bdd56995 100644 --- a/ext/sqlite3/extconf.rb +++ b/ext/sqlite3/extconf.rb @@ -21,8 +21,6 @@ pkg_conf = "#{brew_prefix}/lib/pkgconfig" end - # SQLITE_HAS_CODEC - # pkg_config should be less error prone than parsing compiler # commandline options, but we need to set default ldflags and cpp flags # in case the user doesn't have pkg-config installed