@@ -18,6 +18,30 @@ import Foundation
1818// any edits of this file WILL be overwritten and thus discarded
1919// see section `gyb` in `README` for details.
2020
21+ fileprivate struct ByteIterator < T> : IteratorProtocol {
22+ var currentOffset = 0
23+ var pointer : UnsafeRawBufferPointer ? = nil
24+ let length : Int
25+
26+ init ( _ bytes: T ) {
27+ self . length = Mirror ( reflecting: bytes) . children. count
28+ withUnsafeBytes ( of: bytes) { pointer in
29+ self . pointer = pointer
30+ }
31+ }
32+
33+ @inlinable
34+ public mutating func next( ) -> UInt8 ? {
35+ guard let pointer,
36+ currentOffset < length else { return nil }
37+
38+ let next = pointer. load ( fromByteOffset: currentOffset, as: UInt8 . self)
39+ currentOffset += 1
40+ return next
41+ }
42+ }
43+
44+
2145// MARK: - AES._CBC + IV
2246extension AES . _CBC {
2347 /// A value used once during a cryptographic operation and then discarded.
@@ -109,10 +133,8 @@ extension AES._CBC {
109133 }
110134
111135 /// Returns an iterator over the elements of the nonce.
112- public func makeIterator( ) -> Array < UInt8 > . Iterator {
113- self . withUnsafeBytes ( { ( buffPtr) in
114- return Array ( buffPtr) . makeIterator ( )
115- } )
136+ public func makeIterator( ) -> some IteratorProtocol < UInt8 > {
137+ ByteIterator ( bytes)
116138 }
117139 }
118140}
@@ -202,10 +224,8 @@ extension AES._CFB {
202224 }
203225
204226 /// Returns an iterator over the elements of the nonce.
205- public func makeIterator( ) -> Array < UInt8 > . Iterator {
206- self . withUnsafeBytes ( { ( buffPtr) in
207- return Array ( buffPtr) . makeIterator ( )
208- } )
227+ public func makeIterator( ) -> some IteratorProtocol < UInt8 > {
228+ ByteIterator ( bytes)
209229 }
210230 }
211231}
@@ -295,10 +315,8 @@ extension AES._CTR {
295315 }
296316
297317 /// Returns an iterator over the elements of the nonce.
298- public func makeIterator( ) -> Array < UInt8 > . Iterator {
299- self . withUnsafeBytes ( { ( buffPtr) in
300- return Array ( buffPtr) . makeIterator ( )
301- } )
318+ public func makeIterator( ) -> some IteratorProtocol < UInt8 > {
319+ ByteIterator ( bytes)
302320 }
303321 }
304322}
0 commit comments