@@ -163,6 +163,14 @@ Describe 'Sodium' {
163163 $derivedPublicKey | Should - Be $expectedPublicKey
164164 }
165165
166+ It ' Get-SodiumPublicKey - Returns the public key as a byte array' {
167+ $keyPair = New-SodiumKeyPair
168+ $derivedPublicKey = Get-SodiumPublicKey - PrivateKey $keyPair.PrivateKey - AsByteArray
169+
170+ $derivedPublicKey | Should - BeOfType ([byte ])
171+ [Convert ]::ToBase64String($derivedPublicKey ) | Should - Be $keyPair.PublicKey
172+ }
173+
166174 It ' Get-SodiumPublicKey - Throws an error when an invalid private key is provided' {
167175 $invalidPrivateKey = ' InvalidKey'
168176
@@ -186,4 +194,46 @@ Describe 'Sodium' {
186194 }
187195 }
188196 }
197+
198+ Context ' Parallel sessions' {
199+ It ' Loads and completes crypto round trips in parallel runspaces' {
200+ $modulePath = (Get-Module - Name Sodium - ErrorAction Stop).Path
201+ Test-Path - Path $modulePath | Should - BeTrue
202+ $results = 1 .. 4 | ForEach-Object - Parallel {
203+ Import-Module - Name $using :modulePath - Force
204+ $keyPair = New-SodiumKeyPair - Seed " Runspace-$_ "
205+ $message = " Parallel runspace $_ "
206+ $sealedBox = ConvertTo-SodiumSealedBox - Message $message - PublicKey $keyPair.PublicKey
207+ ConvertFrom-SodiumSealedBox - SealedBox $sealedBox - PrivateKey $keyPair.PrivateKey
208+ } - ThrottleLimit 4
209+
210+ $results | Should - HaveCount 4
211+ $results | Should - Contain ' Parallel runspace 1'
212+ $results | Should - Contain ' Parallel runspace 4'
213+ }
214+
215+ It ' Loads and completes crypto round trips in parallel processes' {
216+ $modulePath = (Get-Module - Name Sodium - ErrorAction Stop).Path
217+ $jobs = 1 .. 4 | ForEach-Object {
218+ Start-Job - ScriptBlock {
219+ $id = $args [0 ]
220+ $modulePath = $args [1 ]
221+ Import-Module - Name $modulePath - Force
222+ $keyPair = New-SodiumKeyPair - Seed " Process-$id "
223+ $message = " Parallel process $id "
224+ $sealedBox = ConvertTo-SodiumSealedBox - Message $message - PublicKey $keyPair.PublicKey
225+ ConvertFrom-SodiumSealedBox - SealedBox $sealedBox - PrivateKey $keyPair.PrivateKey
226+ } - ArgumentList $_ , $modulePath
227+ }
228+
229+ try {
230+ $results = $jobs | Receive-Job - Wait
231+ $results | Should - HaveCount 4
232+ $results | Should - Contain ' Parallel process 1'
233+ $results | Should - Contain ' Parallel process 4'
234+ } finally {
235+ $jobs | Remove-Job - Force
236+ }
237+ }
238+ }
189239}
0 commit comments