format code.

This commit is contained in:
Kitteh 2021-06-06 12:58:18 +01:00
parent 6c09d63c3d
commit 1b685b5dba
8 changed files with 43 additions and 50 deletions

View file

@ -21,7 +21,9 @@ pub const BufferManager = struct {
}
return null;
}
pub fn deinit(s: *BufferManager, ) void {
pub fn deinit(
s: *BufferManager,
) void {
for (s.buffers.items) |item| {
s.allocator.free(item.Name);
}

View file

@ -3,14 +3,14 @@ const std = @import("std");
const BufferManager = @import("./BufferManager.zig");
const SocketManager = @import("./SocketManager.zig");
const read = @import("./qtshit/read.zig");
const write = @import("./qtshit/write.zig");
const QVariant = @import("./qtshit/types/QVariant.zig").QVariant;
const UserType = @import("./qtshit/types/UserType.zig");
const prettyPrintQVariant = @import("./qtshit/utils/prettyPrintQVariant.zig").prettyPrintQVariant;
const freeQVariant = @import("./qtshit/utils/free/freeQVariant.zig").freeQVariant;
const QVariantMapToQVariantList = @import("./qtshit/utils/QVariantMapToQVariantList.zig").QVariantMapToQVariantList;
const UserType = @import("./qtshit/types/UserType.zig");
fn dumpDebug(name: []const u8, list: std.ArrayList(u8)) !void {
std.debug.print("dumpDebug list len {d}\n", .{list.items.len});
@ -155,10 +155,5 @@ pub const Client = struct {
};
pub fn initClient(allocator: *std.mem.Allocator, stream: *std.net.Stream) Client {
return Client{
.allocator = allocator,
.stream = stream,
.bufferManager = BufferManager.initBufferManager(allocator),
.socketManager = SocketManager.initSocketManager(allocator, stream)
};
return Client{ .allocator = allocator, .stream = stream, .bufferManager = BufferManager.initBufferManager(allocator), .socketManager = SocketManager.initSocketManager(allocator, stream) };
}

View file

@ -38,7 +38,7 @@ pub const ChaCha20Stream = struct {
};
}
fn chacha20Core(x: *BlockVec, input: BlockVec) callconv(.Inline) void {
inline fn chacha20Core(x: *BlockVec, input: BlockVec) void {
x.* = input;
const rounds = comptime [_]QuarterRound{
@ -67,7 +67,7 @@ pub const ChaCha20Stream = struct {
}
}
fn hashToBytes(out: *[64]u8, x: BlockVec) callconv(.Inline) void {
inline fn hashToBytes(out: *[64]u8, x: BlockVec) void {
var i: usize = 0;
while (i < 4) : (i += 1) {
mem.writeIntLittle(u32, out[16 * i + 0 ..][0..4], x[i * 4 + 0]);
@ -77,7 +77,7 @@ pub const ChaCha20Stream = struct {
}
}
fn contextFeedback(x: *BlockVec, ctx: BlockVec) callconv(.Inline) void {
inline fn contextFeedback(x: *BlockVec, ctx: BlockVec) void {
var i: usize = 0;
while (i < 16) : (i += 1) {
x[i] +%= ctx[i];
@ -395,10 +395,10 @@ pub const ecc = struct {
P.* = Q;
}
fn point_double(comptime Curve: type, P: *Jacobian(Curve)) callconv(.Inline) void {
inline fn point_double(comptime Curve: type, P: *Jacobian(Curve)) void {
_ = run_code(Curve, P, P.*, &code.double);
}
fn point_add(comptime Curve: type, P1: *Jacobian(Curve), P2: Jacobian(Curve)) callconv(.Inline) void {
inline fn point_add(comptime Curve: type, P1: *Jacobian(Curve), P2: Jacobian(Curve)) void {
_ = run_code(Curve, P1, P2, &code._add);
}
@ -668,39 +668,39 @@ pub const ecc = struct {
return result;
}
fn MUL31(x: u32, y: u32) callconv(.Inline) u64 {
inline fn MUL31(x: u32, y: u32) u64 {
return @as(u64, x) * @as(u64, y);
}
fn MUL31_lo(x: u32, y: u32) callconv(.Inline) u32 {
inline fn MUL31_lo(x: u32, y: u32) u32 {
return (x *% y) & 0x7FFFFFFF;
}
fn MUX(ctl: u32, x: u32, y: u32) callconv(.Inline) u32 {
inline fn MUX(ctl: u32, x: u32, y: u32) u32 {
return y ^ (@bitCast(u32, -@bitCast(i32, ctl)) & (x ^ y));
}
fn NOT(ctl: u32) callconv(.Inline) u32 {
inline fn NOT(ctl: u32) u32 {
return ctl ^ 1;
}
fn NEQ(x: u32, y: u32) callconv(.Inline) u32 {
inline fn NEQ(x: u32, y: u32) u32 {
const q = x ^ y;
return (q | @bitCast(u32, -@bitCast(i32, q))) >> 31;
}
fn EQ(x: u32, y: u32) callconv(.Inline) u32 {
inline fn EQ(x: u32, y: u32) u32 {
const q = x ^ y;
return NOT((q | @bitCast(u32, -@bitCast(i32, q))) >> 31);
}
fn CMP(x: u32, y: u32) callconv(.Inline) i32 {
inline fn CMP(x: u32, y: u32) i32 {
return @bitCast(i32, GT(x, y)) | -@bitCast(i32, GT(y, x));
}
fn GT(x: u32, y: u32) callconv(.Inline) u32 {
inline fn GT(x: u32, y: u32) u32 {
const z = y -% x;
return (z ^ ((x ^ y) & (x ^ z))) >> 31;
}
fn LT(x: u32, y: u32) callconv(.Inline) u32 {
inline fn LT(x: u32, y: u32) u32 {
return GT(y, x);
}
fn GE(x: u32, y: u32) callconv(.Inline) u32 {
inline fn GE(x: u32, y: u32) u32 {
return NOT(GT(y, x));
}
@ -710,7 +710,7 @@ pub const ecc = struct {
}
}
fn set_zero(out: [*]u32, bit_len: u32) callconv(.Inline) void {
inline fn set_zero(out: [*]u32, bit_len: u32) void {
out[0] = bit_len;
mem.set(u32, (out + 1)[0 .. (bit_len + 31) >> 5], 0);
}
@ -739,7 +739,7 @@ pub const ecc = struct {
return q;
}
fn div(hi: u32, lo: u32, d: u32) callconv(.Inline) u32 {
inline fn div(hi: u32, lo: u32, d: u32) u32 {
var r: u32 = undefined;
return divrem(hi, lo, d, &r);
}

View file

@ -798,7 +798,7 @@ pub const curves = struct {
const pub_key_len = 32;
const Keys = std.crypto.dh.X25519.KeyPair;
fn make_key_pair(rand: *std.rand.Random) callconv(.Inline) Keys {
inline fn make_key_pair(rand: *std.rand.Random) Keys {
while (true) {
var seed: [32]u8 = undefined;
rand.bytes(&seed);
@ -806,11 +806,11 @@ pub const curves = struct {
} else unreachable;
}
fn make_pre_master_secret(
inline fn make_pre_master_secret(
key_pair: Keys,
pre_master_secret_buf: []u8,
server_public_key: *const [32]u8,
) callconv(.Inline) ![]const u8 {
) ![]const u8 {
pre_master_secret_buf[0..32].* = std.crypto.dh.X25519.scalarmult(
key_pair.secret_key,
server_public_key.*,
@ -825,17 +825,17 @@ pub const curves = struct {
const pub_key_len = 97;
const Keys = crypto.ecc.KeyPair(crypto.ecc.SECP384R1);
fn make_key_pair(rand: *std.rand.Random) callconv(.Inline) Keys {
inline fn make_key_pair(rand: *std.rand.Random) Keys {
var seed: [48]u8 = undefined;
rand.bytes(&seed);
return crypto.ecc.make_key_pair(crypto.ecc.SECP384R1, seed);
}
fn make_pre_master_secret(
inline fn make_pre_master_secret(
key_pair: Keys,
pre_master_secret_buf: []u8,
server_public_key: *const [97]u8,
) callconv(.Inline) ![]const u8 {
) ![]const u8 {
pre_master_secret_buf[0..96].* = crypto.ecc.scalarmult(
crypto.ecc.SECP384R1,
server_public_key[1..].*,
@ -851,17 +851,17 @@ pub const curves = struct {
const pub_key_len = 65;
const Keys = crypto.ecc.KeyPair(crypto.ecc.SECP256R1);
fn make_key_pair(rand: *std.rand.Random) callconv(.Inline) Keys {
inline fn make_key_pair(rand: *std.rand.Random) Keys {
var seed: [32]u8 = undefined;
rand.bytes(&seed);
return crypto.ecc.make_key_pair(crypto.ecc.SECP256R1, seed);
}
fn make_pre_master_secret(
inline fn make_pre_master_secret(
key_pair: Keys,
pre_master_secret_buf: []u8,
server_public_key: *const [65]u8,
) callconv(.Inline) ![]const u8 {
) ![]const u8 {
pre_master_secret_buf[0..64].* = crypto.ecc.scalarmult(
crypto.ecc.SECP256R1,
server_public_key[1..].*,
@ -911,7 +911,7 @@ pub const curves = struct {
});
}
fn make_key_pair(comptime list: anytype, curve_id: u16, rand: *std.rand.Random) callconv(.Inline) KeyPair(list) {
inline fn make_key_pair(comptime list: anytype, curve_id: u16, rand: *std.rand.Random) KeyPair(list) {
inline for (list) |curve| {
if (curve.tag == curve_id) {
return @unionInit(KeyPair(list), curve.name, curve.make_key_pair(rand));
@ -920,13 +920,13 @@ pub const curves = struct {
unreachable;
}
fn make_pre_master_secret(
inline fn make_pre_master_secret(
comptime list: anytype,
curve_id: u16,
key_pair: KeyPair(list),
pre_master_secret_buf: *[max_pre_master_secret_len(list)]u8,
server_public_key: [max_pub_key_len(list)]u8,
) callconv(.Inline) ![]const u8 {
) ![]const u8 {
inline for (list) |curve| {
if (curve.tag == curve_id) {
return try curve.make_pre_master_secret(
@ -1350,9 +1350,7 @@ pub fn client_connect(
// Certificate request
const certificate_request_bytes = try hashing_reader.readIntBig(u24);
const hello_done_in_same_record =
if (length == certificate_request_bytes + 8) true
else if (length != certificate_request_bytes) false
else return error.ServerMalformedResponse;
if (length == certificate_request_bytes + 8) true else if (length != certificate_request_bytes) false else return error.ServerMalformedResponse;
// TODO: For now, we are ignoring the certificate types, as they have been somewhat
// superceded by the supported_signature_algorithms field
const certificate_types_bytes = try hashing_reader.readByte();
@ -1576,11 +1574,11 @@ pub fn client_connect(
};
const next_32_bytes = struct {
fn f(
inline fn f(
state: *KeyExpansionState,
comptime chunk_idx: comptime_int,
chunk: *[32]u8,
) callconv(.Inline) void {
) void {
if (chunk_idx == 0) {
Hmac256.create(state.a1[0..32], state.seed, state.master_secret);
Hmac256.create(chunk, state.a1, state.master_secret);

View file

@ -38,4 +38,3 @@ test "QVariantMap -> QVariantList" {
try std.testing.expectEqualStrings("owo", list[2].String);
try std.testing.expect(list[3].Byte == 12);
}

View file

@ -15,7 +15,6 @@ const writeQVariantMap = @import("./writeQVariantMap.zig").writeQVariantMap;
const writeQStringList = @import("./writeQStringList.zig").writeQStringList;
const writeUserType = @import("./usertypes/writeUserType.zig").writeUserType;
pub fn writeQVariant(writer: anytype, allocator: *std.mem.Allocator, variant: QVariantType) (@TypeOf(writer).Error || std.os.WriteError || error{OutOfMemory} || error{InvalidUtf8})!void {
try writeQVariantHeader(writer, try QVariantTypeID(variant));
switch (variant) {