aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/CodeSignature.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2020-11-20 10:11:16 +0100
committerJakub Konka <kubkon@jakubkonka.com>2020-11-26 11:50:09 +0100
commitd14cd59ef0d9f03114ea6467a8446c17bf33ab9a (patch)
tree31b67942ac16abe960670a1d1378995532ce953e /src/link/MachO/CodeSignature.zig
parent3ac804628f26ad889701e746d44b21d369cff98d (diff)
downloadzig-d14cd59ef0d9f03114ea6467a8446c17bf33ab9a.tar.gz
zig-d14cd59ef0d9f03114ea6467a8446c17bf33ab9a.zip
stage2 macho: move code signature logic into struct
Diffstat (limited to 'src/link/MachO/CodeSignature.zig')
-rw-r--r--src/link/MachO/CodeSignature.zig59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/link/MachO/CodeSignature.zig b/src/link/MachO/CodeSignature.zig
new file mode 100644
index 0000000000..c03829dace
--- /dev/null
+++ b/src/link/MachO/CodeSignature.zig
@@ -0,0 +1,59 @@
+const CodeSignature = @This();
+
+const std = @import("std");
+const assert = std.debug.assert;
+const log = std.log.scoped(.link);
+const macho = std.macho;
+const mem = std.mem;
+const testing = std.testing;
+const Allocator = mem.Allocator;
+
+// pub const Blob = union(enum) {
+// Signature: struct{
+// inner:
+// }
+// };
+
+alloc: *Allocator,
+inner: macho.SuperBlob = .{
+ .magic = macho.CSMAGIC_EMBEDDED_SIGNATURE,
+ .length = @sizeOf(macho.SuperBlob),
+ .count = 0,
+},
+// blobs: std.ArrayList(Blob),
+
+pub fn init(alloc: *Allocator) CodeSignature {
+ return .{
+ .alloc = alloc,
+ // .indices = std.ArrayList(Blob).init(alloc),
+ };
+}
+
+pub fn calcAdhocSignature(self: *CodeSignature) !void {}
+
+pub fn size(self: CodeSignature) u32 {
+ return self.inner.length;
+}
+
+pub fn write(self: CodeSignature, buffer: []u8) void {
+ assert(buffer.len >= self.inner.length);
+ self.writeHeader(buffer);
+}
+
+pub fn deinit(self: *CodeSignature) void {}
+
+fn writeHeader(self: CodeSignature, buffer: []u8) void {
+ assert(buffer.len >= @sizeOf(macho.SuperBlob));
+ mem.writeIntBig(u32, buffer[0..4], self.inner.magic);
+ mem.writeIntBig(u32, buffer[4..8], self.inner.length);
+ mem.writeIntBig(u32, buffer[8..12], self.inner.count);
+}
+
+test "CodeSignature header" {
+ var code_sig = CodeSignature.init(testing.allocator);
+ defer code_sig.deinit();
+ var buffer: [@sizeOf(macho.SuperBlob)]u8 = undefined;
+ code_sig.writeHeader(buffer[0..]);
+ const expected = &[_]u8{ 0xfa, 0xde, 0x0c, 0xc0, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x0 };
+ testing.expect(mem.eql(u8, expected[0..], buffer[0..]));
+}