Skip to content

Commit

Permalink
Support macOS 10.14.x/iOS 12.x and older again (#34)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dnadoba authored Jul 3, 2023
1 parent 0c33f18 commit 4758353
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions Sources/SwiftASN1/ASN1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ extension DER {
/// - rootNode: The ``ASN1Node`` to parse
/// - returns: A `Sequence` of elements representing the `Result` of parsing the elements in the sequence.
@inlinable
public static func lazySet<T: DERParseable>(of: T.Type = T.self, identifier: ASN1Identifier, rootNode: ASN1Node) throws -> some Sequence<Result<T, Error>> {
public static func lazySet<T: DERParseable>(of: T.Type = T.self, identifier: ASN1Identifier, rootNode: ASN1Node) throws -> LazySetOfSequence<T> {
guard rootNode.identifier == identifier, case .constructed(let nodes) = rootNode.content else {
throw ASN1Error.unexpectedFieldType(rootNode.identifier)
}
Expand All @@ -205,7 +205,42 @@ extension DER {
throw ASN1Error.invalidASN1Object(reason: "SET OF fields are not lexicographically ordered")
}

return nodes.lazy.map { node in Result { try T(derEncoded: node) } }
return .init(nodes.lazy.map { node in Result { try T(derEncoded: node) } })
}

public struct LazySetOfSequence<T>: Sequence {
public typealias Element = Result<T, Error>

@usableFromInline
typealias WrappedSequence = LazyMapSequence<LazySequence<(ASN1NodeCollection)>.Elements, Result<T, Error>>

public struct Iterator: IteratorProtocol {
@usableFromInline
var wrapped: WrappedSequence.Iterator

@inlinable
mutating public func next() -> Element? {
wrapped.next()
}

@inlinable
init(_ wrapped: WrappedSequence.Iterator) {
self.wrapped = wrapped
}
}

@usableFromInline
var wrapped: WrappedSequence

@inlinable
init(_ wrapped: WrappedSequence) {
self.wrapped = wrapped
}

@inlinable
public func makeIterator() -> Iterator {
.init(wrapped.makeIterator())
}
}
}

Expand Down

0 comments on commit 4758353

Please sign in to comment.