1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-29 18:49:07 -05:00
denoland-deno/ext/node/ops/tls.rs
Luca Casonato ab1e391e1d
feat(ext/node): add rootCertificates to node:tls (#25707)
Closes https://github.com/denoland/deno/issues/25604

Signed-off-by: Satya Rohith <me@satyarohith.com>
Co-authored-by: Satya Rohith <me@satyarohith.com>
2024-09-18 21:14:26 +02:00

29 lines
907 B
Rust

// 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
}