Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit 978e5db

Browse files
committed
updated keylib to Zig v0.15.1
1 parent 29e5dc4 commit 978e5db

37 files changed

Lines changed: 201 additions & 188 deletions

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ If you want to see an example on how the library could be used, check out [PassK
77
| Zig version | keylib version |
88
|:-----------:|:--------------:|
99
| 0.13.0 | 0.5.0, 0.5.1, 0.5.2, 0.5.3 |
10-
| 0.14.0 | 0.6.0 |
10+
| 0.14.x | 0.6.0, 0.6.1 |
11+
| 0.15.x | 0.7.0 |
1112

1213
## QA
1314

bindings/linux/src/uhid-c.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export fn uhid_write_packet(fd: c_int, in: [*c]u8, len: usize) c_int {
5959
@memcpy(rev.u.input.data[0..len], in[0..len]);
6060
rev.u.input.size = @as(c_ushort, @intCast(len));
6161

62-
uhid_write(device, &rev) catch {
62+
uhid_write(device, @ptrCast(&rev)) catch {
6363
std.log.err("failed to send CTAPHID packet\n", .{});
6464
return 0;
6565
};

bindings/linux/src/uhid.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub const Uhid = struct {
7676
@memcpy(rev.u.input.data[0..in.len], in[0..]);
7777
rev.u.input.size = @as(c_ushort, @intCast(in.len));
7878

79-
uhid_write(self.device, &rev) catch |e| {
79+
uhid_write(self.device, @ptrCast(&rev)) catch |e| {
8080
std.log.err("failed to send CTAPHID packet\n", .{});
8181
return e;
8282
};

build.zig.zon

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
.{
22
.name = .keylib,
3-
.version = "0.6.1",
3+
.version = "0.7.0",
44
.fingerprint = 0xc25aabcf9323b699,
55
.dependencies = .{
66
.zbor = .{
7-
.url = "https://github.com/r4gus/zbor/archive/refs/tags/0.17.2.tar.gz",
8-
.hash = "zbor-0.17.0-kr-CoHIkAwCy2WhoS6MgwSvyQsLWzzNy6a7UTHqMPMmO",
7+
.url = "https://github.com/r4gus/zbor/archive/refs/tags/0.20.1.tar.gz",
8+
.hash = "zbor-0.20.0-kr-CoK1kAwDtdlkCAsc43I4FkS-G2GJ0buELN1gCVfLN",
99
},
1010
.hidapi = .{
11-
.url = "https://github.com/r4gus/hidapi/archive/refs/tags/0.15.0.tar.gz",
12-
.hash = "1220fcaee19f1bf69764c808ea7292062ebf4ec55f585ef298667c993e54bfbc8cb0",
11+
.url = "https://github.com/r4gus/hidapi/archive/refs/tags/0.16.0.tar.gz",
12+
.hash = "hidapi-0.16.0-470BSmniGwCMJlhcDUFoW8Lw80CRGWngB876THiu8Ryf",
1313
},
1414
.uuid = .{
15-
.url = "https://github.com/r4gus/uuid-zig/archive/refs/tags/0.3.1.tar.gz",
16-
.hash = "uuid-0.3.0-oOieIYF1AAA_BtE7FvVqqTn5uEYTvvz7ycuVnalCOf8C",
15+
.url = "https://github.com/r4gus/uuid-zig/archive/refs/tags/0.4.0.tar.gz",
16+
.hash = "uuid-0.4.0-oOieIR2AAAChAUVBY4ABjYI1XN0EbVALmiN0JIlggC3i",
1717
},
1818
},
1919
.paths = .{

example/authenticator.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ pub fn main() !void {
153153
}
154154
}
155155
}
156-
std.time.sleep(10000000);
156+
var timer = try std.time.Timer.start();
157+
while (timer.read() < 10000000) {}
157158
}
158159
}
159160

@@ -162,7 +163,7 @@ pub fn main() !void {
162163
// /////////////////////////////////////////
163164

164165
// For this example we use a volatile storage solution for our credentials.
165-
var data_set = std.ArrayList(Credential).init(allocator);
166+
var data_set: std.ArrayListUnmanaged(Credential) = .empty;
166167
var fetch_index: ?usize = null;
167168
var fetch_id: ?dt.ABS64B = null;
168169
var fetch_rp: ?dt.ABS128T = null;
@@ -351,12 +352,12 @@ pub fn my_write(
351352
}
352353
}
353354

354-
try data_set.append(data);
355+
try data_set.append(allocator, data);
355356
}
356357

357358
pub fn my_delete(
358359
id: [*c]const u8,
359-
) callconv(.C) Error {
360+
) callconv(.c) Error {
360361
_ = id;
361362
return Error.Other;
362363
}

example/client.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn main() !void {
5151
defer device.close();
5252

5353
// Get information about the device and its capabilities
54-
const infos = try (try authenticatorGetInfo(device)).@"await"(allocator);
54+
const infos = try (try authenticatorGetInfo(device)).await(allocator);
5555
defer infos.deinit(allocator);
5656
const info = try infos.deserializeCbor(Info, allocator);
5757
defer info.deinit(allocator);
@@ -129,13 +129,13 @@ pub fn main() !void {
129129
break :blk ""; // here we would return a token generated via getPinUvAuthTokenUsingPinWithPermissions
130130
};
131131
defer allocator.free(token);
132-
std.log.info("token: {s}", .{std.fmt.fmtSliceHexLower(token)});
132+
std.log.info("token: {x}", .{token});
133133

134134
// 4 the platform collects all RPs present on the given authenticator, removes RPs that
135135
// are not supported IdPs, and then selects the IdP for authentication
136136

137137
// 4.a Create a empty set of idps
138-
var idps = std.ArrayList([]const u8).init(allocator);
138+
var idps: std.ArrayList([]const u8) = .empty;
139139
defer {
140140
for (idps.items) |idp| {
141141
allocator.free(idp);
@@ -145,12 +145,12 @@ pub fn main() !void {
145145
// 4.b Fill the set with RPs present on the authenticator
146146
const rp = try cred_management.enumerateRPsBegin(device, pinUvAuthProtocol, token, allocator, true);
147147
if (rp) |_rp| {
148-
try idps.append(try allocator.dupe(u8, _rp.rp.id.get()));
148+
try idps.append(allocator, try allocator.dupe(u8, _rp.rp.id.get()));
149149

150150
var i: usize = 0;
151151
while (i < _rp.total.? - 1) : (i += 1) {
152152
if (try cred_management.enumerateRPsGetNextRP(device, allocator, true)) |rp2| {
153-
try idps.append(try allocator.dupe(u8, rp2.rp.id.get()));
153+
try idps.append(allocator, try allocator.dupe(u8, rp2.rp.id.get()));
154154
}
155155
}
156156
} else {
@@ -215,7 +215,7 @@ pub fn main() !void {
215215
}
216216
},
217217
.fulfilled => |d| {
218-
std.log.info("{s}", .{std.fmt.fmtSliceHexLower(d)});
218+
std.log.info("{x}", .{d});
219219
break;
220220
},
221221
.rejected => |e| {

lib/client/Transports.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ pub fn deinit(self: *const Self) void {
3232

3333
/// Find all connected devices
3434
pub fn enumerate(a: std.mem.Allocator, options: EnumerateOptions) Error!Self {
35-
var arr = std.ArrayList(Transport).init(a);
36-
defer arr.deinit();
35+
var arr: std.ArrayListUnmanaged(Transport) = .empty;
36+
defer arr.deinit(a);
3737

3838
for (options.funs) |fun| {
3939
if (try fun(a)) |v| {
40-
try arr.appendSlice(v);
40+
try arr.appendSlice(a, v);
4141
}
4242
}
4343

4444
return Self{
45-
.devices = try arr.toOwnedSlice(),
45+
.devices = try arr.toOwnedSlice(a),
4646
.allocator = a,
4747
};
4848
}

lib/client/cbor_commands.zig

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub const Promise = struct {
5050
/// Wait until the promise is fulfilled.
5151
///
5252
/// Either returns fulfilled or an error.
53-
pub fn @"await"(self: *const @This(), allocator: std.mem.Allocator) !State {
53+
pub fn await(self: *const @This(), allocator: std.mem.Allocator) !State {
5454
while (true) {
5555
const S = self.get(allocator);
5656

@@ -243,15 +243,15 @@ pub const credentials = struct {
243243
};
244244
defer a.free(request.rpId);
245245

246-
var arr = std.ArrayList(u8).init(a);
246+
var arr = std.Io.Writer.Allocating.init(a);
247247
defer arr.deinit();
248248

249-
try arr.append(cmd);
250-
try cbor.stringify(request, .{}, arr.writer());
249+
try arr.writer.writeByte(cmd);
250+
try cbor.stringify(request, .{}, &arr.writer);
251251

252-
std.log.info("{s}", .{std.fmt.fmtSliceHexLower(arr.items)});
252+
std.log.info("{x}", .{arr.written()});
253253

254-
try t.write(arr.items);
254+
try t.write(arr.written());
255255

256256
return Promise.new(t, public_key.timeout);
257257
}
@@ -307,15 +307,15 @@ pub const credentials = struct {
307307
.allowList = try keylib.common.dt.ABSPublicKeyCredentialDescriptor.fromSlice(public_key.allowCredentials),
308308
};
309309

310-
var arr = std.ArrayList(u8).init(a);
310+
var arr = std.Io.Writer.Allocating.init(a);
311311
defer arr.deinit();
312312

313-
try arr.append(cmd);
314-
try cbor.stringify(request, .{}, arr.writer());
313+
try arr.writer.writeByte(cmd);
314+
try cbor.stringify(request, .{}, &arr.writer);
315315

316-
std.log.info("{s}", .{std.fmt.fmtSliceHexLower(arr.items)});
316+
std.log.info("{s}", .{arr.written()});
317317

318-
try t.write(arr.items);
318+
try t.write(arr.written());
319319

320320
return Promise.new(t, public_key.timeout);
321321
}
@@ -330,24 +330,24 @@ pub const credentials = struct {
330330
origin: []const u8,
331331
crossOrigin: bool,
332332
) ![]const u8 {
333-
var out = std.ArrayList(u8).init(a);
333+
var out = std.Io.Writer.Allocating.init(a);
334334
errdefer out.deinit();
335335

336-
try out.appendSlice("{\"type\":");
337-
try CCDToString(out.writer(), typ);
338-
try out.appendSlice(",\"challenge\":");
339-
try CCDToString(out.writer(), challenge);
340-
try out.appendSlice(",\"origin\":");
341-
try CCDToString(out.writer(), origin);
342-
try out.appendSlice(",\"crossOrigin\":");
343-
try out.appendSlice(if (crossOrigin) "true" else "false");
336+
try out.writer.writeAll("{\"type\":");
337+
try CCDToString(&out.writer, typ);
338+
try out.writer.writeAll(",\"challenge\":");
339+
try CCDToString(&out.writer, challenge);
340+
try out.writer.writeAll(",\"origin\":");
341+
try CCDToString(&out.writer, origin);
342+
try out.writer.writeAll(",\"crossOrigin\":");
343+
try out.writer.writeAll(if (crossOrigin) "true" else "false");
344344
// TODO: handle tokenBinding
345-
try out.appendSlice("}");
345+
try out.writer.writeAll("}");
346346

347347
return try out.toOwnedSlice();
348348
}
349349

350-
pub fn CCDToString(out: anytype, in: []const u8) !void {
350+
pub fn CCDToString(out: *std.Io.Writer, in: []const u8) !void {
351351
var i: usize = 0;
352352

353353
std.log.info("{s}", .{in});
@@ -429,13 +429,13 @@ pub const client_pin = struct {
429429
.subCommand = .getKeyAgreement,
430430
};
431431

432-
var arr = std.ArrayList(u8).init(a);
432+
var arr = std.Io.Writer.Allocating.init(a);
433433
defer arr.deinit();
434434

435-
try arr.append(cmd);
436-
try cbor.stringify(request, .{}, arr.writer());
435+
try arr.writer.writeByte(cmd);
436+
try cbor.stringify(request, .{}, &arr.writer);
437437

438-
try t.write(arr.items);
438+
try t.write(arr.written());
439439

440440
if (try t.read(a)) |response| {
441441
defer a.free(response);
@@ -511,13 +511,13 @@ pub const client_pin = struct {
511511
}
512512
request.pinHashEnc = try keylib.common.dt.ABS32B.fromSlice(pinHashEnc);
513513

514-
var arr = std.ArrayList(u8).init(a);
514+
var arr = std.Io.Writer.Allocating.init(a);
515515
defer arr.deinit();
516516

517-
try arr.append(cmd);
518-
try cbor.stringify(request, .{}, arr.writer());
517+
try arr.writer.writeByte(cmd);
518+
try cbor.stringify(request, .{}, &arr.writer);
519519

520-
try t.write(arr.items);
520+
try t.write(arr.written());
521521

522522
if (try t.read(a)) |response| {
523523
defer a.free(response);
@@ -600,13 +600,13 @@ pub const client_pin = struct {
600600
}
601601
request.pinHashEnc = pinHashEnc;
602602

603-
var arr = std.ArrayList(u8).init(a);
603+
var arr = std.Io.Writer.Allocating.init(a);
604604
defer arr.deinit();
605605

606-
try arr.append(cmd);
607-
try cbor.stringify(request, .{}, arr.writer());
606+
try arr.writer.writeByte(cmd);
607+
try cbor.stringify(request, .{}, &arr.writer);
608608

609-
try t.write(arr.items);
609+
try t.write(arr.written());
610610

611611
if (try t.read(a)) |response| {
612612
defer a.free(response);
@@ -659,13 +659,13 @@ pub const client_pin = struct {
659659
request.rpId = id;
660660
}
661661

662-
var arr = std.ArrayList(u8).init(a);
662+
var arr = std.Io.Writer.Allocating.init(a);
663663
defer arr.deinit();
664664

665-
try arr.append(cmd);
666-
try cbor.stringify(request, .{}, arr.writer());
665+
try arr.writer.writeByte(cmd);
666+
try cbor.stringify(request, .{}, &arr.writer);
667667

668-
try t.write(arr.items);
668+
try t.write(arr.written());
669669

670670
if (try t.read(a)) |response| {
671671
defer a.free(response);
@@ -730,13 +730,13 @@ pub const cred_management = struct {
730730
.pinUvAuthParam = _param.get(),
731731
};
732732

733-
var arr = std.ArrayList(u8).init(a);
733+
var arr = std.Io.Writer.Allocating.init(a);
734734
defer arr.deinit();
735735

736-
try arr.append(if (is_yubikey) 0x41 else 0x0a);
737-
try cbor.stringify(request, .{}, arr.writer());
736+
try arr.writer.writeByte(if (is_yubikey) 0x41 else 0x0a);
737+
try cbor.stringify(request, .{}, &arr.writer);
738738

739-
try t.write(arr.items);
739+
try t.write(arr.written());
740740

741741
if (try t.read(a)) |response| {
742742
defer a.free(response);
@@ -780,13 +780,13 @@ pub const cred_management = struct {
780780
.subCommand = .enumerateRPsGetNextRP,
781781
};
782782

783-
var arr = std.ArrayList(u8).init(a);
783+
var arr = std.Io.Writer.Allocating.init(a);
784784
defer arr.deinit();
785785

786-
try arr.append(if (is_yubikey) 0x41 else 0x0a);
787-
try cbor.stringify(request, .{}, arr.writer());
786+
try arr.writer.writeByte(if (is_yubikey) 0x41 else 0x0a);
787+
try cbor.stringify(request, .{}, &arr.writer);
788788

789-
try t.write(arr.items);
789+
try t.write(arr.written());
790790

791791
if (try t.read(a)) |response| {
792792
defer a.free(response);

lib/client/transports/usb.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ pub fn enumerate(a: std.mem.Allocator) Transports.Error!?[]Transport {
149149

150150
if (devices == null) return null;
151151

152-
var arr = std.ArrayList(Transport).init(a);
153-
defer arr.deinit();
152+
var arr: std.ArrayList(Transport) = .empty;
153+
defer arr.deinit(a);
154154

155155
while (true) {
156156
if (devices.*.usage_page == 0xf1d0 and devices.*.usage == 0x01) {
@@ -172,17 +172,17 @@ pub fn enumerate(a: std.mem.Allocator) Transports.Error!?[]Transport {
172172
._deinit = deinit,
173173
};
174174

175-
arr.append(t) catch {
176-
arr.deinit();
175+
arr.append(a, t) catch {
176+
arr.deinit(a);
177177
return null;
178178
};
179179
}
180180
if (devices.*.next == null) break;
181181
devices = devices.*.next;
182182
}
183183

184-
return arr.toOwnedSlice() catch {
185-
arr.deinit();
184+
return arr.toOwnedSlice(a) catch {
185+
arr.deinit(a);
186186
return null;
187187
};
188188
}

lib/common/AttestationStatement.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub const AttestationStatement = union(fido.common.AttestationStatementFormatIde
3838
/// Enumeration (enum AttestationConveyancePreference).
3939
none: struct {}, // no attestation
4040

41-
pub fn cborStringify(self: *const @This(), options: cbor.Options, out: anytype) !void {
41+
pub fn cborStringify(self: *const @This(), options: cbor.Options, out: *std.Io.Writer) !void {
4242
return cbor.stringify(self, .{
4343
.allocator = options.allocator,
4444
.ignore_override = true,

0 commit comments

Comments
 (0)