Skip to content

Commit 228f6b5

Browse files
Copilot0xrinegade
andcommitted
Complete Zig 0.15.1 API compatibility fixes - project builds successfully
Co-authored-by: 0xrinegade <101195284+0xrinegade@users.noreply.github.com>
1 parent 2df6204 commit 228f6b5

File tree

7 files changed

+44
-41
lines changed

7 files changed

+44
-41
lines changed

src/blockchain/client.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ pub const BlockchainClient = struct {
260260

261261
// Convert to hex string
262262
var order_id_buffer: [BlockchainConstants.ORDER_ID_HEX_LENGTH]u8 = undefined;
263-
const order_id = std.fmt.bufPrint(&order_id_buffer, "{}", .{std.fmt.fmtSliceHexLower(&order_id_bytes)}) catch return error.OrderIdGenerationFailed;
263+
const order_id = std.fmt.bufPrint(&order_id_buffer, "{s}", .{std.fmt.bytesToHex(&order_id_bytes, .lower)}) catch return error.OrderIdGenerationFailed;
264264

265265
return try self.allocator.dupe(u8, order_id);
266266
}
@@ -346,14 +346,14 @@ pub const Orderbook = struct {
346346
pub fn deinit(self: *Orderbook, allocator: std.mem.Allocator) void {
347347
// Clear and free order data securely
348348
for (self.bids) |bid| {
349-
std.crypto.utils.secureZero(u8, @constCast(bid.order_id));
350-
std.crypto.utils.secureZero(u8, @constCast(bid.owner_address));
349+
@memset(@constCast(bid.order_id), 0);
350+
@memset(@constCast(bid.owner_address), 0);
351351
allocator.free(bid.order_id);
352352
allocator.free(bid.owner_address);
353353
}
354354
for (self.asks) |ask| {
355-
std.crypto.utils.secureZero(u8, @constCast(ask.order_id));
356-
std.crypto.utils.secureZero(u8, @constCast(ask.owner_address));
355+
@memset(@constCast(ask.order_id), 0);
356+
@memset(@constCast(ask.owner_address), 0);
357357
allocator.free(ask.order_id);
358358
allocator.free(ask.owner_address);
359359
}
@@ -363,8 +363,8 @@ pub const Orderbook = struct {
363363
allocator.free(self.asks);
364364

365365
// Clear and free market data
366-
std.crypto.utils.secureZero(u8, @constCast(self.market));
367-
std.crypto.utils.secureZero(u8, @constCast(self.market_address));
366+
@memset(@constCast(self.market), 0);
367+
@memset(@constCast(self.market_address), 0);
368368
allocator.free(self.market);
369369
allocator.free(self.market_address);
370370
}

src/blockchain/error.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub const ErrorHandler = struct {
101101
// If this isn't the first attempt, apply exponential backoff
102102
if (retry_count > 0) {
103103
const delay_ms = self.base_delay_ms * (@as(u32, 1) << @intCast(retry_count - 1));
104-
std.time.sleep(delay_ms * std.time.ns_per_ms);
104+
std.Thread.sleep(delay_ms * std.time.ns_per_ms);
105105

106106
// Log retry attempt
107107
std.debug.print("Retrying operation (attempt {d}/{d})...\n", .{ retry_count, self.max_retries });
@@ -130,7 +130,7 @@ pub const ErrorHandler = struct {
130130
// Rate limiting requires retry with backoff
131131
BlockchainError.RateLimitExceeded => {
132132
// Add extra delay for rate limit errors
133-
std.time.sleep(BlockchainConstants.RATE_LIMIT_EXTRA_DELAY_MS * std.time.ns_per_ms);
133+
std.Thread.sleep(BlockchainConstants.RATE_LIMIT_EXTRA_DELAY_MS * std.time.ns_per_ms);
134134
if (retry_count < self.max_retries) {
135135
continue;
136136
} else {

src/blockchain/signer.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub const TransactionSigner = struct {
5757
size,
5858
timestamp,
5959
nonce,
60-
std.fmt.fmtSliceHexLower(&self.keypair.public_key.bytes),
60+
std.fmt.bytesToHex(&self.keypair.public_key.bytes, .lower),
6161
}
6262
);
6363

@@ -97,7 +97,7 @@ pub const TransactionSigner = struct {
9797
order_id,
9898
timestamp,
9999
nonce,
100-
std.fmt.fmtSliceHexLower(&self.keypair.public_key.bytes),
100+
std.fmt.bytesToHex(&self.keypair.public_key.bytes, .lower),
101101
}
102102
);
103103

src/cli.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ pub fn execute(registry: *CommandRegistry, args: []const []const u8) !void {
9494
}
9595

9696
// Stage 3: Sanitize command arguments
97-
var sanitized_args = std.ArrayList([]const u8).init(std.heap.page_allocator);
97+
var sanitized_args = std.ArrayList([]const u8){};
9898
defer {
9999
for (sanitized_args.items) |arg| {
100100
std.heap.page_allocator.free(arg);
101101
}
102-
sanitized_args.deinit();
102+
sanitized_args.deinit(std.heap.page_allocator);
103103
}
104104

105105
for (command_args) |arg| {
@@ -128,7 +128,7 @@ pub fn execute(registry: *CommandRegistry, args: []const []const u8) !void {
128128
continue;
129129
}
130130

131-
try sanitized_args.append(try std.heap.page_allocator.dupe(u8, arg_result.cleaned_input));
131+
try sanitized_args.append(std.heap.page_allocator, try std.heap.page_allocator.dupe(u8, arg_result.cleaned_input));
132132
}
133133

134134
// Validate command name is not empty after sanitization

src/cli/input_sanitizer.zig

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ pub const InputSanitizer = struct {
9090
continue;
9191
};
9292

93-
try normalized.appendSlice(utf8_bytes[0..written]);
93+
try normalized.appendSlice(self.allocator, utf8_bytes[0..written]);
9494
i += utf8_len;
9595
}
9696

97-
return normalized.toOwnedSlice();
97+
return normalized.toOwnedSlice(self.allocator);
9898
}
9999

100100
/// Apply normalization rules to individual codepoints
@@ -475,7 +475,7 @@ pub const InputSanitizer = struct {
475475
if (input.len == 0) return .BLOCKED;
476476

477477
// Check for valid command format: command [subcommand] [args...]
478-
var parts = std.mem.split(u8, input, " ");
478+
var parts = std.mem.splitSequence(u8, input, " ");
479479
const command = parts.next() orelse return .BLOCKED;
480480

481481
// Validate command name (alphanumeric and hyphens only)
@@ -520,13 +520,13 @@ pub const InputSanitizer = struct {
520520

521521
for (input) |char| {
522522
switch (char) {
523-
'"' => try escaped.appendSlice("\\\""),
524-
'\\' => try escaped.appendSlice("\\\\"),
525-
'\n' => try escaped.appendSlice("\\n"),
526-
'\r' => try escaped.appendSlice("\\r"),
527-
'\t' => try escaped.appendSlice("\\t"),
523+
'"' => try escaped.appendSlice(self.allocator, "\\\""),
524+
'\\' => try escaped.appendSlice(self.allocator, "\\\\"),
525+
'\n' => try escaped.appendSlice(self.allocator, "\\n"),
526+
'\r' => try escaped.appendSlice(self.allocator, "\\r"),
527+
'\t' => try escaped.appendSlice(self.allocator, "\\t"),
528528
0...8, 11...12, 14...31, 127...255 => {
529-
try escaped.writer().print("\\x{X:0>2}", .{char});
529+
try escaped.writer(self.allocator).print("\\x{X:0>2}", .{char});
530530
},
531531
else => try escaped.append(self.allocator, char),
532532
}
@@ -559,7 +559,7 @@ pub const InputSanitizer = struct {
559559

560560
// Phase 3: Pattern combination analysis
561561
if (suspicion_score >= 3.0) {
562-
try result.blocked_patterns.append(try self.allocator.dupe(u8, "Multiple suspicious patterns detected"));
562+
try result.blocked_patterns.append(self.allocator, try self.allocator.dupe(u8, "Multiple suspicious patterns detected"));
563563
return .BLOCKED;
564564
}
565565

@@ -592,10 +592,10 @@ pub const InputSanitizer = struct {
592592
}
593593

594594
if (url_encoded_count > input.len / 4) {
595-
try result.blocked_patterns.append(try std.fmt.allocPrint(self.allocator, "Excessive URL encoding: {d} encoded chars", .{url_encoded_count}));
595+
try result.blocked_patterns.append(self.allocator, try std.fmt.allocPrint(self.allocator, "Excessive URL encoding: {d} encoded chars", .{url_encoded_count}));
596596
return .BLOCKED;
597597
} else if (url_encoded_count > 5) {
598-
try result.warnings.append(try std.fmt.allocPrint(self.allocator, "URL encoding detected: {d} chars", .{url_encoded_count}));
598+
try result.warnings.append(self.allocator, try std.fmt.allocPrint(self.allocator, "URL encoding detected: {d} chars", .{url_encoded_count}));
599599
encoding_level = .SUSPICIOUS;
600600
}
601601

@@ -613,7 +613,7 @@ pub const InputSanitizer = struct {
613613
}
614614

615615
if (hex_count > 3) {
616-
try result.warnings.append(try std.fmt.allocPrint(self.allocator, "Multiple hex patterns: {d}", .{hex_count}));
616+
try result.warnings.append(self.allocator, try std.fmt.allocPrint(self.allocator, "Multiple hex patterns: {d}", .{hex_count}));
617617
encoding_level = .SUSPICIOUS;
618618
}
619619
}
@@ -627,7 +627,7 @@ pub const InputSanitizer = struct {
627627

628628
// Analyze command-like structures
629629
if (input.len > 0 and (input[0] == '/' or input[0] == '\\' or input[0] == '.')) {
630-
try result.warnings.append(try self.allocator.dupe(u8, "Path-like input detected"));
630+
try result.warnings.append(self.allocator, try self.allocator.dupe(u8, "Path-like input detected"));
631631
context_level = .SUSPICIOUS;
632632
}
633633

@@ -646,7 +646,7 @@ pub const InputSanitizer = struct {
646646
}
647647

648648
if (bracket_count > 4 and paren_count > 2) {
649-
try result.warnings.append(try self.allocator.dupe(u8, "Script-like structure detected"));
649+
try result.warnings.append(self.allocator, try self.allocator.dupe(u8, "Script-like structure detected"));
650650
context_level = .SUSPICIOUS;
651651
}
652652

@@ -661,7 +661,7 @@ pub const InputSanitizer = struct {
661661
}
662662

663663
if (sql_keyword_count >= 2) {
664-
try result.blocked_patterns.append(try self.allocator.dupe(u8, "SQL-like command structure detected"));
664+
try result.blocked_patterns.append(self.allocator, try self.allocator.dupe(u8, "SQL-like command structure detected"));
665665
return .BLOCKED;
666666
}
667667

@@ -683,18 +683,18 @@ pub const InputSanitizer = struct {
683683
// Check for excessive repetition of any character
684684
for (char_freq, 0..) |freq, char| {
685685
if (freq > input.len / 2 and freq > 10) {
686-
try result.warnings.append(try std.fmt.allocPrint(self.allocator, "Excessive character repetition: '{c}' appears {d} times", .{ @as(u8, @intCast(char)), freq }));
686+
try result.warnings.append(self.allocator, try std.fmt.allocPrint(self.allocator, "Excessive character repetition: '{c}' appears {d} times", .{ @as(u8, @intCast(char)), freq }));
687687
stats_level = .SUSPICIOUS;
688688
}
689689
}
690690

691691
// Entropy analysis (simplified)
692692
const entropy = self.calculateEntropy(input);
693693
if (entropy < 1.0) {
694-
try result.warnings.append(try std.fmt.allocPrint(self.allocator, "Low entropy input: {d:.2}", .{entropy}));
694+
try result.warnings.append(self.allocator, try std.fmt.allocPrint(self.allocator, "Low entropy input: {d:.2}", .{entropy}));
695695
stats_level = .SUSPICIOUS;
696696
} else if (entropy > 7.0) {
697-
try result.warnings.append(try std.fmt.allocPrint(self.allocator, "High entropy input (possible encoded): {d:.2}", .{entropy}));
697+
try result.warnings.append(self.allocator, try std.fmt.allocPrint(self.allocator, "High entropy input (possible encoded): {d:.2}", .{entropy}));
698698
stats_level = .SUSPICIOUS;
699699
}
700700

@@ -710,12 +710,12 @@ pub const InputSanitizer = struct {
710710
}
711711

712712
if (space_count < input.len / 20) { // Very few spaces in long input
713-
try result.warnings.append(try self.allocator.dupe(u8, "Long input with minimal spacing (possible obfuscation)"));
713+
try result.warnings.append(self.allocator, try self.allocator.dupe(u8, "Long input with minimal spacing (possible obfuscation)"));
714714
stats_level = .SUSPICIOUS;
715715
}
716716

717717
if (special_char_count > input.len / 3) { // Too many special characters
718-
try result.warnings.append(try self.allocator.dupe(u8, "High special character density"));
718+
try result.warnings.append(self.allocator, try self.allocator.dupe(u8, "High special character density"));
719719
stats_level = .SUSPICIOUS;
720720
}
721721
}
@@ -738,7 +738,7 @@ pub const InputSanitizer = struct {
738738

739739
for (script_variations) |variation| {
740740
if (std.mem.indexOf(u8, input, variation)) |_| {
741-
try result.blocked_patterns.append(try std.fmt.allocPrint(self.allocator, "Obfuscated script pattern: {s}", .{variation}));
741+
try result.blocked_patterns.append(self.allocator, try std.fmt.allocPrint(self.allocator, "Obfuscated script pattern: {s}", .{variation}));
742742
return .BLOCKED;
743743
}
744744
}
@@ -753,7 +753,7 @@ pub const InputSanitizer = struct {
753753

754754
for (cmd_patterns) |pattern| {
755755
if (std.mem.indexOf(u8, input, pattern)) |_| {
756-
try result.warnings.append(try std.fmt.allocPrint(self.allocator, "Spaced command pattern: {s}", .{pattern}));
756+
try result.warnings.append(self.allocator, try std.fmt.allocPrint(self.allocator, "Spaced command pattern: {s}", .{pattern}));
757757
fuzzy_level = .DANGEROUS;
758758
}
759759
}

src/cli/tui.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ pub fn run() !void {
6363
std.debug.print("\nPress any key to exit...\n", .{});
6464

6565
// Wait for input (simplified for this example)
66-
const stdin = std.io.getStdIn().reader();
67-
_ = try stdin.readByte();
66+
const stdin_file = std.fs.File{ .handle = std.posix.STDIN_FILENO };
67+
var buffer: [1]u8 = undefined;
68+
var stdin = stdin_file.reader(&buffer);
69+
var read_buf: [1]u8 = undefined;
70+
_ = try stdin.read(&read_buf);
6871

6972
std.debug.print("Exiting TUI...\n", .{});
7073
}

src/services/enhanced_orders.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub const EnhancedOrderService = struct {
241241
};
242242
defer {
243243
// Secure cleanup of signature
244-
std.crypto.utils.secureZero(u8, @constCast(signature));
244+
@memset(@constCast(signature), 0);
245245
self.allocator.free(signature);
246246
}
247247

@@ -353,7 +353,7 @@ pub const EnhancedOrderService = struct {
353353
};
354354
defer {
355355
// Secure cleanup of signature
356-
std.crypto.utils.secureZero(u8, @constCast(signature));
356+
@memset(@constCast(signature), 0);
357357
self.allocator.free(signature);
358358
}
359359

0 commit comments

Comments
 (0)