better-sqlite3-multiple-ciphers 7.5.1 → 7.5.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,10 +23,10 @@ The fastest and simplest library for SQLite3 in Node.js. This particular fork su
23
23
  - **SQLite3 Multiple Ciphers** - [`1.3.10`](https://github.com/utelle/SQLite3MultipleCiphers/releases/tag/v1.3.10)
24
24
 
25
25
  - ### Beta
26
- - **better-sqlite3-multiple-ciphers** - [`7.5.1-beta.3`](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/releases/tag/v7.5.1-beta.3)
27
- - **better-sqlite3** - [`7.5.0`](https://github.com/JoshuaWise/better-sqlite3/releases/tag/v7.5.0)
28
- - **SQLite** - [`3.38.1`](https://www.sqlite.org/draft/releaselog/3_38_1.html)
29
- - **SQLite3 Multiple Ciphers** - [`1.3.9`](https://github.com/utelle/SQLite3MultipleCiphers/releases/tag/v1.3.9)
26
+ - **better-sqlite3-multiple-ciphers** - [`7.5.2-beta.0`](https://github.com/m4heshd/better-sqlite3-multiple-ciphers/releases/tag/v7.5.2-beta.0)
27
+ - **better-sqlite3** - [`7.5.1`](https://github.com/JoshuaWise/better-sqlite3/releases/tag/v7.5.1)
28
+ - **SQLite** - [`3.38.2`](https://www.sqlite.org/draft/releaselog/3_38_2.html)
29
+ - **SQLite3 Multiple Ciphers** - [`1.4.1`](https://github.com/utelle/SQLite3MultipleCiphers/releases/tag/v1.4.1)
30
30
 
31
31
  ## Help this project stay strong! 💪
32
32
 
package/deps/setup.ps1 CHANGED
@@ -2,7 +2,7 @@
2
2
  $ErrorActionPreference = "Stop"
3
3
 
4
4
  # SQLite Info
5
- $SQLITEMC_VER = "v1.3.10"
5
+ $SQLITEMC_VER = "v1.4.1"
6
6
  $API_URL = "https://api.github.com/repos/utelle/SQLite3MultipleCiphers/releases/tags/" + $SQLITEMC_VER
7
7
 
8
8
  # Paths
@@ -239670,10 +239670,10 @@ SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
239670
239670
  #define SQLITE3MC_VERSION_H_
239671
239671
 
239672
239672
  #define SQLITE3MC_VERSION_MAJOR 1
239673
- #define SQLITE3MC_VERSION_MINOR 3
239674
- #define SQLITE3MC_VERSION_RELEASE 10
239673
+ #define SQLITE3MC_VERSION_MINOR 4
239674
+ #define SQLITE3MC_VERSION_RELEASE 0
239675
239675
  #define SQLITE3MC_VERSION_SUBRELEASE 0
239676
- #define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.3.10"
239676
+ #define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.4.0"
239677
239677
 
239678
239678
  #endif /* SQLITE3MC_VERSION_H_ */
239679
239679
  /*** End of #include "sqlite3mc_version.h" ***/
@@ -262581,7 +262581,7 @@ sqlite3mcHandleMainKey(sqlite3* db, const char* zPath)
262581
262581
  ** Purpose: Implementation of SQLite codec API
262582
262582
  ** Author: Ulrich Telle
262583
262583
  ** Created: 2006-12-06
262584
- ** Copyright: (c) 2006-2021 Ulrich Telle
262584
+ ** Copyright: (c) 2006-2022 Ulrich Telle
262585
262585
  ** License: MIT
262586
262586
  */
262587
262587
 
@@ -263049,7 +263049,7 @@ SQLITE_PRIVATE Codec*
263049
263049
  sqlite3mcGetMainCodec(sqlite3* db);
263050
263050
 
263051
263051
  SQLITE_PRIVATE void
263052
- sqlite3mcSetCodec(sqlite3* db, const char* zFileName, Codec* codec);
263052
+ sqlite3mcSetCodec(sqlite3* db, const char* zDbName, const char* zFileName, Codec* codec);
263053
263053
 
263054
263054
  static int
263055
263055
  mcAdjustBtree(Btree* pBt, int nPageSize, int nReserved, int isLegacy)
@@ -263111,7 +263111,7 @@ sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey,
263111
263111
  sqlite3mcSetBtree(codec, db->aDb[nDb].pBt);
263112
263112
  mcAdjustBtree(db->aDb[nDb].pBt, pageSize, reserved, sqlite3mcGetLegacyWriteCipher(codec));
263113
263113
  sqlite3mcCodecSizeChange(codec, pageSize, reserved);
263114
- sqlite3mcSetCodec(db, dbFileName, codec);
263114
+ sqlite3mcSetCodec(db, zDbName, dbFileName, codec);
263115
263115
  }
263116
263116
  else
263117
263117
  {
@@ -263132,7 +263132,7 @@ sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey,
263132
263132
  /* Remove codec for main database */
263133
263133
  if (nDb == 0 && nKey == 0)
263134
263134
  {
263135
- sqlite3mcSetCodec(db, dbFileName, NULL);
263135
+ sqlite3mcSetCodec(db, zDbName, dbFileName, NULL);
263136
263136
  }
263137
263137
  }
263138
263138
  }
@@ -263167,7 +263167,7 @@ sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey,
263167
263167
  int reserved = sqlite3mcGetReservedWriteCipher(codec);
263168
263168
  mcAdjustBtree(db->aDb[nDb].pBt, pageSize, reserved, sqlite3mcGetLegacyWriteCipher(codec));
263169
263169
  sqlite3mcCodecSizeChange(codec, pageSize, reserved);
263170
- sqlite3mcSetCodec(db, dbFileName, codec);
263170
+ sqlite3mcSetCodec(db, zDbName, dbFileName, codec);
263171
263171
  }
263172
263172
  else
263173
263173
  {
@@ -263314,7 +263314,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
263314
263314
  int nReservedWriteCipher;
263315
263315
  sqlite3mcSetHasReadCipher(codec, 0); /* Original database is not encrypted */
263316
263316
  mcAdjustBtree(pBt, sqlite3mcGetPageSizeWriteCipher(codec), sqlite3mcGetReservedWriteCipher(codec), sqlite3mcGetLegacyWriteCipher(codec));
263317
- sqlite3mcSetCodec(db, dbFileName, codec);
263317
+ sqlite3mcSetCodec(db, zDbName, dbFileName, codec);
263318
263318
  nReservedWriteCipher = sqlite3mcGetReservedWriteCipher(codec);
263319
263319
  sqlite3mcCodecSizeChange(codec, nPagesize, nReservedWriteCipher);
263320
263320
  if (nReserved != nReservedWriteCipher)
@@ -263465,7 +263465,7 @@ leave_rekey:
263465
263465
  if (!sqlite3mcIsEncrypted(codec))
263466
263466
  {
263467
263467
  /* Remove codec for unencrypted database */
263468
- sqlite3mcSetCodec(db, dbFileName, NULL);
263468
+ sqlite3mcSetCodec(db, zDbName, dbFileName, NULL);
263469
263469
  }
263470
263470
  return rc;
263471
263471
  }
@@ -273367,7 +273367,7 @@ int sqlite3_regexp_init(
273367
273367
  ** Purpose: Implementation of SQLite VFS for Multiple Ciphers
273368
273368
  ** Author: Ulrich Telle
273369
273369
  ** Created: 2020-02-28
273370
- ** Copyright: (c) 2020-2021 Ulrich Telle
273370
+ ** Copyright: (c) 2020-2022 Ulrich Telle
273371
273371
  ** License: MIT
273372
273372
  */
273373
273373
 
@@ -273396,6 +273396,7 @@ struct sqlite3mc_file
273396
273396
  {
273397
273397
  sqlite3_file base; /* sqlite3_file I/O methods */
273398
273398
  sqlite3_file* pFile; /* Real underlying OS file */
273399
+ sqlite3mc_vfs* pVfsMC; /* Pointer to the sqlite3mc_vfs object */
273399
273400
  const char* zFileName; /* File name */
273400
273401
  int openFlags; /* Open flags */
273401
273402
  sqlite3mc_file* pMainNext; /* Next main db file */
@@ -273418,9 +273419,6 @@ struct sqlite3mc_vfs
273418
273419
  #define REALVFS(p) ((sqlite3_vfs*)(((sqlite3mc_vfs*)(p))->base.pAppData))
273419
273420
  #define REALFILE(p) (((sqlite3mc_file*)(p))->pFile)
273420
273421
 
273421
- #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
273422
- #define ORIGFILE(p) ((sqlite3_file*)(((CksmFile*)(p))+1))
273423
-
273424
273422
  /*
273425
273423
  ** Prototypes for VFS methods
273426
273424
  */
@@ -273474,37 +273472,8 @@ static const int walFrameHeaderSize = 24;
273474
273472
  static const int walFileHeaderSize = 32;
273475
273473
 
273476
273474
  /*
273477
- ** Global VFS structure of SQLite3 Multiple Ciphers VFS
273475
+ ** Global I/O method structure of SQLite3 Multiple Ciphers VFS
273478
273476
  */
273479
- static sqlite3mc_vfs mcVfsGlobal =
273480
- {
273481
- {
273482
- 3, /* iVersion */
273483
- 0, /* szOsFile */
273484
- 1024, /* mxPathname */
273485
- 0, /* pNext */
273486
- SQLITE3MC_VFS_NAME, /* zName */
273487
- 0, /* pAppData */
273488
- mcVfsOpen, /* xOpen */
273489
- mcVfsDelete, /* xDelete */
273490
- mcVfsAccess, /* xAccess */
273491
- mcVfsFullPathname, /* xFullPathname */
273492
- mcVfsDlOpen, /* xDlOpen */
273493
- mcVfsDlError, /* xDlError */
273494
- mcVfsDlSym, /* xDlSym */
273495
- mcVfsDlClose, /* xDlClose */
273496
- mcVfsRandomness, /* xRandomness */
273497
- mcVfsSleep, /* xSleep */
273498
- mcVfsCurrentTime, /* xCurrentTime */
273499
- mcVfsGetLastError, /* xGetLastError */
273500
- mcVfsCurrentTimeInt64, /* xCurrentTimeInt64 */
273501
- mcVfsSetSystemCall, /* xSetSystemCall */
273502
- mcVfsGetSystemCall, /* xGetSystemCall */
273503
- mcVfsNextSystemCall /* xNextSystemCall */
273504
- },
273505
- NULL
273506
- };
273507
-
273508
273477
  static sqlite3_io_methods mcIoMethodsGlobal =
273509
273478
  {
273510
273479
  3, /* iVersion */
@@ -273538,10 +273507,10 @@ static sqlite3_io_methods mcIoMethodsGlobal =
273538
273507
  static void mcMainListAdd(sqlite3mc_file* pFile)
273539
273508
  {
273540
273509
  assert( (pFile->openFlags & SQLITE_OPEN_MAIN_DB) );
273541
- sqlite3_mutex_enter(mcVfsGlobal.mutex);
273542
- pFile->pMainNext = mcVfsGlobal.pMain;
273543
- mcVfsGlobal.pMain = pFile;
273544
- sqlite3_mutex_leave(mcVfsGlobal.mutex);
273510
+ sqlite3_mutex_enter(pFile->pVfsMC->mutex);
273511
+ pFile->pMainNext = pFile->pVfsMC->pMain;
273512
+ pFile->pVfsMC->pMain = pFile;
273513
+ sqlite3_mutex_leave(pFile->pVfsMC->mutex);
273545
273514
  }
273546
273515
 
273547
273516
  /*
@@ -273550,11 +273519,11 @@ static void mcMainListAdd(sqlite3mc_file* pFile)
273550
273519
  static void mcMainListRemove(sqlite3mc_file* pFile)
273551
273520
  {
273552
273521
  sqlite3mc_file** pMainPrev;
273553
- sqlite3_mutex_enter(mcVfsGlobal.mutex);
273554
- for (pMainPrev = &mcVfsGlobal.pMain; *pMainPrev && *pMainPrev != pFile; pMainPrev = &((*pMainPrev)->pMainNext)){}
273522
+ sqlite3_mutex_enter(pFile->pVfsMC->mutex);
273523
+ for (pMainPrev = &pFile->pVfsMC->pMain; *pMainPrev && *pMainPrev != pFile; pMainPrev = &((*pMainPrev)->pMainNext)){}
273555
273524
  if (*pMainPrev) *pMainPrev = pFile->pMainNext;
273556
273525
  pFile->pMainNext = 0;
273557
- sqlite3_mutex_leave(mcVfsGlobal.mutex);
273526
+ sqlite3_mutex_leave(pFile->pVfsMC->mutex);
273558
273527
  }
273559
273528
 
273560
273529
  /*
@@ -273572,6 +273541,51 @@ static sqlite3mc_file* mcFindDbMainFileName(sqlite3mc_vfs* mcVfs, const char* zF
273572
273541
  return pDb;
273573
273542
  }
273574
273543
 
273544
+ /*
273545
+ ** Find a pointer to the Multiple Ciphers VFS in use for a database connection.
273546
+ */
273547
+ static sqlite3mc_vfs* mcFindVfs(sqlite3* db, const char* zDbName)
273548
+ {
273549
+ sqlite3mc_vfs* pVfsMC = NULL;
273550
+ if (db->pVfs && db->pVfs->xOpen == mcVfsOpen)
273551
+ {
273552
+ /* The top level VFS is a Multiple Ciphers VFS */
273553
+ pVfsMC = (sqlite3mc_vfs*)(db->pVfs);
273554
+ }
273555
+ else
273556
+ {
273557
+ /*
273558
+ ** The top level VFS is not a Multiple Ciphers VFS.
273559
+ ** Retrieve the VFS names stack.
273560
+ */
273561
+ char* zVfsNameStack = 0;
273562
+ if ((sqlite3_file_control(db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsNameStack) == SQLITE_OK) && (zVfsNameStack != NULL))
273563
+ {
273564
+ /* Search for the name prefix of a Multiple Ciphers VFS. */
273565
+ char* zVfsName = strstr(zVfsNameStack, SQLITE3MC_VFS_NAME);
273566
+ if (zVfsName != NULL)
273567
+ {
273568
+ /* The prefix was found, now determine the full VFS name. */
273569
+ char* zVfsNameEnd = zVfsName + strlen(SQLITE3MC_VFS_NAME);
273570
+ if (*zVfsNameEnd == '-')
273571
+ {
273572
+ for (++zVfsNameEnd; *zVfsNameEnd != '/' && *zVfsNameEnd != 0; ++zVfsNameEnd);
273573
+ if (*zVfsNameEnd == '/') *zVfsNameEnd = 0;
273574
+
273575
+ /* Find a pointer to the VFS with the determined name. */
273576
+ sqlite3_vfs* pVfs = sqlite3_vfs_find(zVfsName);
273577
+ if (pVfs && pVfs->xOpen == mcVfsOpen)
273578
+ {
273579
+ pVfsMC = (sqlite3mc_vfs*) pVfs;
273580
+ }
273581
+ }
273582
+ }
273583
+ sqlite3_free(zVfsNameStack);
273584
+ }
273585
+ }
273586
+ return pVfsMC;
273587
+ }
273588
+
273575
273589
  /*
273576
273590
  ** Find the codec of the database file
273577
273591
  ** corresponding to the database schema name.
@@ -273579,11 +273593,16 @@ static sqlite3mc_file* mcFindDbMainFileName(sqlite3mc_vfs* mcVfs, const char* zF
273579
273593
  SQLITE_PRIVATE Codec* sqlite3mcGetCodec(sqlite3* db, const char* zDbName)
273580
273594
  {
273581
273595
  Codec* codec = NULL;
273582
- const char* dbFileName = sqlite3_db_filename(db, zDbName);
273583
- sqlite3mc_file* pDbMain = mcFindDbMainFileName(&mcVfsGlobal, dbFileName);
273584
- if (pDbMain)
273596
+ sqlite3mc_vfs* pVfsMC = mcFindVfs(db, zDbName);
273597
+
273598
+ if (pVfsMC)
273585
273599
  {
273586
- codec = pDbMain->codec;
273600
+ const char* dbFileName = sqlite3_db_filename(db, zDbName);
273601
+ sqlite3mc_file* pDbMain = mcFindDbMainFileName(pVfsMC, dbFileName);
273602
+ if (pDbMain)
273603
+ {
273604
+ codec = pDbMain->codec;
273605
+ }
273587
273606
  }
273588
273607
  return codec;
273589
273608
  }
@@ -273606,9 +273625,14 @@ SQLITE_PRIVATE Codec* sqlite3mcGetMainCodec(sqlite3* db)
273606
273625
  ** connection handle is actually valid, because the association between
273607
273626
  ** connection handles and database file handles is not maintained properly.
273608
273627
  */
273609
- SQLITE_PRIVATE void sqlite3mcSetCodec(sqlite3* db, const char* zFileName, Codec* codec)
273628
+ SQLITE_PRIVATE void sqlite3mcSetCodec(sqlite3* db, const char* zDbName, const char* zFileName, Codec* codec)
273610
273629
  {
273611
- sqlite3mc_file* pDbMain = mcFindDbMainFileName(&mcVfsGlobal, zFileName);
273630
+ sqlite3mc_file* pDbMain = NULL;
273631
+ sqlite3mc_vfs* pVfsMC = mcFindVfs(db, zDbName);
273632
+ if (pVfsMC)
273633
+ {
273634
+ pDbMain = mcFindDbMainFileName((sqlite3mc_vfs*)(db->pVfs), zFileName);
273635
+ }
273612
273636
  if (pDbMain)
273613
273637
  {
273614
273638
  Codec* prevCodec = pDbMain->codec;
@@ -273677,6 +273701,7 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
273677
273701
  sqlite3mc_vfs* mcVfs = (sqlite3mc_vfs*) pVfs;
273678
273702
  sqlite3mc_file* mcFile = (sqlite3mc_file*) pFile;
273679
273703
  mcFile->pFile = (sqlite3_file*) &mcFile[1];
273704
+ mcFile->pVfsMC = mcVfs;
273680
273705
  mcFile->openFlags = flags;
273681
273706
  mcFile->zFileName = zName;
273682
273707
  mcFile->codec = 0;
@@ -273707,7 +273732,7 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
273707
273732
  else if (flags & SQLITE_OPEN_MAIN_JOURNAL)
273708
273733
  {
273709
273734
  const char* dbFileName = sqlite3_filename_database(zName);
273710
- mcFile->pMainDb = mcFindDbMainFileName(&mcVfsGlobal, dbFileName);
273735
+ mcFile->pMainDb = mcFindDbMainFileName(mcFile->pVfsMC, dbFileName);
273711
273736
  mcFile->zFileName = zName;
273712
273737
  SQLITE3MC_DEBUG_LOG("mcVfsOpen MAIN Journal: mcFile=%p fileName=%s dbFileName=%s\n", mcFile, mcFile->zFileName, dbFileName);
273713
273738
  }
@@ -273722,7 +273747,7 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
273722
273747
  else if (flags & SQLITE_OPEN_SUBJOURNAL)
273723
273748
  {
273724
273749
  const char* dbFileName = sqlite3_filename_database(zName);
273725
- mcFile->pMainDb = mcFindDbMainFileName(&mcVfsGlobal, dbFileName);
273750
+ mcFile->pMainDb = mcFindDbMainFileName(mcFile->pVfsMC, dbFileName);
273726
273751
  mcFile->zFileName = zName;
273727
273752
  SQLITE3MC_DEBUG_LOG("mcVfsOpen SUB Journal: mcFile=%p fileName=%s dbFileName=%s\n", mcFile, mcFile->zFileName, dbFileName);
273728
273753
  }
@@ -273738,7 +273763,7 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
273738
273763
  else if (flags & SQLITE_OPEN_WAL)
273739
273764
  {
273740
273765
  const char* dbFileName = sqlite3_filename_database(zName);
273741
- mcFile->pMainDb = mcFindDbMainFileName(&mcVfsGlobal, dbFileName);
273766
+ mcFile->pMainDb = mcFindDbMainFileName(mcFile->pVfsMC, dbFileName);
273742
273767
  mcFile->zFileName = zName;
273743
273768
  SQLITE3MC_DEBUG_LOG("mcVfsOpen WAL Journal: mcFile=%p fileName=%s dbFileName=%s\n", mcFile, mcFile->zFileName, dbFileName);
273744
273769
  }
@@ -273860,7 +273885,7 @@ static int mcIoClose(sqlite3_file* pFile)
273860
273885
  p->codec = 0;
273861
273886
  }
273862
273887
 
273863
- assert(p->pMainNext == 0 && mcVfsGlobal.pMain != p);
273888
+ assert(p->pMainNext == 0 && p->pVfsMC->pMain != p);
273864
273889
  rc = REALFILE(pFile)->pMethods->xClose(REALFILE(pFile));
273865
273890
  return rc;
273866
273891
  }
@@ -274522,6 +274547,14 @@ static int mcIoFileControl(sqlite3_file* pFile, int op, void* pArg)
274522
274547
  if (doReal)
274523
274548
  {
274524
274549
  rc = REALFILE(pFile)->pMethods->xFileControl(REALFILE(pFile), op, pArg);
274550
+ if (rc == SQLITE_OK && op == SQLITE_FCNTL_VFSNAME)
274551
+ {
274552
+ sqlite3mc_vfs* pVfsMC = p->pVfsMC;
274553
+ char* zIn = *(char**)pArg;
274554
+ char* zOut = sqlite3_mprintf("%s/%z", pVfsMC->base.zName, zIn);
274555
+ *(char**)pArg = zOut;
274556
+ if (zOut == 0) rc = SQLITE_NOMEM;
274557
+ }
274525
274558
  }
274526
274559
  return rc;
274527
274560
  }
@@ -30,10 +30,10 @@
30
30
  #define SQLITE3MC_VERSION_H_
31
31
 
32
32
  #define SQLITE3MC_VERSION_MAJOR 1
33
- #define SQLITE3MC_VERSION_MINOR 3
34
- #define SQLITE3MC_VERSION_RELEASE 10
33
+ #define SQLITE3MC_VERSION_MINOR 4
34
+ #define SQLITE3MC_VERSION_RELEASE 0
35
35
  #define SQLITE3MC_VERSION_SUBRELEASE 0
36
- #define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.3.10"
36
+ #define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.4.0"
37
37
 
38
38
  #endif /* SQLITE3MC_VERSION_H_ */
39
39
  /*** End of #include "sqlite3mc_version.h" ***/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-sqlite3-multiple-ciphers",
3
- "version": "7.5.1",
3
+ "version": "7.5.2-beta.0",
4
4
  "description": "better-sqlite3 with multiple-cipher encryption support",
5
5
  "homepage": "https://github.com/m4heshd/better-sqlite3-multiple-ciphers",
6
6
  "author": "Mahesh Bandara Wijerathna (m4heshd) <m4heshd@gmail.com>",