diff --git a/src/crypto.c b/src/crypto.c index 787311b..830f062 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -130,12 +130,17 @@ int codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLeft, const c sqlcipher_set_default_use_hmac(sqlite3GetBoolean(zRight,1)); }else if( sqlite3StrICmp(zLeft,"cipher_use_hmac")==0 ){ - if(ctx) { - rc = sqlcipher_codec_ctx_set_use_hmac(ctx, sqlite3GetBoolean(zRight,1)); - if(rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, rc); - /* since the use of hmac has changed, the page size may also change */ - rc = codec_set_btree_to_codec_pagesize(db, pDb, ctx); - if(rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, rc); + + if( zRight ) { + if(ctx) { + rc = sqlcipher_codec_ctx_set_use_hmac(ctx, sqlite3GetBoolean(zRight,1)); + if(rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, rc); + /* since the use of hmac has changed, the page size may also change */ + rc = codec_set_btree_to_codec_pagesize(db, pDb, ctx); + if(rc != SQLITE_OK) sqlcipher_codec_ctx_set_error(ctx, rc); + } + } else { + if(ctx) sqlcipher_codec_ctx_get_use_hmac(pParse, ctx, 2); } }else if( sqlite3StrICmp(zLeft,"cipher_hmac_pgno")==0 ){ diff --git a/src/crypto_impl.c b/src/crypto_impl.c index a3bb954..291d1c3 100644 --- a/src/crypto_impl.c +++ b/src/crypto_impl.c @@ -422,6 +422,16 @@ int sqlcipher_codec_ctx_set_use_hmac(codec_ctx *ctx, int use) { return SQLITE_OK; } +int sqlcipher_codec_ctx_get_use_hmac(Parse *pParse, codec_ctx *ctx, int for_ctx) { + cipher_ctx * c_ctx = for_ctx ? ctx->write_ctx : ctx->read_ctx; + int hmac_flag_set = c_ctx->flags & CIPHER_FLAG_HMAC > 0; + char *hmac_flag = sqlite3_mprintf("%d", hmac_flag_set); + codec_vdbe_return_static_string(pParse, "cipher_use_hmac", hmac_flag); + sqlite3_free(hmac_flag); + + return SQLITE_OK; +} + int sqlcipher_codec_ctx_set_flag(codec_ctx *ctx, unsigned int flag) { ctx->write_ctx->flags |= flag; ctx->read_ctx->flags |= flag;