@@ -31,11 +31,15 @@ extension AES._CBC {
31
31
UInt8 , UInt8 , UInt8 , UInt8 , UInt8 , UInt8 , UInt8 , UInt8
32
32
)
33
33
34
- private var bytes : IVTuple
34
+ var bytes : IVTuple
35
+ static var emptyBytes : IVTuple = (
36
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
37
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
38
+ )
35
39
36
40
/// Creates a new random nonce.
37
41
public init ( ) {
38
- var bytes = IVTuple ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
42
+ var bytes = Self . emptyBytes
39
43
Swift . withUnsafeMutableBytes ( of: & bytes) {
40
44
let count = MemoryLayout< IVTuple> . size
41
45
$0. initializeWithRandomBytes ( count: count)
@@ -56,7 +60,7 @@ extension AES._CBC {
56
60
throw CryptoKitError . incorrectKeySize
57
61
}
58
62
59
- var bytes = IVTuple ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
63
+ var bytes = Self . emptyBytes
60
64
Swift . withUnsafeMutableBytes ( of: & bytes) { bytesPtr in
61
65
bytesPtr. copyBytes ( from: ivBytes)
62
66
}
@@ -76,7 +80,7 @@ extension AES._CBC {
76
80
throw CryptoKitError . incorrectParameterSize
77
81
}
78
82
79
- var bytes = IVTuple ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
83
+ var bytes = Self . emptyBytes
80
84
Swift . withUnsafeMutableBytes ( of: & bytes) { bytesPtr in
81
85
data. copyBytes ( to: bytesPtr)
82
86
}
@@ -123,11 +127,12 @@ extension AES._CFB {
123
127
public struct IV : Sendable , ContiguousBytes , Sequence {
124
128
typealias IVTuple = ( UInt64 , UInt64 )
125
129
126
- private var bytes : IVTuple
130
+ var bytes : IVTuple
131
+ static var emptyBytes : IVTuple = ( 0 , 0 )
127
132
128
133
/// Creates a new random nonce.
129
134
public init ( ) {
130
- var bytes = IVTuple ( 0 , 0 )
135
+ var bytes = Self . emptyBytes
131
136
Swift . withUnsafeMutableBytes ( of: & bytes) {
132
137
let count = MemoryLayout< IVTuple> . size
133
138
$0. initializeWithRandomBytes ( count: count)
@@ -148,7 +153,7 @@ extension AES._CFB {
148
153
throw CryptoKitError . incorrectKeySize
149
154
}
150
155
151
- var bytes = IVTuple ( 0 , 0 )
156
+ var bytes = Self . emptyBytes
152
157
Swift . withUnsafeMutableBytes ( of: & bytes) { bytesPtr in
153
158
bytesPtr. copyBytes ( from: ivBytes)
154
159
}
@@ -168,7 +173,7 @@ extension AES._CFB {
168
173
throw CryptoKitError . incorrectParameterSize
169
174
}
170
175
171
- var bytes = IVTuple ( 0 , 0 )
176
+ var bytes = Self . emptyBytes
172
177
Swift . withUnsafeMutableBytes ( of: & bytes) { bytesPtr in
173
178
data. copyBytes ( to: bytesPtr)
174
179
}
@@ -215,11 +220,12 @@ extension AES._CTR {
215
220
public struct Nonce : Sendable , ContiguousBytes , Sequence {
216
221
typealias NonceTuple = ( UInt64 , UInt32 , UInt32 )
217
222
218
- private var bytes : NonceTuple
223
+ var bytes : NonceTuple
224
+ static var emptyBytes : NonceTuple = ( 0 , 0 , 0 )
219
225
220
226
/// Creates a new random nonce.
221
227
public init ( ) {
222
- var bytes = NonceTuple ( 0 , 0 , 0 )
228
+ var bytes = Self . emptyBytes
223
229
Swift . withUnsafeMutableBytes ( of: & bytes) {
224
230
let count = MemoryLayout< NonceTuple> . size
225
231
$0. initializeWithRandomBytes ( count: count)
@@ -240,7 +246,7 @@ extension AES._CTR {
240
246
throw CryptoKitError . incorrectKeySize
241
247
}
242
248
243
- var bytes = NonceTuple ( 0 , 0 , 0 )
249
+ var bytes = Self . emptyBytes
244
250
Swift . withUnsafeMutableBytes ( of: & bytes) { bytesPtr in
245
251
bytesPtr. copyBytes ( from: nonceBytes)
246
252
}
@@ -260,7 +266,7 @@ extension AES._CTR {
260
266
throw CryptoKitError . incorrectParameterSize
261
267
}
262
268
263
- var bytes = NonceTuple ( 0 , 0 , 0 )
269
+ var bytes = Self . emptyBytes
264
270
Swift . withUnsafeMutableBytes ( of: & bytes) { bytesPtr in
265
271
data. copyBytes ( to: bytesPtr)
266
272
}
0 commit comments