Accept epub for faster decrypting/encrypting

This commit is contained in:
Daniel Lugo 2021-06-08 14:09:14 -04:00
parent 265e006797
commit 921097dea1

View file

@ -81,6 +81,7 @@ async function deepEncryptIfNeeded(value) {
} }
const pk = /** @type {string|undefined} */ (value.$$__ENCRYPT__FOR) const pk = /** @type {string|undefined} */ (value.$$__ENCRYPT__FOR)
const epub = /** @type {string|undefined} */ (value.$$__EPUB__FOR)
if (!pk) { if (!pk) {
return Bluebird.props(mapValues(value, deepEncryptIfNeeded)) return Bluebird.props(mapValues(value, deepEncryptIfNeeded))
@ -93,7 +94,15 @@ async function deepEncryptIfNeeded(value) {
if (pk === u.is.pub || pk === 'me') { if (pk === u.is.pub || pk === 'me') {
encryptedValue = await SEA.encrypt(actualValue, getMySecret()) encryptedValue = await SEA.encrypt(actualValue, getMySecret())
} else { } else {
const sec = await SEA.secret(await pubToEpub(pk), u._.sea) const sec = await SEA.secret(
await (() => {
if (epub) {
return epub
}
return pubToEpub(pk)
})(),
u._.sea
)
encryptedValue = await SEA.encrypt(actualValue, sec) encryptedValue = await SEA.encrypt(actualValue, sec)
} }