1
- Clear-Host
2
- Import-Module - Name Pester - Force
3
1
Import-Module .\Crypto.AES\Crypto.AES.psm1 - Force
4
2
5
3
Describe ' Crypto.AES.Tests' {
6
- $encoding = [System.Text.UTF8Encoding ]::new()
4
+ BeforeAll {
5
+ $encoding = [System.Text.UTF8Encoding ]::new()
6
+ }
7
7
8
8
Context " AES key generation" {
9
9
It " Should return key as string - default" {
@@ -24,9 +24,11 @@ Describe 'Crypto.AES.Tests' {
24
24
}
25
25
26
26
Context " Protect-Data - Result" {
27
- $Key = [byte []]::new(32 )
28
- $nonce = [byte []]::new(12 )
29
- $data = $encoding.GetBytes (" Test" )
27
+ BeforeAll {
28
+ $Key = [byte []]::new(32 )
29
+ $nonce = [byte []]::new(12 )
30
+ $data = $encoding.GetBytes (" Test" )
31
+ }
30
32
31
33
It " has correct size" {
32
34
$r_key = Protect-Data - Key $Key - Data $data - Nonce $nonce
@@ -58,14 +60,16 @@ Describe 'Crypto.AES.Tests' {
58
60
}
59
61
60
62
Context " Protect-Data - signature" {
63
+ BeforeAll {
61
64
$Key = [byte []]::new(32 )
62
- $nonce = [byte []]::new(12 )
65
+ $nonce = [byte []]::new(12 )
63
66
$nonce [0 ] = 104 # random value to test with mock
64
- $data = $encoding.GetBytes (" Test" )
67
+ $data = $encoding.GetBytes (" Test" )
65
68
66
69
Mock - CommandName Get-RandomNonce - ModuleName Crypto.AES - MockWith {
67
70
Write-Output $nonce - NoEnumerate
68
71
}
72
+ }
69
73
70
74
It " optional nonce" {
71
75
$r_explicit = Protect-Data - Key $Key - Data $data - Nonce $nonce
@@ -89,9 +93,11 @@ Describe 'Crypto.AES.Tests' {
89
93
}
90
94
91
95
Context " Protect-Data - nonce" {
92
- $Key = [byte []]::new(32 )
93
- $nonce = [byte []]::new(12 )
94
- $data = $encoding.GetBytes (" Test" )
96
+ BeforeAll {
97
+ $Key = [byte []]::new(32 )
98
+ $nonce = [byte []]::new(12 )
99
+ $data = $encoding.GetBytes (" Test" )
100
+ }
95
101
96
102
It " the same nonce" {
97
103
$a = Protect-Data - Key $Key - Data $data - Nonce $nonce
@@ -115,10 +121,12 @@ Describe 'Crypto.AES.Tests' {
115
121
}
116
122
117
123
Context " Unprotect-Data" {
118
- $Key = [byte []]::new(32 )
119
- [byte []]$nonce = @ (228 , 132 , 78 , 5 , 31 , 60 , 78 , 70 , 192 , 119 , 50 , 184 )
120
- [byte []]$tag = @ (188 , 136 , 244 , 158 , 253 , 2 , 183 , 117 , 127 , 2 , 193 , 66 , 39 , 37 , 94 , 188 )
121
- $data = @ (48 , 22 , 117 , 218 )
124
+ BeforeAll {
125
+ $Key = [byte []]::new(32 )
126
+ [byte []]$nonce = @ (228 , 132 , 78 , 5 , 31 , 60 , 78 , 70 , 192 , 119 , 50 , 184 )
127
+ [byte []]$tag = @ (188 , 136 , 244 , 158 , 253 , 2 , 183 , 117 , 127 , 2 , 193 , 66 , 39 , 37 , 94 , 188 )
128
+ $data = @ (48 , 22 , 117 , 218 )
129
+ }
122
130
123
131
It " has correct size" {
124
132
$r_key = Unprotect-Data - Key $Key - Data $data - Nonce $nonce - Tag $tag
0 commit comments