@@ -31,30 +31,30 @@ func TestEnc(t *testing.T) {
31
31
t .Run ("encrypt/decrypt" , func (t * testing.T ) {
32
32
t .Parallel ()
33
33
34
- msgToEncryt := "hello world!"
34
+ msgToEncrypt := "hello world!"
35
35
key := getSecretKey ()
36
36
enc := New (key )
37
37
38
- encryptedMsg := enc .Encrypt (msgToEncryt )
38
+ encryptedMsg := enc .Encrypt (msgToEncrypt )
39
39
40
40
decryptedMsg , err := enc .Decrypt (encryptedMsg )
41
41
attest .Ok (t , err )
42
42
43
- attest .Equal (t , string (decryptedMsg ), msgToEncryt )
43
+ attest .Equal (t , string (decryptedMsg ), msgToEncrypt )
44
44
})
45
45
46
46
t .Run ("encrypt/decrypt base64" , func (t * testing.T ) {
47
47
t .Parallel ()
48
48
49
- msgToEncryt := "hello world!"
49
+ msgToEncrypt := "hello world!"
50
50
key := getSecretKey ()
51
51
enc := New (key )
52
52
53
- token := enc .EncryptEncode (msgToEncryt )
53
+ token := enc .EncryptEncode (msgToEncrypt )
54
54
55
55
decryptedMsg , err := enc .DecryptDecode (token )
56
56
attest .Ok (t , err )
57
- attest .Equal (t , string (decryptedMsg ), msgToEncryt )
57
+ attest .Equal (t , string (decryptedMsg ), msgToEncrypt )
58
58
})
59
59
60
60
t .Run ("encrypt same msg is unique" , func (t * testing.T ) {
@@ -63,27 +63,27 @@ func TestEnc(t *testing.T) {
63
63
// This is a useful property especially in how we use it in csrf protection
64
64
// against breachattack.
65
65
66
- msgToEncryt := "hello world!"
66
+ msgToEncrypt := "hello world!"
67
67
key := getSecretKey ()
68
68
enc := New (key )
69
69
70
- encryptedMsg := enc .Encrypt (msgToEncryt )
70
+ encryptedMsg := enc .Encrypt (msgToEncrypt )
71
71
72
72
var em []byte
73
73
for i := 0 ; i < 4 ; i ++ {
74
- em = enc .Encrypt (msgToEncryt )
74
+ em = enc .Encrypt (msgToEncrypt )
75
75
if slices .Equal (encryptedMsg , em ) {
76
76
t .Fatal ("slices should not be equal" )
77
77
}
78
78
}
79
79
80
80
decryptedMsg , err := enc .Decrypt (encryptedMsg )
81
81
attest .Ok (t , err )
82
- attest .Equal (t , string (decryptedMsg ), msgToEncryt )
82
+ attest .Equal (t , string (decryptedMsg ), msgToEncrypt )
83
83
84
84
decryptedMsgForEm , err := enc .Decrypt (em )
85
85
attest .Ok (t , err )
86
- attest .Equal (t , string (decryptedMsgForEm ), msgToEncryt )
86
+ attest .Equal (t , string (decryptedMsgForEm ), msgToEncrypt )
87
87
})
88
88
89
89
t .Run ("same input key will always be able to encrypt and decrypt" , func (t * testing.T ) {
@@ -93,31 +93,31 @@ func TestEnc(t *testing.T) {
93
93
// A csrf token that was encrypted today, should be able to be decrypted tomorrow
94
94
// even if the server was restarted; so long as the same key is re-used.
95
95
96
- msgToEncryt := "hello world!"
96
+ msgToEncrypt := "hello world!"
97
97
key := getSecretKey ()
98
98
99
99
enc1 := New (key )
100
- encryptedMsg := enc1 .Encrypt (msgToEncryt )
100
+ encryptedMsg := enc1 .Encrypt (msgToEncrypt )
101
101
102
102
enc2 := New (key ) // server restarted
103
103
decryptedMsg , err := enc2 .Decrypt (encryptedMsg )
104
104
attest .Ok (t , err )
105
- attest .Equal (t , string (decryptedMsg ), msgToEncryt )
105
+ attest .Equal (t , string (decryptedMsg ), msgToEncrypt )
106
106
})
107
107
108
108
t .Run ("concurrency safe" , func (t * testing.T ) {
109
109
t .Parallel ()
110
110
111
- msgToEncryt := "hello world!"
111
+ msgToEncrypt := "hello world!"
112
112
113
113
run := func () {
114
114
key := getSecretKey ()
115
115
enc := New (key )
116
116
117
- encryptedMsg := enc .Encrypt (msgToEncryt )
117
+ encryptedMsg := enc .Encrypt (msgToEncrypt )
118
118
decryptedMsg , err := enc .Decrypt (encryptedMsg )
119
119
attest .Ok (t , err )
120
- attest .Equal (t , string (decryptedMsg ), msgToEncryt )
120
+ attest .Equal (t , string (decryptedMsg ), msgToEncrypt )
121
121
}
122
122
123
123
wg := & sync.WaitGroup {}
0 commit comments