Skip to content

Commit fbbccdf

Browse files
committed
Using Array iterator under the hood
1 parent ae25dca commit fbbccdf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Sources/_CryptoExtras/AES/Nonces.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ import Foundation
2020

2121
fileprivate struct ByteIterator<T>: IteratorProtocol {
2222
var currentOffset = 0
23-
var pointer: UnsafeRawBufferPointer? = nil
23+
var iterator: Array<UInt8>.Iterator? = nil
2424
let length: Int
2525

2626
init(_ bytes: T) {
2727
self.length = Mirror(reflecting: bytes).children.count
2828
withUnsafeBytes(of: bytes) { pointer in
29-
self.pointer = pointer
29+
self.iterator = Array(pointer).makeIterator()
3030
}
3131
}
3232

3333
@inlinable
3434
public mutating func next() -> UInt8? {
35-
guard let pointer,
35+
guard var iterator,
3636
currentOffset < length else { return nil }
3737

38-
let next = pointer.load(fromByteOffset: currentOffset, as: UInt8.self)
38+
let next = iterator.next()
3939
currentOffset += 1
4040
return next
4141
}

0 commit comments

Comments
 (0)