Disclaimer: This library is in its early development phase and should not yet be used in production. All the code in this repository might change, including its APIs. This library is not very well optimised. If you are looking for the absolute best performance this library is probably not for you.
Base32Kit is a simple pure Swift Library for the Base32 encoding as defined by RFC 4648 that is implemented without Apples Foundation framework.
import Base32Kit
let encoded = Base32.encode(string: "foobar")
print(encoded) // prints MZXW6YTBOI======
Decoding
All decode* methods can throw an error. In general you have two options of dealing with this. If you are not interested in the error and just need to decode the value or do “nothing”, you can use a simple try? statement:
import Base32Kit
if let decoded = try? Base32.decode(string: "MZXW6YTBOI======") {
print(decoded) // prints "foobar"
}
If you want to handle any possible error in a more generlised way, you can use the following simple do-catch statement:
import Base32Kit
do {
let decoded = try Base32.decode(string: "MZXW6YTBOI======")
print(decoded) // prints "foobar"
} catch {
print("Error!")
}
The above code does not allow to handle all the different errors that may be thrown separately. To handle errors separately, you can use an extended version of the above do-catch statement:
import Base32Kit
do {
let decoded = try Base32.decode(string: "MZXW6YTBOI======")
print(decoded) // prints "foobar"
} catch Base32.DecodingError.invalidLength {
print("Encoded string has invalid length!")
} catch Base32.DecodingError.invalidPaddingCharacters {
print("Encoded string uses illegal padding characters!")
} catch Base32.DecodingError.invalidCharacter(let illegalCharacters) {
print("Encoded string contained the following illegal characters: \(illegalCharacters)")
} catch Base32.DecodingError.missingCharacter {
print("During decoding there was an unexpected missing character!")
} catch {
print("Error!")
}
Base32Kit
Base32Kit is a simple pure Swift Library for the Base32 encoding as defined by RFC 4648 that is implemented without Apples Foundation framework.
API reference documentation is available at https://jenslauterbach.github.io/Base32Kit/
Table of Contents
Installation
(Back to top)
Swift Package Manager
Usage
Encoding
Decoding
All
decode*
methods can throw an error. In general you have two options of dealing with this. If you are not interested in the error and just need to decode the value or do “nothing”, you can use a simpletry?
statement:If you want to handle any possible error in a more generlised way, you can use the following simple
do-catch
statement:The above code does not allow to handle all the different errors that may be thrown separately. To handle errors separately, you can use an extended version of the above
do-catch
statement:Quick Start
(Back to top)
You can start playing around with
Base32Kit
by using the Swift REPL on your local machine:Design Goals
(Back to top)
The primary design goals of this Swift package are:
Furthermore, we try to create a comprehensive test suite to verify the package with a big variety of test data on all supported platforms.
Alternatives
(Back to top)
Versioning
(Back to top)
We use SemVer for versioning. For the versions available, see the releases page.
Authors
(Back to top)
License
(Back to top)
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Acknowledgments
(Back to top)