// 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 { 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::>() // 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::()) .collect::>() .join("\n"); let pem = format!( "-----BEGIN CERTIFICATE-----\n{pem_lines}\n-----END CERTIFICATE-----\n", ); pem }) .collect::>(); certs }