1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Minor cleanups to [8fbda563d2f5].

FossilOrigin-Name: 5ee2594b657b96aea9e482a175820dcbacfa9298da45b38cf17f39ad076d3f7f
This commit is contained in:
stephan
2024-04-22 17:03:52 +00:00
parent 0a42e9913b
commit 5d8daf184d
4 changed files with 25 additions and 13 deletions

View File

@ -87,6 +87,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
*/
const __vfsPostOpenSql = Object.create(null);
//#if enable-see
/**
Converts ArrayBuffer or Uint8Array ba into a string of hex
digits.
@ -103,7 +104,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
return li.join('');
};
//#if enable-see
/**
Internal helper to apply an SEE key to a just-opened
database. Requires that db be-a DB object which has just been
@ -160,7 +160,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
}else if('string'!==typeof key){
toss3("Invalid value for the 'hexkey' option. Expecting a string, ArrayBuffer, or Uint8Array.");
}
/* else assume it's valid hex codes */;
/* else assume it's valid hex codes */
}else{
return;
}
@ -385,7 +385,13 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
- `key`, `hexkey`, or `textkey`: encryption key as a string,
ArrayBuffer, or Uint8Array. These flags function as documented
for the SEE pragmas of the same names.
for the SEE pragmas of the same names. Using a byte array for
`hexkey` is equivalent to the same series of hex codes in
string form, so '666f6f' is equivalent to
Uint8Array([0x66,0x6f,0x6f]). A `textkey` byte array is assumed
to be UTF-8. A `key` string is transformed into a UTF-8 byte
array, and a `key` byte array is transformed into a `hexkey`
with the same bytes.
In non-SEE builds, these options are ignored. In SEE builds,
`PRAGMA key/textkey/hexkey=X` is executed immediately after

View File

@ -2613,10 +2613,16 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
test: function(sqlite3){
this.kvvfsUnlink();
let db;
const encOpt1 = 1
? {textkey: 'foo'}
: {key: 'foo'};
const encOpt2 = encOpt1.textkey
? encOpt1
: {hexkey: new Uint8Array([0x66,0x6f,0x6f]/*==>"foo"*/)}
try{
db = new this.JDb({
filename: this.kvvfsDbFile,
key: 'foo'
...encOpt1
});
db.exec([
"create table t(a,b);",
@ -2643,7 +2649,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
db = new sqlite3.oo1.DB({
filename: this.kvvfsDbFile,
vfs: 'kvvfs',
hexkey: new Uint8Array([0x66,0x6f,0x6f]) // equivalent: '666f6f'
...encOpt2
});
T.assert( 4===db.selectValue('select sum(a) from t') );
}finally{