Skip to content

Commit 0384f99

Browse files
committed
fixed
1 parent b2ae4a8 commit 0384f99

File tree

7 files changed

+25
-26
lines changed

7 files changed

+25
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A JWT (JSON Web Token) library for zig.
55

66
### Env
77

8-
- Zig >= 0.15.1
8+
- Zig >= 0.16.0-dev.164+bc7955306.
99

1010

1111
### What the heck is a JWT?

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.{
22
.name = .zig_jwt,
33
.description = "A JWT (JSON Web Token) library for zig.",
4-
.version = "1.3.1",
4+
.version = "1.3.2",
55
.fingerprint = 0x30a5aec248bd7ac3,
66
.minimum_zig_version = "0.15.1",
77
.dependencies = .{},

src/ecdsa.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ pub fn ParseKeyDer(comptime EC: type, comptime CheckOidFn: type) type {
184184

185185
fn checkECDSAPublickeyOid(oid: []const u8) !void {
186186
var buf: [256]u8 = undefined;
187-
var stream = std.Io.fixedBufferStream(&buf);
188-
try oids.decode(oid, stream.writer());
187+
var stream: std.Io.Writer = .fixed(&buf);
188+
try oids.decode(oid, &stream);
189189

190-
const oid_string = stream.getWritten();
190+
const oid_string = stream.written();
191191
if (!std.mem.eql(u8, oid_string, oid_ecdsa_publickey)) {
192192
return error.JWTEcdsaOidError;
193193
}
@@ -197,10 +197,10 @@ fn checkECDSAPublickeyOid(oid: []const u8) !void {
197197

198198
fn checkECDSAPublickeyNamedCurveOid(oid: []const u8, namedcurve_oid: []const u8) !void {
199199
var buf: [256]u8 = undefined;
200-
var stream = std.Io.fixedBufferStream(&buf);
201-
try oids.decode(oid, stream.writer());
200+
var stream: std.Io.Writer = .fixed(&buf);
201+
try oids.decode(oid, &stream);
202202

203-
const oid_string = stream.getWritten();
203+
const oid_string = stream.written();
204204
if (!std.mem.eql(u8, oid_string, namedcurve_oid)) {
205205
return error.JWTEcdsaNamedCurveNotSupport;
206206
}

src/eddsa.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ pub fn parsePublicKeyDer(bytes: []const u8) !Ed25519.PublicKey {
123123

124124
fn checkEdDSAPublickeyOid(oid: []const u8) !void {
125125
var buf: [256]u8 = undefined;
126-
var stream = std.Io.fixedBufferStream(&buf);
127-
try oids.decode(oid, stream.writer());
126+
var stream: std.Io.Writer = .fixed(&buf);
127+
try oids.decode(oid, &stream);
128128

129-
const oid_string = stream.getWritten();
129+
const oid_string = stream.written();
130130
if (!std.mem.eql(u8, oid_string, oid_eddsa_publickey)) {
131131
return error.JWTEdDSAOidError;
132132
}

src/rsa/der.zig

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ pub const Parser = struct {
9696
return Enum.oids.get(oid) orelse {
9797
if (builtin.mode == .Debug) {
9898
var buf: [256]u8 = undefined;
99-
var stream = std.Io.fixedBufferStream(&buf);
100-
try @import("./oid.zig").decode(oid, stream.writer());
101-
log.warn("unknown oid {s} for enum {s}\n", .{ stream.getWritten(), @typeName(Enum) });
99+
var stream: std.Io.Writer = .fixed(&buf);
100+
try @import("./oid.zig").decode(oid, &stream);
101+
log.warn("unknown oid {s} for enum {s}\n", .{ stream.written(), @typeName(Enum) });
102102
}
103103
return error.UnknownObjectId;
104104
};
@@ -223,11 +223,10 @@ pub const Element = struct {
223223
};
224224

225225
pub fn init(bytes: []const u8, index: Index) !Element {
226-
var stream = std.Io.fixedBufferStream(bytes[index..]);
227-
var reader = stream.reader();
226+
var reader = std.Io.Reader.fixed(bytes[index..]);
228227

229-
const identifier = @as(Identifier, @bitCast(try reader.readByte()));
230-
const size_or_len_size = try reader.readByte();
228+
const identifier = @as(Identifier, @bitCast(try reader.takeByte()));
229+
const size_or_len_size = try reader.takeByte();
231230

232231
var start = index + 2;
233232
// short form between 0-127
@@ -242,7 +241,7 @@ pub const Element = struct {
242241
const len_size: u7 = @truncate(size_or_len_size);
243242
start += len_size;
244243
if (len_size > @sizeOf(Index)) return error.InvalidLength;
245-
const len = try reader.readVarInt(Index, .big, len_size);
244+
const len = try reader.takeVarInt(Index, .big, len_size);
246245
if (len < 128) return error.InvalidLength; // should have used short form
247246

248247
const end = std.math.add(Index, start, len) catch return error.InvalidLength;

src/rsa/oid.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn encode(dot_notation: []const u8, buf: []u8) EncodeError![]const u8 {
6161
return buf[0..i];
6262
}
6363

64-
pub fn decode(encoded: []const u8, writer: anytype) @TypeOf(writer).Error!void {
64+
pub fn decode(encoded: []const u8, writer: anytype) !void {
6565
const first = @divTrunc(encoded[0], 40);
6666
const second = encoded[0] - first * 40;
6767
try writer.print("{d}.{d}", .{ first, second });
@@ -102,9 +102,9 @@ fn testOid(expected_encoded: []const u8, expected_dot_notation: []const u8) !voi
102102
const encoded = try encode(expected_dot_notation, &buf);
103103
try std.testing.expectEqualSlices(u8, expected_encoded, encoded);
104104

105-
var stream = std.Io.fixedBufferStream(&buf);
106-
try decode(expected_encoded, stream.writer());
107-
try std.testing.expectEqualStrings(expected_dot_notation, stream.getWritten());
105+
var stream: std.Io.Writer = .fixed(&buf);
106+
try decode(expected_encoded, &stream);
107+
try std.testing.expectEqualStrings(expected_dot_notation, stream.written());
108108
}
109109

110110
test "encode and decode" {

src/rsa/rsa.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,10 @@ pub const CRTValue = struct {
460460

461461
fn checkRSAPublickeyOid(oid: []const u8) !void {
462462
var buf: [256]u8 = undefined;
463-
var stream = std.Io.fixedBufferStream(&buf);
464-
try oids.decode(oid, stream.writer());
463+
var stream: std.Io.Writer = .fixed(&buf);
464+
try oids.decode(oid, &stream);
465465

466-
const oid_string = stream.getWritten();
466+
const oid_string = stream.written();
467467
if (!std.mem.eql(u8, oid_string, oid_rsa_publickey)) {
468468
return error.RSAOidError;
469469
}

0 commit comments

Comments
 (0)