Skip to content

Commit

Permalink
report SQLCipher version alongside SQLite version in shell
Browse files Browse the repository at this point in the history
  • Loading branch information
sjlombardo committed Apr 22, 2020
1 parent 94e4c45 commit 299fe42
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
7 changes: 1 addition & 6 deletions src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,7 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
}
} else
if( sqlite3StrICmp(zLeft, "cipher_version")==0 && !zRight ){
#ifdef CIPHER_VERSION_QUALIFIER
char *version = sqlite3_mprintf("%s %s %s", CIPHER_XSTR(CIPHER_VERSION_NUMBER), CIPHER_XSTR(CIPHER_VERSION_QUALIFIER), CIPHER_XSTR(CIPHER_VERSION_BUILD));
#else
char *version = sqlite3_mprintf("%s %s", CIPHER_XSTR(CIPHER_VERSION_NUMBER), CIPHER_XSTR(CIPHER_VERSION_BUILD));
#endif
codec_vdbe_return_string(pParse, "cipher_version", version, P4_DYNAMIC);
codec_vdbe_return_string(pParse, "cipher_version", sqlcipher_version(), P4_DYNAMIC);
}else
if( sqlite3StrICmp(zLeft, "cipher")==0 ){
if(ctx) {
Expand Down
9 changes: 9 additions & 0 deletions src/crypto_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,15 @@ void* sqlcipher_malloc(int sz) {
return ptr;
}

char* sqlcipher_version() {
#ifdef CIPHER_VERSION_QUALIFIER
char *version = sqlite3_mprintf("%s %s %s", CIPHER_XSTR(CIPHER_VERSION_NUMBER), CIPHER_XSTR(CIPHER_VERSION_QUALIFIER), CIPHER_XSTR(CIPHER_VERSION_BUILD));
#else
char *version = sqlite3_mprintf("%s %s", CIPHER_XSTR(CIPHER_VERSION_NUMBER), CIPHER_XSTR(CIPHER_VERSION_BUILD));
#endif
return version;
}

/**
* Initialize new cipher_ctx struct. This function will allocate memory
* for the cipher context and for the key
Expand Down
36 changes: 32 additions & 4 deletions src/shell.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -9523,6 +9523,16 @@ static int do_meta_command(char *zLine, ShellState *p){
if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
utf8_printf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
sqlite3_libversion(), sqlite3_sourceid());
/* BEGIN SQLCIPHER */
#ifdef SQLITE_HAS_CODEC
{
extern char* sqlcipher_version();
char *sqlcipher_ver = sqlcipher_version();
utf8_printf(p->out, "SQLCipher %s\n", sqlcipher_ver);
sqlite3_free(sqlcipher_ver);
}
#endif
/* END SQLCIPHER */
#if SQLITE_HAVE_ZLIB
utf8_printf(p->out, "zlib version %s\n", zlibVersion());
#endif
Expand Down Expand Up @@ -10416,7 +10426,17 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
}else if( strcmp(z,"-bail")==0 ){
bail_on_error = 1;
}else if( strcmp(z,"-version")==0 ){
/* BEGIN SQLCIPHER */
#ifdef SQLITE_HAS_CODEC
extern char* sqlcipher_version();
char *sqlcipher_ver = sqlcipher_version();
printf("%s %s", sqlite3_libversion(), sqlite3_sourceid());
printf(" (SQLCipher %s)\n", sqlcipher_ver);
sqlite3_free(sqlcipher_ver);
#else
printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
#endif
/* BEGIN SQLCIPHER */
return 0;
}else if( strcmp(z,"-interactive")==0 ){
stdin_is_interactive = 1;
Expand Down Expand Up @@ -10523,17 +10543,25 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
char *zHome;
char *zHistory;
int nHistory;
printf(
/* BEGIN SQLCIPHER */
#ifdef SQLITE_HAS_CODEC
"SQLCipher version %s %.19s\n" /*extra-version-info*/
extern char* sqlcipher_version();
char *sqlcipher_ver = sqlcipher_version();
printf(
"SQLite version %s %.19s" /*extra-version-info*/
" (SQLCipher %s)\n" /*sqlcipher version info*/
"Enter \".help\" for usage hints.\n",
sqlite3_libversion(), sqlite3_sourceid(), sqlcipher_ver
);
sqlite3_free(sqlcipher_ver);
#else
printf(
"SQLite version %s %.19s\n" /*extra-version-info*/
#endif
/* END SQLCIPHER */
"Enter \".help\" for usage hints.\n",
sqlite3_libversion(), sqlite3_sourceid()
);
#endif
/* END SQLCIPHER */
if( warnInmemoryDb ){
printf("Connected to a ");
printBold("transient in-memory database");
Expand Down
1 change: 1 addition & 0 deletions src/sqlcipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void* sqlcipher_memset(void *, unsigned char, int);
int sqlcipher_ismemset(const void *, unsigned char, int);
int sqlcipher_memcmp(const void *, const void *, int);
void sqlcipher_free(void *, int);
char* sqlcipher_version();

/* provider interfaces */
int sqlcipher_register_provider(sqlcipher_provider *);
Expand Down

0 comments on commit 299fe42

Please sign in to comment.