Skip to content

Commit

Permalink
fix: make keychain pass optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun committed Aug 5, 2020
1 parent 96d72b3 commit 088b782
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
24 changes: 8 additions & 16 deletions src/keychain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,14 @@ class Keychain {
throw new Error(`dek.iterationCount must be least ${NIST.minIterationCount}`)
}

// Lazily create the derived encrypting key
let dek
Object.defineProperty(this, '_', {
value: () => {
if (!dek) {
dek = crypto.pbkdf2(
this.opts.passPhrase,
this.opts.dek.salt,
this.opts.dek.iterationCount,
this.opts.dek.keyLength,
this.opts.dek.hash)
}

return dek
}
})
const dek = this.opts.passPhrase ? crypto.pbkdf2(
this.opts.passPhrase,
this.opts.dek.salt,
this.opts.dek.iterationCount,
this.opts.dek.keyLength,
this.opts.dek.hash) : ''

Object.defineProperty(this, '_', { value: () => dek })
}

/**
Expand Down
4 changes: 1 addition & 3 deletions test/keychain/keychain.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ describe('keychain', () => {
})

it('does not support unsupported hashing alorithms', () => {
const keychain = new Keychain(datastore2, { passPhrase: passPhrase, dek: { hash: 'my-hash' } })

expect(keychain.createKey('derp')).to.be.rejected()
expect(() => new Keychain(datastore2, { passPhrase: passPhrase, dek: { hash: 'my-hash' } })).to.throw()
})

it('can list keys without a password', async () => {
Expand Down

0 comments on commit 088b782

Please sign in to comment.