Skip to content

Commit

Permalink
More Sendability annotiations (#72)
Browse files Browse the repository at this point in the history
Motivation:

Completing annotations helps with coverage for consuming projects.

Modifications:

Mark more things and Sendable or not.

Result:

Consuming libraries more likely to get correct usage.

Co-authored-by: Cory Benfield <lukasa@apple.com>
  • Loading branch information
PeterAdams-A and Lukasa authored Oct 14, 2024
1 parent 9969712 commit aeb9c92
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Sources/SwiftASN1/ASN1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
//
//===----------------------------------------------------------------------===//


@available(*, unavailable)
extension ASN1: Sendable { }

public enum ASN1 {}

// MARK: - EncodingRules
extension ASN1 {
@usableFromInline
enum EncodingRules {
enum EncodingRules: Sendable {
case basic

case distinguished
Expand Down Expand Up @@ -124,7 +128,7 @@ extension ASN1.ParserNode {

extension ASN1 {
@usableFromInline
struct ParseResult {
struct ParseResult: Sendable {
@inlinable
static var _maximumNodeDepth: Int { 50 }

Expand Down Expand Up @@ -303,6 +307,12 @@ extension ASN1 {
}
}

@available(*, unavailable)
extension ASN1.LazySetOfSequence: Sendable {}

@available(*, unavailable)
extension ASN1.LazySetOfSequence.Iterator: Sendable {}

// MARK: - NodeCollection
/// Represents a collection of ASN.1 nodes contained in a constructed ASN.1 node.
///
Expand Down Expand Up @@ -333,7 +343,7 @@ extension ASN1NodeCollection: Sendable {}

extension ASN1NodeCollection: Sequence {
/// An iterator of ASN.1 nodes that are children of a specific constructed node.
public struct Iterator: IteratorProtocol {
public struct Iterator: IteratorProtocol, Sendable {
@usableFromInline
var _nodes: ArraySlice<ASN1.ParserNode>

Expand Down Expand Up @@ -427,7 +437,7 @@ extension ASN1Node {

extension ArraySlice where Element == UInt8 {
@usableFromInline
enum ASN1Length {
enum ASN1Length: Sendable {
case indefinite
case definite(_: UInt)
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftASN1/BER.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
/// for BER encoding and decoding.
public enum BER {}

@available(*, unavailable)
extension BER: Sendable {}

// MARK: - Parser Node
extension BER {
@usableFromInline
Expand Down
12 changes: 12 additions & 0 deletions Sources/SwiftASN1/Basic ASN1 Types/ObjectIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ extension ASN1ObjectIdentifier: CustomStringConvertible {
}
}

@available(*, unavailable)
extension ASN1ObjectIdentifier.NamedCurves: Sendable {}

@available(*, unavailable)
extension ASN1ObjectIdentifier.AlgorithmIdentifier: Sendable {}

@available(*, unavailable)
extension ASN1ObjectIdentifier.NameAttributes: Sendable {}

@available(*, unavailable)
extension ASN1ObjectIdentifier.OCSP: Sendable {}

extension ASN1ObjectIdentifier {
/// Represents a namespace for OIDs that identify named Elliptic Curves.
///
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftASN1/Basic ASN1 Types/TimeUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
//
//===----------------------------------------------------------------------===//


@available(*, unavailable)
extension TimeUtilities: Sendable {}

@usableFromInline
enum TimeUtilities {
@inlinable
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftASN1/DER.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
/// for DER encoding and decoding.
public enum DER {}

@available(*, unavailable)
extension DER: Sendable {}

// MARK: - Parser Node
extension DER {
@usableFromInline
Expand Down

0 comments on commit aeb9c92

Please sign in to comment.