@@ -72,21 +72,28 @@ private void createVault(Path path) throws IOException {
7272 try (var passphraseContainer = passwordSource .readPassphrase ();
7373 var masterkey = Masterkey .generate (csprng )) {
7474
75- Path masterkeyFilePath = path .resolve (MASTERKEY_FILE_NAME );
76- MasterkeyFileAccess masterkeyFileAccess = new MasterkeyFileAccess (PEPPER , csprng );
77- masterkeyFileAccess .persist (
78- masterkey , masterkeyFilePath , CharBuffer .wrap (passphraseContainer .content ()));
79-
80- try {
81- CryptoFileSystemProperties fsProps =
82- CryptoFileSystemProperties .cryptoFileSystemProperties ()
83- .withCipherCombo (CryptorProvider .Scheme .SIV_GCM )
84- .withKeyLoader (ignored -> masterkey .copy ())
85- .build ();
86- CryptoFileSystemProvider .initialize (path , fsProps , DEFAULT_KEY_ID );
87- } catch (CryptoException e ) {
88- throw new IOException ("Vault initialization failed" , e );
89- }
75+ persistMasterkey (path , masterkey , passphraseContainer .content ());
76+ initializeVault (path , masterkey );
77+ }
78+ }
79+
80+ private void persistMasterkey (Path path , Masterkey masterkey , char [] passphrase )
81+ throws IOException {
82+ Path masterkeyFilePath = path .resolve (MASTERKEY_FILE_NAME );
83+ MasterkeyFileAccess masterkeyFileAccess = new MasterkeyFileAccess (PEPPER , csprng );
84+ masterkeyFileAccess .persist (masterkey , masterkeyFilePath , CharBuffer .wrap (passphrase ));
85+ }
86+
87+ private void initializeVault (Path path , Masterkey masterkey ) throws IOException {
88+ CryptoFileSystemProperties fsProps =
89+ CryptoFileSystemProperties .cryptoFileSystemProperties ()
90+ .withCipherCombo (CryptorProvider .Scheme .SIV_GCM )
91+ .withKeyLoader (ignored -> masterkey .copy ())
92+ .build ();
93+ try {
94+ CryptoFileSystemProvider .initialize (path , fsProps , DEFAULT_KEY_ID );
95+ } catch (CryptoException e ) {
96+ throw new IOException ("Vault initialization failed" , e );
9097 }
9198 }
9299}
0 commit comments