authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-20 00:47:04-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-02 16:57:15-07:00
log504070e8fc50de0c354f6322115e08fe99503578
tree12522b09e95bb923f00e60b489246a0e8cd659fd
parentbbc074252cde0f45576b3910bec5a0f9e867c7f2

std.crypto.CertificateBundle: ignore duplicate certificates


1 files changed, 8 insertions(+), 2 deletions(-)

lib/std/crypto/CertificateBundle.zig+8-2
......@@ -2,7 +2,8 @@
22//! these are "Certificate Authorities" used to validate SSL certificates.
33//! This data structure stores certificates in DER-encoded form, all of them
44//! concatenated together in the `bytes` array. The `map` field contains an
5//! index from the DER-encoded subject name to the index within `bytes`.
5//! index from the DER-encoded subject name to the index of the containing
6//! certificate within `bytes`.
67
78map: std.HashMapUnmanaged(Key, u32, MapContext, std.hash_map.default_max_load_percentage) = .{},
89bytes: std.ArrayListUnmanaged(u8) = .{},
......@@ -105,7 +106,12 @@ pub fn addCertsFromFile(
105106 const dest_buf = cb.bytes.allocatedSlice()[decoded_start..];
106107 cb.bytes.items.len += try base64.decode(dest_buf, encoded_cert);
107108 const k = try key(cb, decoded_start);
108 try cb.map.putContext(gpa, k, decoded_start, .{ .cb = cb });
109 const gop = try cb.map.getOrPutContext(gpa, k, .{ .cb = cb });
110 if (gop.found_existing) {
111 cb.bytes.items.len = decoded_start;
112 } else {
113 gop.value_ptr.* = decoded_start;
114 }
109115 }
110116}
111117