mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
30 lines
907 B
Rust
30 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
|
||
|
}
|