This repository was archived by the owner on Jun 15, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,18 @@ class Keychain {
138138 return defaultOptions
139139 }
140140
141+ /**
142+ * Generates the options for a keychain. A random salt is produced.
143+ *
144+ * @returns {object }
145+ */
146+ static generateOptions ( ) {
147+ const options = Object . assign ( { } , defaultOptions )
148+ const saltLength = Math . ceil ( NIST . minSaltLength / 3 ) * 3 // no base64 padding
149+ options . dek . salt = crypto . randomBytes ( saltLength ) . toString ( 'base64' )
150+ return options
151+ }
152+
141153 /**
142154 * Create a new key.
143155 *
Original file line number Diff line number Diff line change @@ -46,6 +46,13 @@ module.exports = (datastore1, datastore2) => {
4646 expect ( ( ) => new Keychain ( datastore2 , { passPhrase : passPhrase , dek : { hash : 'my-hash' } } ) ) . to . throw ( )
4747 } )
4848
49+ it ( 'can generate options' , ( ) => {
50+ const options = Keychain . generateOptions ( )
51+ options . passPhrase = passPhrase
52+ const chain = new Keychain ( datastore2 , options )
53+ expect ( chain ) . to . exist ( )
54+ } )
55+
4956 describe ( 'key name' , ( ) => {
5057 it ( 'is a valid filename and non-ASCII' , ( ) => {
5158 ks . removeKey ( '../../nasty' , ( err ) => {
You can’t perform that action at this time.
0 commit comments