https://github.com/zigster64/paseto.zig
A Zig implementation of Paseto token encode / decode as an alternative to JWT
https://github.com/zigster64/paseto.zig
paseto paseto-v4 zig-package
Last synced: 9 days ago
JSON representation
A Zig implementation of Paseto token encode / decode as an alternative to JWT
- Host: GitHub
- URL: https://github.com/zigster64/paseto.zig
- Owner: zigster64
- License: mit
- Created: 2025-08-05T23:36:09.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-11-15T01:36:29.000Z (7 months ago)
- Last Synced: 2025-11-15T03:33:36.345Z (7 months ago)
- Topics: paseto, paseto-v4, zig-package
- Language: Zig
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# paseto.zig
A Zig implementation of Paseto token encode / decode as an alternative to JWT
This implementation is assumed to be used in a web backend, therefore :
- Implements local v4 only
- Takes an arena allocator (which your handler should provide), which makes MM much simpler
and allows for the JSON decoder to use the parseFromSliceLeaky variant
Tested and works with http.zig 0.15.1
# Install
1) Add paseto.zig as a dependency in your `build.zig.zon`:
```bash
zig fetch --save "git+https://github.com/zigster64/paseto.zig#master"
```
2) In your `build.zig`, add the `paseto` module as an import on your executable target
# Test
`zig build run` will run a local test of encoding a struct into JSON, encoding it into
a paseto token, then decoding it, then printing it.
# Encode - Create a local token with encrypted payload
```
/// Generates a PASETO v4.local token from a payload and secret key
/// payload: any type that can be serialized to JSON
/// secret_key: exactly 32 bytes for ChaCha20-Poly1305 encryption
pub fn encode(
arena: Allocator,
payload: anytype,
secret_key: []const u8,
) ![]u8
```
# Decode - Validate a token and extract its payload
```
/// Decodes a PASETO v4.local token as JSON, and then parses the
/// JSON payload into the given comptime struct.
/// Returns an instance of that type
pub fn decode(
arena: Allocator,
token: []const u8,
secret_key: []const u8,
comptime T: type,
) !T
```