Adding get support to PRAGMA cipher_use_hmac

This commit is contained in:
Nick Parker 2012-11-06 11:41:59 -06:00
parent 6eb69e384a
commit 9a9873b933
2 changed files with 21 additions and 6 deletions

View File

@ -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 ){

View File

@ -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;