### Example Bug Report Source: https://github.com/apple/swift-asn1/blob/main/CONTRIBUTING.md An example of a comprehensive bug report including commit hash, context, reproduction steps, and system information. ```text Commit hash: b17a8a9f0f814c01a56977680cb68d8a779c951f Context: While testing my application that uses with swift-asn1, I noticed that ... Steps to reproduce: 1. ... 2. ... 3. ... 4. ... $ swift --version Swift version 4.0.2 (swift-4.0.2-RELEASE) Target: x86_64-unknown-linux-gnu Operating system: Ubuntu Linux 16.04 64-bit $ uname -a Linux beefy.machine 4.4.0-101-generic #124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux My system has IPv6 disabled. ``` -------------------------------- ### Update CMakeLists Files using Script Source: https://github.com/apple/swift-asn1/blob/main/CONTRIBUTING.md Example of using curl to fetch and execute the update-cmake-lists.sh script with a specific configuration. ```bash curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/update-cmake-lists.sh | CONFIG_JSON='{"targets":[{"name":"SwiftASN1","type":"source","exceptions":[]}]}' bash ``` -------------------------------- ### Configure SwiftASN1 CMake Project Source: https://github.com/apple/swift-asn1/blob/main/CMakeLists.txt Sets up the project name, language, and build directories for the SwiftASN1 library. ```cmake cmake_minimum_required(VERSION 3.19) project(SwiftASN1 LANGUAGES Swift) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) include(SwiftSupport) option(BUILD_SHARED_LIBS "Build shared libraries by default" YES) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) set(CMAKE_POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}) find_package(dispatch CONFIG) find_package(Foundation CONFIG) add_subdirectory(Sources) add_subdirectory(cmake/modules) ``` -------------------------------- ### Add SwiftASN1 product to target Source: https://github.com/apple/swift-asn1/blob/main/README.md Add the SwiftASN1 product to your target's dependencies to use the library in your code. ```swift dependencies: [ .product(name: "SwiftASN1", package: "swift-asn1"), ] ``` -------------------------------- ### Configure and Export SwiftASN1 Targets Source: https://github.com/apple/swift-asn1/blob/main/cmake/modules/CMakeLists.txt Configures the project's CMake export files and exports the defined targets for external use. ```cmake set(SWIFT_ASN1_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftASN1Exports.cmake) configure_file(SwiftASN1Config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/SwiftASN1Config.cmake) get_property(SWIFT_ASN1_EXPORTS GLOBAL PROPERTY SWIFT_ASN1_EXPORTS) export(TARGETS ${SWIFT_ASN1_EXPORTS} FILE ${SWIFT_ASN1_EXPORTS_FILE}) ``` -------------------------------- ### Configure Git Commit Template Source: https://github.com/apple/swift-asn1/blob/main/CONTRIBUTING.md Command to configure Git to use the project's commit message template. ```bash git config commit.template dev/git.commit.template ``` -------------------------------- ### Add SwiftASN1 dependency to Package.swift Source: https://github.com/apple/swift-asn1/blob/main/README.md Include this dependency in your Package.swift file to integrate the library into your project. ```swift dependencies: [ .package(url: "https://github.com/apple/swift-asn1.git", .upToNextMajor(from: "1.0.0")) ] ``` -------------------------------- ### Run CI Checks Locally with act Source: https://github.com/apple/swift-asn1/blob/main/CONTRIBUTING.md Command to run Github Actions workflows locally using 'act' for CI checks, specifically the 'cmake-lists' job. ```bash act --container-architecture linux/amd64 pull_request -j cmake-lists -W ./.github/workflows/pull_request.yml --bind ``` -------------------------------- ### Built-in ASN.1 Types Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/index.md A list of common ASN.1 types implemented within the library. ```APIDOC ## Built-in ASN.1 Types ### Description Commonly used ASN.1 types provided by the library. ### Protocols - `ASN1IntegerRepresentable` ### Types - `IntegerBytesCollection` - `GeneralizedTime` - `ASN1BitString` - `UTCTime` - `ASN1OctetString` - `ASN1Any` - `ASN1Null` - `ASN1ObjectIdentifier` - `ASN1UTF8String` - `ASN1PrintableString` - `ASN1BMPString` - `ASN1IA5String` - `ASN1TeletexString` - `ASN1UniversalString` ``` -------------------------------- ### Initialize ECDSASignature from DER encoded data Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/DecodingASN1.md Implement the DERImplicitlyTaggable protocol to decode an ECDSASignature from DER encoded data. This involves parsing a SEQUENCE node and recursively decoding its INTEGER components. ```swift extension ECDSASignature: DERImplicitlyTaggable { init(derEncoded rootNode: ASN1Node, withIdentifier identifier: ASN1Identifier) throws { self = try DER.sequence(rootNode, identifier: identifier) { // TODO } } } ``` ```swift init(derEncoded rootNode: ASN1Node, withIdentifier identifier: ASN1Identifier) throws { self = try DER.sequence(rootNode, identifier: identifier) { let r = try ArraySlice(derEncoded: &nodes) let s = try ArraySlice(derEncoded: &nodes) return ECDSASignature(r: r, s: s) } } ``` -------------------------------- ### DER Serialization API Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/index.md This section outlines the components used for serializing ASN.1 structures into DER-encoded data. ```APIDOC ## DER Serialization ### Description Components for serializing ASN.1 structures into DER-encoded data. ### Types - `DER/Serializer` ### Protocols - `DERSerializable` - `DERImplicitlyTaggable` ``` -------------------------------- ### Decode Explicitly Tagged INTEGER Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/DecodingASN1.md Use this initializer to decode an explicitly tagged INTEGER within a SEQUENCE. It requires the root node and specifies the tag number and class for the explicit tag. ```swift init(derEncoded rootNode: ASN1Node) throws { self = try DER.sequence(rootNode, identifier: .sequence) { nodes in let value = try ASN1.explicitlyTagged(&nodes, tagNumber: 0, tagClass: .contextSpecific) { try Int64(derEncoded: $0) } return ContainsExplicitTag(value: value) } } ``` -------------------------------- ### PEM Parsing and Serialization Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/index.md APIs for handling Privacy-Enhanced Mail (PEM) encoded data. ```APIDOC ## PEM Parsing and Serialization ### Description Protocols and types for parsing and serializing PEM-encoded data. ### Protocols - `PEMRepresentable` - `PEMParseable` - `PEMSerializable` ### Types - `PEMDocument` ``` -------------------------------- ### DER Parsing API Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/index.md This section details the functions and protocols related to parsing DER-encoded data into ASN.1 structures. ```APIDOC ## DER Parsing ### Description Functions and protocols for parsing DER-encoded data. ### Functions - `DER/parse(_:)-72yd1` - `DER/parse(_:)-6uo24` ### Protocols - `DERParseable` - `DERImplicitlyTaggable` - `DERSerializable` ``` -------------------------------- ### ASN.1 Node Representation Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/index.md Details on the `ASN1Node` structure used to represent ASN.1 objects in a tree-like format. ```APIDOC ## ASN.1 Node Representation ### Description Represents an ASN.1 object as a tree of nodes. ### Types - `ASN1Node` - `ASN1NodeCollection` - `ASN1Identifier` ``` -------------------------------- ### Decode Implicitly Tagged INTEGER Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/DecodingASN1.md Initializes a ContainsImplicitTag object by decoding a SEQUENCE containing an implicitly tagged INTEGER. ```swift init(derEncoded rootNode: ASN1Node) throws { self = try DER.sequence(rootNode, identifier: .sequence) { let value = try Int64(derEncoded: &nodes, withIdentifier: .init(tagWithNumber: 0, tagClass: .contextSpecific)) return ContainsImplicitTag(value: value) } } ``` -------------------------------- ### Encode Explicitly Tagged INTEGER Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/DecodingASN1.md Implement this method to serialize an explicitly tagged INTEGER. It appends a constructed node to the coder and serializes the value with the specified explicit tag. ```swift func serialize(into coder: inout DER.Serializer) throws { try coder.appendConstructedNode(identifier: .sequence) { coder in try coder.serialize(self.value, explicitlyTaggedWithTagNumber: 0, tagClass: .contextSpecific) } } ``` -------------------------------- ### Serialize ECDSASignature to DER format Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/DecodingASN1.md Implement the DERImplicitlyTaggable protocol to serialize an ECDSASignature into DER format. This uses DER.Serializer to append a constructed node and recursively serialize its components. ```swift func serialize(into coder: inout DER.Serializer, withIdentifier identifier: ASN1Identifier) throws { try coder.appendConstructedNode(identifier: identifier) { coder in try coder.serialize(self.r) try coder.serialize(self.s) } } ``` -------------------------------- ### Define ECDSASignature with DERImplicitlyTaggable Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/DecodingASN1.md Defines the ECDSASignature struct conforming to DERImplicitlyTaggable, including default identifier, properties, and initializers for decoding and encoding. ```swift struct ECDSASignature: DERImplicitlyTaggable { static var defaultIdentifier: ASN1Identifier { .sequence } var r: ArraySlice var s: ArraySlice init(r: ArraySlice, s: ArraySlice) { self.r = r self.s = s } init(derEncoded rootNode: ASN1Node, withIdentifier identifier: ASN1Identifier) throws { self = try DER.sequence(rootNode, identifier: identifier) { nodes in let r = try ArraySlice(derEncoded: &nodes) let s = try ArraySlice(derEncoded: &nodes) return ECDSASignature(r: r, s: s) } } func serialize(into coder: inout DER.Serializer, withIdentifier identifier: ASN1Identifier) throws { try coder.appendConstructedNode(identifier: identifier) { coder in try coder.serialize(self.r) try coder.serialize(self.s) } } } ``` -------------------------------- ### Define ECDSASignature Struct Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/DecodingASN1.md Define a Swift struct to represent the ECDSA signature, which consists of two INTEGER fields. Use ArraySlice to store the raw bytes of these arbitrary-sized integers. ```swift struct ECDSASignature { var r: ArraySlice var s: ArraySlice init(r: ArraySlice, s: ArraySlice) { self.r = r self.s = s } } ``` -------------------------------- ### Encode Implicitly Tagged INTEGER Source: https://github.com/apple/swift-asn1/blob/main/Sources/SwiftASN1/Docs.docc/DecodingASN1.md Serializes a ContainsImplicitTag object by encoding its value into a SEQUENCE with an implicitly tagged INTEGER. ```swift func serialize(into coder: inout DER.Serializer) throws { try coder.appendConstructedNode(identifier: .sequence) { try self.value.serialize(into: &coder, withIdentifier: .init(tagWithNumber: 0, tagClass: .contextSpecific)) } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.