Skip to content

Commit

Permalink
bumped supported version to Zig 0.14.0 (to be released soon)
Browse files Browse the repository at this point in the history
  • Loading branch information
r4gus committed Jan 26, 2025
1 parent c5cc3ee commit 30d7b25
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
zig-cache
.zig-cache
zig-out
gyro.lock
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ to share some ideas feel free to open an issue or write me a mail, but please be

## Getting started

Versions
| Zig version | zbor version |
|:-----------:|:------------:|
| 0.13.0 | 0.15.0, 0.15.1, 0.15.2 |
| 0.14.0 | 0.16.0 |

First add this library as a dependency to your `build.zig.zon` file:

```zig
Expand Down
Empty file.
Empty file removed src/.zig-cache/h/timestamp
Empty file.

This file was deleted.

Binary file removed src/.zig-cache/z/53d8da468c12563c8ba398391b5e75e7
Binary file not shown.
Binary file removed src/.zig-cache/z/9336bc0dae9317405c6789805f0dbf96
Binary file not shown.
2 changes: 1 addition & 1 deletion src/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn writeFloat(writer: anytype, f: anytype) !void {
const TInf = @typeInfo(T);

switch (TInf) {
.Float => |float| {
.float => |float| {
switch (float.bits) {
16 => try cbor.encode_2(writer, 0xe0, @as(u64, @intCast(@as(u16, @bitCast(f))))),
32 => try cbor.encode_4(writer, 0xe0, @as(u64, @intCast(@as(u32, @bitCast(f))))),
Expand Down
9 changes: 6 additions & 3 deletions src/cose.zig
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ pub const Key = union(KeyTag) {
/// // Use the key pair...
/// ```
pub fn es256(seed: ?[32]u8) !@This() {
const kp = try EcdsaP256Sha256.KeyPair.create(seed);
const kp = if (seed) |seed_|
try EcdsaP256Sha256.KeyPair.generateDeterministic(seed_)
else
EcdsaP256Sha256.KeyPair.generate();
const sec1 = kp.public_key.toUncompressedSec1();
const pk = kp.secret_key.toBytes();
return .{ .P256 = .{
Expand Down Expand Up @@ -498,7 +501,7 @@ test "es256 sign verify 1" {
const allocator = std.testing.allocator;
const msg = "Hello, World!";

const kp1 = try EcdsaP256Sha256.KeyPair.create(null);
const kp1 = EcdsaP256Sha256.KeyPair.generate();

// Create a signature via cose key struct
var cosep256 = Key.fromP256PrivPub(.Es256, kp1.secret_key, kp1.public_key);
Expand All @@ -522,7 +525,7 @@ test "es256 sign verify 1" {
}

test "copy secure #1" {
const kp1 = try EcdsaP256Sha256.KeyPair.create(null);
const kp1 = EcdsaP256Sha256.KeyPair.generate();
var cosep256 = Key.fromP256PrivPub(.Es256, kp1.secret_key, kp1.public_key);
const cpy = cosep256.copySecure();
try std.testing.expectEqual(cpy.P256.d, null);
Expand Down
22 changes: 11 additions & 11 deletions src/parse.zig
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ pub fn parse(
if (field.type == std.mem.Allocator and options.allocator != null) {
// Assign the allocator that was provided by the caller
@field(r, field.name) = options.allocator.?;
} else if (field.default_value) |default_ptr| {
} else if (field.default_value_ptr) |default_ptr| {
if (!field.is_comptime) {
const default = @as(*align(1) const field.type, @ptrCast(default_ptr)).*;
@field(r, field.name) = default;
Expand Down Expand Up @@ -365,14 +365,14 @@ pub fn parse(
const allocator = options.allocator orelse return ParseError.AllocatorRequired;

switch (ptrInfo.size) {
.One => {
.one => {
// We use *ptrInfo.child instead of T to allow const and non-const types
const r: *ptrInfo.child = try allocator.create(ptrInfo.child);
errdefer allocator.destroy(r);
r.* = try parse(ptrInfo.child, item, options);
return r;
},
.Slice => {
.slice => {
switch (item.getType()) {
.ByteString, .TextString => {
const v = if (item.string()) |x| x else return ParseError.Malformed;
Expand All @@ -381,14 +381,14 @@ pub fn parse(
}

var sentinel: usize = 0;
if (ptrInfo.sentinel != null) {
if (ptrInfo.sentinel_ptr != null) {
sentinel += 1;
}

var r: []ptrInfo.child = try allocator.alloc(ptrInfo.child, v.len + sentinel);
errdefer allocator.free(r);
std.mem.copyForwards(ptrInfo.child, r[0..], v[0..]);
if (ptrInfo.sentinel) |some| {
if (ptrInfo.sentinel_ptr) |some| {
const sentinel_value = @as(*align(1) const ptrInfo.child, @ptrCast(some)).*;
r[r.len - 1] = sentinel_value;
return r[0 .. r.len - 1 :sentinel_value];
Expand All @@ -410,7 +410,7 @@ pub fn parse(
arraylist.appendAssumeCapacity(x);
}

if (ptrInfo.sentinel) |some| {
if (ptrInfo.sentinel_ptr) |some| {
const sentinel_value = @as(*align(1) const ptrInfo.child, @ptrCast(some)).*;
try arraylist.append(sentinel_value);
const output = try arraylist.toOwnedSlice();
Expand Down Expand Up @@ -550,7 +550,7 @@ pub fn stringify(
.float, .comptime_float => {
head = 0xe0;
switch (TInf) {
.Float => |float| {
.float => |float| {
switch (float.bits) {
16 => try encode_2(out, head, @as(u64, @intCast(@as(u16, @bitCast(value))))),
32 => try encode_4(out, head, @as(u64, @intCast(@as(u32, @bitCast(value))))),
Expand All @@ -559,7 +559,7 @@ pub fn stringify(
}
return;
},
.ComptimeFloat => {
.comptime_float => {
// Comptime floats are always encoded as single precision floats
try encode_4(out, head, @as(u64, @intCast(@as(u32, @bitCast(@as(f32, @floatCast(value)))))));
return;
Expand Down Expand Up @@ -712,7 +712,7 @@ pub fn stringify(
}
},
.pointer => |ptr_info| switch (ptr_info.size) {
.Slice => {
.slice => {
if (ptr_info.child == u8) {
head = switch (options.slice_serialization_type) {
.TextString => blk: {
Expand All @@ -737,7 +737,7 @@ pub fn stringify(
}
return;
},
.One => {
.one => {
try stringify(value.*, options, out);
return;
},
Expand Down Expand Up @@ -770,7 +770,7 @@ pub fn stringify(
return value.cborStringify(options, out);
}

const info = @typeInfo(T).Union;
const info = @typeInfo(T).@"union";
if (info.tag_type) |UnionTagType| {
inline for (info.fields) |u_field| {
if (value == @field(UnionTagType, u_field.name)) {
Expand Down

0 comments on commit 30d7b25

Please sign in to comment.