blob: 86b1779601549b603dc37354396f4337e6a6cbe9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use base64::Engine;
use deno_core::op2;
use webpki_root_certs;
#[op2]
#[serde]
pub fn op_get_root_certificates() -> Vec<String> {
let certs = webpki_root_certs::TLS_SERVER_ROOT_CERTS
.iter()
.map(|cert| {
let b64 = base64::engine::general_purpose::STANDARD.encode(cert);
let pem_lines = b64
.chars()
.collect::<Vec<char>>()
// Node uses 72 characters per line, so we need to follow node even though
// it's not spec compliant https://datatracker.ietf.org/doc/html/rfc7468#section-2
.chunks(72)
.map(|c| c.iter().collect::<String>())
.collect::<Vec<String>>()
.join("\n");
let pem = format!(
"-----BEGIN CERTIFICATE-----\n{pem_lines}\n-----END CERTIFICATE-----\n",
);
pem
})
.collect::<Vec<String>>();
certs
}
|