Skip to content

Commit 4758353

Browse files
authored
Support macOS 10.14.x/iOS 12.x and older again (#34)
* Support macOS 10.14.x/iOS 12.x and older again * Revert "Support macOS 10.14.x/iOS 12.x and older again" This reverts commit 6eeba03. * Erase concrete type manually
1 parent 0c33f18 commit 4758353

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

Sources/SwiftASN1/ASN1.swift

+37-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ extension DER {
196196
/// - rootNode: The ``ASN1Node`` to parse
197197
/// - returns: A `Sequence` of elements representing the `Result` of parsing the elements in the sequence.
198198
@inlinable
199-
public static func lazySet<T: DERParseable>(of: T.Type = T.self, identifier: ASN1Identifier, rootNode: ASN1Node) throws -> some Sequence<Result<T, Error>> {
199+
public static func lazySet<T: DERParseable>(of: T.Type = T.self, identifier: ASN1Identifier, rootNode: ASN1Node) throws -> LazySetOfSequence<T> {
200200
guard rootNode.identifier == identifier, case .constructed(let nodes) = rootNode.content else {
201201
throw ASN1Error.unexpectedFieldType(rootNode.identifier)
202202
}
@@ -205,7 +205,42 @@ extension DER {
205205
throw ASN1Error.invalidASN1Object(reason: "SET OF fields are not lexicographically ordered")
206206
}
207207

208-
return nodes.lazy.map { node in Result { try T(derEncoded: node) } }
208+
return .init(nodes.lazy.map { node in Result { try T(derEncoded: node) } })
209+
}
210+
211+
public struct LazySetOfSequence<T>: Sequence {
212+
public typealias Element = Result<T, Error>
213+
214+
@usableFromInline
215+
typealias WrappedSequence = LazyMapSequence<LazySequence<(ASN1NodeCollection)>.Elements, Result<T, Error>>
216+
217+
public struct Iterator: IteratorProtocol {
218+
@usableFromInline
219+
var wrapped: WrappedSequence.Iterator
220+
221+
@inlinable
222+
mutating public func next() -> Element? {
223+
wrapped.next()
224+
}
225+
226+
@inlinable
227+
init(_ wrapped: WrappedSequence.Iterator) {
228+
self.wrapped = wrapped
229+
}
230+
}
231+
232+
@usableFromInline
233+
var wrapped: WrappedSequence
234+
235+
@inlinable
236+
init(_ wrapped: WrappedSequence) {
237+
self.wrapped = wrapped
238+
}
239+
240+
@inlinable
241+
public func makeIterator() -> Iterator {
242+
.init(wrapped.makeIterator())
243+
}
209244
}
210245
}
211246

0 commit comments

Comments
 (0)