Skip to content

Commit 493cff0

Browse files
authored
Upgrade to lru-cache 11. (#32)
1 parent 4be6c67 commit 493cff0

15 files changed

Lines changed: 146 additions & 82 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ First: this library only makes sense if your clients sit behind a firewall, or i
66

77
This library monkey-patches either the Firebase Admin SDK or the Firebase JavaScript Client SDK to automatically encrypt and decrypt keys and values of your choosing using AES-SIV, and to compress encrypted string values. Almost everything just works, except that `startAt` and `endAt` queries on encrypted data would produce randomly ordered results and so are forbidden. `equalTo` queries will work fine, however, since a given plaintext value will always encrypt to the same ciphertext — but it will also let an attacker know if any two values are equal, even if they don't know what they are.
88

9-
The library works both in Node (20.x+) and in the browser. In the browser, you need to also load [`crypto-js`](https://github.com/brix/crypto-js) (the following modules are sufficient: `core.js`, `lib-typedarrays.js`, `enc-base64.js`, `enc-base64url.js`, `sha1.js`, `md5.js`, `evpkdf.js`, `cipher-core.js`, `aes.js`, `mode-ctr.js`) and [`cryptojs-extension`](https://github.com/artjomb/cryptojs-extension) (only `build/siv.js` is required). If you want to enable caching to enhance performance, then in the browser you'll also want to load [`node-lru-cache`](https://github.com/isaacs/node-lru-cache). All these libraries are automatically included in the Node distribution.
9+
The library works both in Node (20.x+) and in the browser. In the browser, you need to also load [`crypto-js`](https://github.com/brix/crypto-js) (the following modules are sufficient: `core.js`, `lib-typedarrays.js`, `enc-base64.js`, `enc-base64url.js`, `sha1.js`, `md5.js`, `evpkdf.js`, `cipher-core.js`, `aes.js`, `mode-ctr.js`) and [`cryptojs-extension`](https://github.com/artjomb/cryptojs-extension) (only `build/siv.js` is required). If you want to enable caching to enhance performance, then in the browser you'll also want to load [`lru-cache`](https://github.com/isaacs/node-lru-cache) into the `lrucache` global variable. All these libraries are automatically included in the Node distribution.
1010

1111
Upon requiring this library, the `admin.database()` or `firebase.database()` method as well as the
1212
`app.App.database()` methods are monkey-patched to return a custom `FireCrypt` instance in place of
@@ -54,7 +54,7 @@ The `options` are as follows:
5454
* `keyCheckValue`: a value generated by a previous call to `configureFireCrypt()` used to verify that the `aes-siv` `key` used in both calls is the same. If a different key was used to generate the `keyCheckValue` then an error with `firecrypt === 'WRONG_KEY'` will be thrown.
5555
* For convenience, the `keyCheckValue` is also available at any time via
5656
`admin.database().encryptionKeyCheckValue` or `firebase.database().encryptionKeyCheckValue`.
57-
* `cacheSize`: the maximum size in bytes of the encryption and decryption caches, used to improve performance. In the browser, the caches will only be activated if `LRUCache` is defined; it should conform to the API of [`node-lru-cache`](https://github.com/isaacs/node-lru-cache). You can also specify `encryptionCacheSize` and `decryptionCacheSize` separately.
57+
* `cacheSize`: the maximum size in bytes of the encryption and decryption caches, used to improve performance. In the browser, the caches will only be activated if `lrucache.LRUCache` is defined; it should conform to the API of [`lru-cache`](https://github.com/isaacs/node-lru-cache). You can also specify `encryptionCacheSize` and `decryptionCacheSize` separately.
5858
* `compression`: the compression algorithm to use. Currently supported values are:
5959
* `deflate`: the classic, low-overhead deflate algorithm.
6060
* `none`: no compression.

dist/browser/firecrypt.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/firecrypt.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/firecrypt.min.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/firecrypt.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node/firecrypt.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node/firecrypt.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default [
1717
...globals.es2017,
1818
CryptoJS: false,
1919
fflate: false,
20-
LRUCache: false,
20+
lrucache: false,
2121
},
2222
ecmaVersion: 2019,
2323
sourceType: 'module',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"crypto-js": "^4.0.0",
2929
"cryptojs-extension": "github:reviewable/cryptojs-extension",
3030
"fflate": "^0.8.2",
31-
"serialized-lru-cache": "^3.1.0"
31+
"lru-cache": "^11.2.6"
3232
},
3333
"peerDependencies": {
3434
"firebase": "9.x || 10.x",

src/crypto.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ export default class Crypto {
3333
}
3434
this._compressionThreshold = options.compressionThreshold || 150;
3535

36-
if (typeof LRUCache === 'function') {
37-
this._encryptionCache = new LRUCache({
38-
max: options.encryptionCacheSize,
39-
length: this._computeCacheItemSize,
36+
if (typeof lrucache !== 'undefined') {
37+
this._encryptionCache = new lrucache.LRUCache({
38+
maxSize: options.encryptionCacheSize,
39+
sizeCalculation: this._computeCacheItemSize,
4040
});
41-
this._decryptionCache = new LRUCache({
42-
max: options.decryptionCacheSize,
43-
length: this._computeCacheItemSize,
41+
this._decryptionCache = new lrucache.LRUCache({
42+
maxSize: options.decryptionCacheSize,
43+
sizeCalculation: this._computeCacheItemSize,
4444
});
4545
}
4646

0 commit comments

Comments
 (0)