@@ -45,6 +45,8 @@ class Reader
4545
4646 const OUTPUT_TO_DECRYPTED = 'SHOW_DECRYPTED ' ;
4747
48+ const OUTPUT_TO_RAW = 'SHOW_RAW ' ;
49+
4850 /**
4951 * Writer constructor.
5052 *
@@ -65,7 +67,7 @@ public function __construct(Vault $vault)
6567 * @return KeyValuePair[]
6668 * @throws SodiumException
6769 */
68- public function convertStreamToArray (string $ stream , string $ loadType = self ::LOAD_FROM_ENCRYPTED , string $ outputType = self ::OUTPUT_TO_ENCRYPTED , string $ nonce = null ): array
70+ public function convertStreamToKeyPairArray (string $ stream , string $ loadType = self ::LOAD_FROM_ENCRYPTED , string $ outputType = self ::OUTPUT_TO_ENCRYPTED , string $ nonce = null ): array
6971 {
7072 $ lines = explode ("\n" , $ stream );
7173 $ return = array ();
@@ -146,7 +148,7 @@ public function convertStreamToArray(string $stream, string $loadType = self::LO
146148 }
147149
148150 /**
149- * Adds given array to vault.
151+ * Adds given array to vault (old) .
150152 *
151153 * @param KeyValuePair[] $array
152154 * @param string|null $nonce
@@ -164,6 +166,19 @@ public function addArrayToVault(array $array, string $nonce = null): void
164166 }
165167 }
166168
169+ /**
170+ * Adds given key pair array to vault.
171+ *
172+ * @param KeyValuePair[] $array
173+ * @return void
174+ */
175+ public function addKeyValuePairArrayToVault (array $ array ): void
176+ {
177+ foreach ($ array as $ name => $ keyPair ) {
178+ $ this ->vault ->addKeyValuePair ($ name , $ keyPair );
179+ }
180+ }
181+
167182 /**
168183 * Adds given stream to vault.
169184 *
@@ -175,9 +190,7 @@ public function addArrayToVault(array $array, string $nonce = null): void
175190 */
176191 public function addStreamToVault (string $ stream , string $ loadType = self ::LOAD_FROM_ENCRYPTED , string $ outputType = self ::OUTPUT_TO_ENCRYPTED ): void
177192 {
178- $ array = $ this ->convertStreamToArray ($ stream , $ loadType , Reader::OUTPUT_TO_ENCRYPTED );
179-
180- $ this ->addArrayToVault ($ array , null );
193+ $ this ->addKeyValuePairArrayToVault ($ this ->convertStreamToKeyPairArray ($ stream , $ loadType , $ outputType ));
181194 }
182195
183196 /**
@@ -188,6 +201,7 @@ public function addStreamToVault(string $stream, string $loadType = self::LOAD_F
188201 * @param string $outputType
189202 * @return void
190203 * @throws SodiumException
204+ * @throws Exception
191205 */
192206 public function addFileToVault (string $ file , string $ loadType = self ::LOAD_FROM_ENCRYPTED , string $ outputType = self ::OUTPUT_TO_ENCRYPTED ): void
193207 {
0 commit comments