Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/serialize/src/deserialize_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export function deserializeFactory<Suite extends AlgorithmSuite> (
* @param encodedEncryptionContext Uint8Array
*/
function decodeEncryptionContext (encodedEncryptionContext: Uint8Array) {
const encryptionContext: EncryptionContext = {}
const encryptionContext: EncryptionContext = Object.create(null)
/* Check for early return (Postcondition): The case of 0 length is defined as an empty object. */
if (!encodedEncryptionContext.byteLength) {
return encryptionContext
Expand Down
23 changes: 23 additions & 0 deletions modules/serialize/test/deserialize_factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ describe('deserializeFactory:decodeEncryptionContext', () => {
expect(test).to.have.property('information')
.and.to.eql('\u00bd + \u00bc = \u00be')
})

it('Keys may be properties of Object.prototype, decodeEncryptionContext has to succeed', () => {
const { decodeEncryptionContext } = deserializeFactory(toUtf8, WebCryptoAlgorithmSuite)

/* Single key-value pair */
const kvPairCount = Buffer.alloc(2)
kvPairCount.writeUInt16BE(1, 0)

/* Actual key-value pair */
const kvPair = [ 'hasOwnProperty', 'arbitraryValue' ]

/* Constructing the encryption context */
const kvPairBinary = kvPair.map(str => new Uint8Array([...Buffer.from(str)]))
const encryptionContext = concatBuffers(kvPairCount, ...kvPairBinary.map(bufStr => {
const len = Buffer.alloc(2)
len.writeUInt16BE(bufStr.byteLength, 0)
return concatBuffers(len, bufStr)
}))

const test = decodeEncryptionContext(encryptionContext)
expect(test).to.have.property('hasOwnProperty')
.and.to.eql('arbitraryValue')
})
})

describe('deserializeFactory:deserializeEncryptedDataKeys', () => {
Expand Down