1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//! parse and validate atproto identifiers: at:// URIs, DIDs, handles.
//!
//! run: zig build example-parse-identifiers
const std = @import("std");
const zat = @import("zat");
pub fn main() void {
// an at:// URI addresses a record: authority / collection / rkey.
// this one points at a post by jcsalterego.bsky.social.
const at_uri = "at://did:plc:vc7f4oafdgxsihk4cry2xpze/app.bsky.feed.post/3mpk2wua4jc2x";
const uri = zat.AtUri.parse(at_uri).?;
std.debug.print("{s:<14}{s}\n", .{ "authority:", uri.authority() });
std.debug.print("{s:<14}{s}\n", .{ "collection:", uri.collection().? });
std.debug.print("{s:<14}{s}\n", .{ "rkey:", uri.rkey().? });
const did = zat.Did.parse("did:plc:vc7f4oafdgxsihk4cry2xpze").?;
std.debug.print("{s:<14}{t}\n", .{ "did method:", did.method() });
// Handle.parse returns null for invalid input
std.debug.print("{s:<14}{s}\n", .{ "bsky.app:", validity("bsky.app") });
std.debug.print("{s:<14}{s}\n", .{ "not a handle:", validity("not a handle") });
}
fn validity(handle: []const u8) []const u8 {
return if (zat.Handle.parse(handle) != null) "valid" else "invalid";
}