8000 Merge branch 'attach' into kdfiter · githubzhaoliang/sqlcipher@cfee6c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit cfee6c2

Browse files
Merge branch 'attach' into kdfiter
Conflicts: test/crypto.test
2 parents 81e487a + 6f4a0f2 commit cfee6c2

File tree

4 files changed

+405
-39
lines changed

4 files changed

+405
-39
lines changed

src/crypto.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ int codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLeft, const c
8989

9090
CODEC_TRACE(("codec_pragma: entered db=%p iDb=%d pParse=%p zLeft=%s zRight=%s ctx=%p\n", db, iDb, pParse, zLeft, zRight, ctx));
9191

92+
if( sqlite3StrICmp(zLeft, "cipher_migrate")==0 && !zRight ){
93+
if(ctx){
94+
char *migrate_status = sqlite3_mprintf("%d", sqlcipher_codec_ctx_migrate(ctx));
95+
codec_vdbe_return_static_string(pParse, "sqlcipher_migrate", migrate_status);
96+
sqlite3_free(migrate_status);
97+
}
98+
} else
9299
if( sqlite3StrICmp(zLeft, "cipher_provider")==0 && !zRight ){
93100
if(ctx) { codec_vdbe_return_static_string(pParse, "cipher_provider",
94101
sqlcipher_codec_get_cipher_provider(ctx));
@@ -421,13 +428,11 @@ int sqlite3_rekey(sqlite3 *db, const void *pKey, int nKey) {
421428
void sqlite3CodecGetKey(sqlite3* db, int nDb, void **zKey, int *nKey) {
422429
struct Db *pDb = &db->aDb[nDb];
423430
CODEC_TRACE(("sqlite3CodecGetKey: entered db=%p, nDb=%d\n", db, nDb));
424-
425431
if( pDb->pBt ) {
426432
codec_ctx *ctx;
427433
sqlite3pager_get_codec(pDb->pBt->pBt->pPager, (void **) &ctx);
428-
429434
if(ctx) { /* if the codec has an attached codec_context user the raw key data */
430-
sqlcipher_codec_get_pass(ctx, zKey, nKey);
435+
sqlcipher_codec_get_keyspec(ctx, zKey, nKey);
431436
} else {
432437
*zKey = NULL;
433438
*nKey = 0;

src/crypto.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ static void cipher_hex2bin(const char *hex, int sz, unsigned char *out){
149149
}
150150
}
151151

152+
static void cipher_bin2hex(const unsigned char* in, int sz, char *out) {
153+
int i;
154+
for(i=0; i < sz; i++) {
155+
sprintf(out + (i*2), "%02x ", in[i]);
156+
}
157+
}
158+
152159
/* extensions defined in crypto_impl.c */
153160
typedef struct codec_ctx codec_ctx;
154161

@@ -167,7 +174,7 @@ int sqlcipher_page_cipher(codec_ctx *, int, Pgno, int, int, unsigned char *, uns
167174
void sqlcipher_codec_ctx_set_error(codec_ctx *, int);
168175

169176
int sqlcipher_codec_ctx_set_pass(codec_ctx *, const void *, int, int);
170-
void sqlcipher_codec_get_pass(codec_ctx *, void **zKey, int *nKey);
177+
void sqlcipher_codec_get_keyspec(codec_ctx *, void **zKey, int *nKey);
171178

172179
int sqlcipher_codec_ctx_set_pagesize(codec_ctx *, int);
173180
int sqlcipher_codec_ctx_get_pagesize(codec_ctx *);
@@ -205,6 +212,7 @@ int sqlcipher_codec_ctx_unset_flag(codec_ctx *ctx, unsigned int flag);
205212
int sqlcipher_codec_ctx_get_flag(codec_ctx *ctx, unsigned int flag, int for_ctx);
206213

207214
const char* sqlcipher_codec_get_cipher_provider(codec_ctx *ctx);
215+
int sqlcipher_codec_ctx_migrate(codec_ctx *ctx);
208216
#endif
209217
#endif
210218
/* END SQLCIPHER */

0 commit comments

Comments
 (0)
0