Skip to content

Commit

Permalink
fix(runtime/tls): remove unnecessary clone calls (denoland#9429)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Feb 7, 2021
1 parent a6723fa commit a601d94
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions runtime/ops/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,17 @@ async fn op_start_tls(
) -> Result<Value, AnyError> {
let args: StartTLSArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
let cert_file = args.cert_file.clone();

let mut domain = args.hostname;
let mut domain = args.hostname.as_str();
if domain.is_empty() {
domain.push_str("localhost");
domain = "localhost";
}
{
super::check_unstable2(&state, "Deno.startTls");
let s = state.borrow();
let permissions = s.borrow::<Permissions>();
permissions.check_net(&(&domain, Some(0)))?;
if let Some(path) = cert_file.clone() {
if let Some(path) = &args.cert_file {
permissions.check_read(Path::new(&path))?;
}
}
Expand All @@ -134,7 +133,7 @@ async fn op_start_tls(
config
.root_store
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
if let Some(path) = cert_file {
if let Some(path) = args.cert_file {
let key_file = File::open(path)?;
let reader = &mut BufReader::new(key_file);
config.root_store.add_pem_file(reader).unwrap();
Expand Down Expand Up @@ -172,18 +171,17 @@ async fn op_connect_tls(
_zero_copy: BufVec,
) -> Result<Value, AnyError> {
let args: ConnectTLSArgs = serde_json::from_value(args)?;
let cert_file = args.cert_file.clone();
{
let s = state.borrow();
let permissions = s.borrow::<Permissions>();
permissions.check_net(&(&args.hostname, Some(args.port)))?;
if let Some(path) = cert_file.clone() {
if let Some(path) = &args.cert_file {
permissions.check_read(Path::new(&path))?;
}
}
let mut domain = args.hostname.clone();
let mut domain = args.hostname.as_str();
if domain.is_empty() {
domain.push_str("localhost");
domain = "localhost";
}

let addr = resolve_addr(&args.hostname, args.port)
Expand All @@ -198,7 +196,7 @@ async fn op_connect_tls(
config
.root_store
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
if let Some(path) = cert_file {
if let Some(path) = args.cert_file {
let key_file = File::open(path)?;
let reader = &mut BufReader::new(key_file);
config.root_store.add_pem_file(reader).unwrap();
Expand Down

0 comments on commit a601d94

Please sign in to comment.