The ASN1 package implements a subset of the ASN1 (Abstract Syntax Notation One) specification in Swift.
It is intended to be used in writing cryptographic applications like ECIES and ECDSA in Swift.
ASN1 supports:
Building ASN1 structures from their byte array representation
DER encoding of ASN1 structures
Displaying ASN1 structures
Definite length encoding and decoding
Indefinite length decoding of sets and sequences
Tag numbers less than 128
Universal (0) and context-specific (2) tag classes
It supports the following ASN1 types:
BitString
BMPString
Boolean
GeneralizedTime
IA5String
Integer
Null
ObjectIdentifier
OctetString
PrintableString
Sequence
Set
T61String
UTCTime
UTF8String
Usage
In your project Package.swift file add a dependency like
Example 2 shows how to build an ASN1 structure programmatically and encode it to a byte array.
import ASN1
import BigInt
let privKey = BInt("238854808789429455904277046626010014418497476175")!
let seq = ASN1Sequence()
seq.add(ASN1Integer(BInt(1))).add(ASN1OctetString(privKey.asMagnitudeBytes()))
print(seq)
let b = seq.encode()
print("Byte array =", b)
Description
The ASN1 package implements a subset of the ASN1 (Abstract Syntax Notation One) specification in Swift. It is intended to be used in writing cryptographic applications like ECIES and ECDSA in Swift.
ASN1 supports:
It supports the following ASN1 types:
Usage
In your project Package.swift file add a dependency likeExample 1
Example 1 shows how to decode a byte array containing an ASN1 structure.
giving
Example 2
Example 2 shows how to build an ASN1 structure programmatically and encode it to a byte array.
giving
Dependencies
ASN1 requires Swift 5.0.
The ASN1 package depends on the BigInt package
References