Swiftpack.co - nextincrement/simple-asn1-reader-writer as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by nextincrement.
nextincrement/simple-asn1-reader-writer 0.1.0
Simple ASN.1 reader and writer
⭐️ 7
πŸ•“ 4 years ago
.package(url: "https://github.com/nextincrement/simple-asn1-reader-writer.git", from: "0.1.0")

Simple ASN.1 Reader and Writer

A simple reader and writer for reading and writing ASN.1 encoded bytes.

Swift Version License

This project includes the SimpleASN1Reader and SimpleASN1Writer module, written in Swift and featuring a reader and writer that can be used for reading and writing ASN.1 encoded bytes.

Features

Reader

  • β˜‘ Reading any ASN.1 BER encoding (so, including DER and CER encoding formats)
  • β˜‘ Reading contents bytes
  • β˜‘ Readahead of identifier byte
  • β˜‘ Validation of identifier byte
  • β˜‘ Validation of an expected array of bytes
  • β˜‘ Validation of length bytes
  • β˜‘ Skipping bytes

Writer

  • β˜‘ Encoding bytes using the ASN.1 DER encoding format
  • β˜‘ Inserting new bytes on top of all bytes written before (as a sibling)
  • β˜‘ Inserting a component represented with a simple type on top of all bytes written before (as a sibling)
  • β˜‘ Composing structured types with a dedicated writer and inserting these components on top of all bytes written before (as a sibling)
  • β˜‘ Wrapping all bytes written before (as a parent)

Not Supported

  • ☐ Conversion of bytes into Swift data types (such as Int, String etc.)
  • ☐ Reading and writing from and to an underlying Stream
  • ☐ High tag numbers (that is, tag numbers are encoded by a single byte)
  • ☐ Encodings with an indefinite length
  • ☐ ASN.1 CER encoding format when writing bytes

The above items are deliberately not supported to keep both the reader and the writer simple and focused. In addition, the assumption has been made that the last three items are not commonly used. So, it is not expected that one of these items will be supported at some time in the future.

Usage

simple-asn1-reader-writer is a SwiftPM project and can be built and tested using these commands:

$ swift build
$ swift test

To depend on simple-asn1-reader-writer, put the following in the dependencies of your Package.swift:

.package(url: "https://github.com/nextincrement/simple-asn1-reader-writer.git", from: "0.1.0"),

See the rsa-public-key-importer-exporter project for an example of how the reader and writer can be used.

Contribute

Your interest in this project is highly appreciated. However, contributions might not be accepted for the following reasons:

  • The development environment that I currently have at hand is a Linux system on a virtual machine. I will thus not always be able to test how this code runs on a macOS or an iOS platform (although the first version will be tested on an iOS platform).
  • I’m just one developer and time is scarce.

Some contributions may get accepted if for example a bug should be fixed that prevents parts of the code from being used in a common situation.

Resources

A Layman’s Guide to a Subset of ASN.1, BER, and DER

X.690

Thanks

To the following project, which served as reference and inspiration during development:

JOSESwift

License

simple-asn1-reader-writer is licensed under the MIT License. See LICENSE for details.

GitHub

link
Stars: 7
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Simple ASN.1 Reader and Writer 0.1.0
4 years ago

Changes

  • Remove deprecated methods

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics