Skip to content

A lightweight Swift library providing useful utilities for handling Base64 encoding and decoding.

License

Notifications You must be signed in to change notification settings

nashysolutions/base64-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

base64-swift

A small Swift library that provides explicit, predictable Base64 encoding and decoding.


Why this exists

In real-world systems, Base64 handling tends to show up at boundaries: authentication flows, cryptographic payloads, API contracts, persistence layers.

In many codebases, this logic ends up:

  • duplicated across projects
  • mixed with unrelated string manipulation
  • loosely validated or inconsistently encoded
  • difficult to reason about at call sites

This library exists to make Base64 handling:

  • explicit
  • well-typed
  • easy to audit
  • hard to misuse

It pulls this logic into a single, focused abstraction that can be reused confidently across projects.


What it is

  • A lightweight Swift wrapper around Base64 encoding and decoding
  • Focused on clarity and correctness, not cleverness
  • Designed to be used at system boundaries
  • Small enough to read and understand end-to-end

What it deliberately avoids

  • Convenience extensions that hide failure
  • Silent coercion of invalid input
  • Global helpers scattered across String or Data
  • Over-generalised encoding utilities

If a value cannot be decoded, the API makes that explicit.


Example

let encoded = EncodedBase64("hello world")
let decoded = try encoded.decodedString()

The intent is visible at the call site: you are working with a Base64-encoded value, not an arbitrary string.

Design principles

  • Explicit representation Encoded values are modelled intentionally, not inferred.
  • Fail clearly Invalid input is surfaced immediately rather than silently ignored.
  • Small surface area The library does one thing and stays out of the way.
  • Production-oriented Suitable for authentication, cryptography, and API boundary code.

When to use this

Use this library when:

  • Base64 values are part of your domain or protocol
  • correctness matters more than convenience
  • you want to make encoding/decoding intent obvious in code

If you only need a one-off helper, this may be more structure than you need.

Note

This logic was originally extracted from production WebAuthn-related code and simplified for general reuse. It remains intentionally minimal.

base64-swift

A small Swift library that provides explicit, predictable Base64 encoding and decoding.

Designed for production codebases that need to handle Base64 safely and consistently without scattering string utilities across the app.


Why this exists

In real-world systems, Base64 handling tends to show up at boundaries: authentication flows, cryptographic payloads, API contracts, persistence layers.

In many codebases, this logic ends up:

  • duplicated across projects
  • mixed with unrelated string manipulation
  • loosely validated or inconsistently encoded
  • difficult to reason about at call sites

This library exists to make Base64 handling:

  • explicit
  • well-typed
  • easy to audit
  • hard to misuse

It pulls this logic into a single, focused abstraction that can be reused confidently across projects.


What it is

  • A lightweight Swift wrapper around Base64 encoding and decoding
  • Focused on clarity and correctness, not cleverness
  • Designed to be used at system boundaries
  • Small enough to read and understand end-to-end

What it deliberately avoids

  • Convenience extensions that hide failure
  • Silent coercion of invalid input
  • Global helpers scattered across String or Data
  • Over-generalised encoding utilities

If a value cannot be decoded, the API makes that explicit.


Example

let encoded = EncodedBase64("hello world")
let decoded = try encoded.decodedString()

The intent is visible at the call site: you are working with a Base64-encoded value, not an arbitrary string.

Design principles

  • Explicit representation Encoded values are modelled intentionally, not inferred.
  • Fail clearly Invalid input is surfaced immediately rather than silently ignored.
  • Small surface area The library does one thing and stays out of the way.
  • Production-oriented Suitable for authentication, cryptography, and API boundary code.

When to use this

Use this library when:

  • Base64 values are part of your domain or protocol
  • correctness matters more than convenience
  • you want to make encoding/decoding intent obvious in code

If you only need a one-off helper, this may be more structure than you need.

Acknowledgements

This library was extracted and adapted from Base64 handling logic originally implemented in webauthn-swift-models.

The original project implements parts of the WebAuthn specification in Swift. This package isolates and generalises the Base64-related components for reuse in non-WebAuthn contexts.

Credit and thanks to the original authors and contributors.

About

A lightweight Swift library providing useful utilities for handling Base64 encoding and decoding.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages