| ... | @@ -111,25 +111,29 @@ pub fn rescanWindows(cb: *Bundle, gpa: Allocator) !void { | ... | @@ -111,25 +111,29 @@ pub fn rescanWindows(cb: *Bundle, gpa: Allocator) !void { |
| 111 | cb.bytes.clearRetainingCapacity(); | 111 | cb.bytes.clearRetainingCapacity(); |
| 112 | cb.map.clearRetainingCapacity(); | 112 | cb.map.clearRetainingCapacity(); |
| 113 | | 113 | |
| 114 | const store = try os.windows.crypt32.certOpenSystemStoreW(null, &[4:0]u16{ 'R', 'O', 'O', 'T' }); | 114 | const w = std.os.windows; |
| 115 | defer os.windows.crypt32.certCloseStore(store, 0) catch unreachable; | 115 | const GetLastError = w.kernel32.GetLastError; |
| 116 | | 116 | const root = [4:0]u16{ 'R', 'O', 'O', 'T' }; |
| 117 | var ctx = os.windows.crypt32.CertEnumCertificatesInStore(store, null); | 117 | const store = w.crypt32.CertOpenSystemStoreW(null, &root) orelse switch (GetLastError()) { |
| 118 | while (ctx) |context| : (ctx = os.windows.crypt32.CertEnumCertificatesInStore(store, ctx)) { | 118 | .FILE_NOT_FOUND => return error.FileNotFound, |
| 119 | var start = @intCast(u32, cb.bytes.items.len); | 119 | else => |err| return w.unexpectedError(err), |
| 120 | try cb.bytes.appendSlice(gpa, context.pbCertEncoded[0..context.cbCertEncoded]); | 120 | }; |
| 121 | var parsed = Certificate.parse(.{ | 121 | defer _ = w.crypt32.CertCloseStore(store, 0); |
| | 122 | |
| | 123 | var ctx = w.crypt32.CertEnumCertificatesInStore(store, null); |
| | 124 | while (ctx) |context| : (ctx = w.crypt32.CertEnumCertificatesInStore(store, ctx)) { |
| | 125 | const decoded_start = @intCast(u32, cb.bytes.items.len); |
| | 126 | const encoded_cert = context.pbCertEncoded[0..context.cbCertEncoded]; |
| | 127 | try cb.bytes.appendSlice(gpa, encoded_cert); |
| | 128 | const parsed_cert = try Certificate.parse(.{ |
| 122 | .buffer = cb.bytes.items, | 129 | .buffer = cb.bytes.items, |
| 123 | .index = start, | 130 | .index = decoded_start, |
| 124 | }) catch { | 131 | }); |
| 125 | cb.bytes.items.len = start; | 132 | const gop = try cb.map.getOrPutContext(gpa, parsed_cert.subject_slice, .{ .cb = cb }); |
| 126 | continue; | | |
| 127 | }; | | |
| 128 | const gop = try cb.map.getOrPutContext(gpa, parsed.subject_slice, .{ .cb = cb }); | | |
| 129 | if (gop.found_existing) { | 133 | if (gop.found_existing) { |
| 130 | cb.bytes.items.len = start; | 134 | cb.bytes.items.len = decoded_start; |
| 131 | } else { | 135 | } else { |
| 132 | gop.value_ptr.* = start; | 136 | gop.value_ptr.* = decoded_start; |
| 133 | } | 137 | } |
| 134 | } | 138 | } |
| 135 | cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len); | 139 | cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len); |
| ... | @@ -250,7 +254,6 @@ pub fn parseCert(cb: *Bundle, gpa: Allocator, decoded_start: u32, now_sec: i64) | ... | @@ -250,7 +254,6 @@ pub fn parseCert(cb: *Bundle, gpa: Allocator, decoded_start: u32, now_sec: i64) |
| 250 | const builtin = @import("builtin"); | 254 | const builtin = @import("builtin"); |
| 251 | const std = @import("../../std.zig"); | 255 | const std = @import("../../std.zig"); |
| 252 | const assert = std.debug.assert; | 256 | const assert = std.debug.assert; |
| 253 | const os = std.os; | | |
| 254 | const fs = std.fs; | 257 | const fs = std.fs; |
| 255 | const mem = std.mem; | 258 | const mem = std.mem; |
| 256 | const crypto = std.crypto; | 259 | const crypto = std.crypto; |