Skip to content

Commit

Permalink
read timestamp configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cstkingkey committed Jan 21, 2022
1 parent 9a6f5e8 commit 90ccddb
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use std::process::{Command, Stdio};
use std::str::FromStr;

use cargo_metadata::Package;
use serde_json::Value;

/// A builder for creating an execution context to sign an installer.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -184,7 +185,11 @@ impl Execution {
let manifest = super::manifest(self.input.as_ref())?;
debug!("target_directory = {:?}", manifest.target_directory);
let package = super::package(&manifest, self.package.as_deref())?;
let metadata = package.metadata.clone();
debug!("metadata = {:?}", metadata);
let product_name = super::product_name(self.product_name.as_ref(), &package);
let timestamp = self.timestamp(&metadata);
debug!("timestamp = {:?}", timestamp);
let description = if let Some(d) = super::description(self.description.clone(), &package) {
trace!("A description was provided either at the command line or in the package's manifest (Cargo.toml).");
format!("{} - {}", product_name, d)
Expand Down Expand Up @@ -212,7 +217,7 @@ impl Execution {
trace!("Using the '{}' URL for the expanded description", h);
signer.arg("/du").arg(h);
}
if let Some(t) = self.timestamp {
if let Some(t) = timestamp {
let server = TimestampServer::from_str(&t)?;
trace!(
"Using the '{}' timestamp server to sign the installer",
Expand Down Expand Up @@ -333,6 +338,22 @@ impl Execution {
Ok(Command::new(SIGNTOOL))
}
}

fn timestamp(&self, metadata: &Value) -> Option<String> {
if let Some(timestamp) = &self.timestamp {
Some(timestamp.to_owned())
} else if let Some(pkg_meta_wix_timestamp) = metadata
.get("wix")
.and_then(|w| w.as_object())
.and_then(|t| t.get("timestamp"))
.and_then(|l| l.as_str())
.map(String::from)
{
Some(pkg_meta_wix_timestamp)
} else {
None
}
}
}

impl Default for Execution {
Expand Down

0 comments on commit 90ccddb

Please sign in to comment.