Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.key binary=true -diff
12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ regex = "1"
log = "0.4"
urlencoding = "2.1"
self-replace = "1"
zipsign-api = { version = "0.1.0-a.3", default-features = false, optional = true }

[features]
default = ["reqwest/default-tls"]
archive-zip = ["zip"]
compression-zip-bzip2 = ["zip/bzip2"] #
compression-zip-deflate = ["zip/deflate"] #
archive-tar = ["tar"]
compression-flate2 = ["flate2", "either"] #
archive-zip = ["zip", "zipsign-api?/verify-zip"]
compression-zip-bzip2 = ["archive-zip", "zip/bzip2"]
compression-zip-deflate = ["archive-zip", "zip/deflate"]
archive-tar = ["tar", "zipsign-api?/verify-tar"]
compression-flate2 = ["archive-tar", "flate2", "either"]
rustls = ["reqwest/rustls-tls"]
signatures = ["dep:zipsign-api"]

[package.metadata.docs.rs]
# Whether to pass `--all-features` to Cargo (default: false)
Expand Down
1 change: 1 addition & 0 deletions examples/github-private.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
S��Đ*E��ʦ](Խ��V� ���yBփ�AsWVf2�N�w�� �E��<�$^}��п
1 change: 1 addition & 0 deletions examples/github-public.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
փ�AsWVf2�N�w�� �E��<�$^}��п
5 changes: 3 additions & 2 deletions examples/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ extern crate self_update;

fn run() -> Result<(), Box<dyn ::std::error::Error>> {
let releases = self_update::backends::github::ReleaseList::configure()
.repo_owner("jaemk")
.repo_owner("Kijewski")
.repo_name("self_update")
.build()?
.fetch()?;
println!("found releases:");
println!("{:#?}\n", releases);

let status = self_update::backends::github::Update::configure()
.repo_owner("jaemk")
.repo_owner("Kijewski")
.repo_name("self_update")
.bin_name("github")
.show_download_progress(true)
Expand All @@ -30,6 +30,7 @@ fn run() -> Result<(), Box<dyn ::std::error::Error>> {
// or prompting the user for input
//.auth_token(env!("DOWNLOAD_AUTH_TOKEN"))
.current_version(cargo_crate_version!())
.verifying_keys([*include_bytes!("github-public.key")])
.build()?
.update()?;
println!("Update status: `{}`!", status.version());
Expand Down
31 changes: 31 additions & 0 deletions src/backends/gitea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ pub struct UpdateBuilder {
progress_template: String,
progress_chars: String,
auth_token: Option<String>,
#[cfg(feature = "signatures")]
verifying_keys: Vec<[u8; zipsign_api::PUBLIC_KEY_LENGTH]>,
}

impl UpdateBuilder {
Expand Down Expand Up @@ -385,6 +387,24 @@ impl UpdateBuilder {
self
}

/// Specify a slice of ed25519ph verifying keys to validate a download's authenticy
///
/// Unless the feature `"signatures"` is activated, this methods does nothing.
/// If the feature is activated AND at least one key was provided, a download is verifying.
/// At least one key has to match.
pub fn verifying_keys(
&mut self,
keys: impl Into<Vec<[u8; crate::PUBLIC_KEY_LENGTH]>>,
) -> &mut Self {
#[cfg(feature = "signatures")]
{
self.verifying_keys = keys.into();
}
#[cfg(not(feature = "signatures"))]
drop(keys);
self
}

/// Confirm config and create a ready-to-use `Update`
///
/// * Errors:
Expand Down Expand Up @@ -440,6 +460,8 @@ impl UpdateBuilder {
show_output: self.show_output,
no_confirm: self.no_confirm,
auth_token: self.auth_token.clone(),
#[cfg(feature = "signatures")]
verifying_keys: self.verifying_keys.clone(),
}))
}
}
Expand All @@ -462,6 +484,8 @@ pub struct Update {
progress_template: String,
progress_chars: String,
auth_token: Option<String>,
#[cfg(feature = "signatures")]
verifying_keys: Vec<[u8; zipsign_api::PUBLIC_KEY_LENGTH]>,
}
impl Update {
/// Initialize a new `Update` builder
Expand Down Expand Up @@ -566,6 +590,11 @@ impl ReleaseUpdate for Update {
fn api_headers(&self, auth_token: &Option<String>) -> Result<header::HeaderMap> {
api_headers(auth_token)
}

#[cfg(feature = "signatures")]
fn verifying_keys(&self) -> &[[u8; zipsign_api::PUBLIC_KEY_LENGTH]] {
&self.verifying_keys
}
}

impl Default for UpdateBuilder {
Expand All @@ -586,6 +615,8 @@ impl Default for UpdateBuilder {
progress_template: DEFAULT_PROGRESS_TEMPLATE.to_string(),
progress_chars: DEFAULT_PROGRESS_CHARS.to_string(),
auth_token: None,
#[cfg(feature = "signatures")]
verifying_keys: vec![],
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/backends/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ pub struct UpdateBuilder {
progress_chars: String,
auth_token: Option<String>,
custom_url: Option<String>,
#[cfg(feature = "signatures")]
verifying_keys: Vec<[u8; zipsign_api::PUBLIC_KEY_LENGTH]>,
}

impl UpdateBuilder {
Expand Down Expand Up @@ -398,6 +400,24 @@ impl UpdateBuilder {
self
}

/// Specify a slice of ed25519ph verifying keys to validate a download's authenticy
///
/// Unless the feature `"signatures"` is activated, this methods does nothing.
/// If the feature is activated AND at least one key was provided, a download is verifying.
/// At least one key has to match.
pub fn verifying_keys(
&mut self,
keys: impl Into<Vec<[u8; crate::PUBLIC_KEY_LENGTH]>>,
) -> &mut Self {
#[cfg(feature = "signatures")]
{
self.verifying_keys = keys.into();
}
#[cfg(not(feature = "signatures"))]
drop(keys);
self
}

/// Confirm config and create a ready-to-use `Update`
///
/// * Errors:
Expand Down Expand Up @@ -450,6 +470,8 @@ impl UpdateBuilder {
no_confirm: self.no_confirm,
auth_token: self.auth_token.clone(),
custom_url: self.custom_url.clone(),
#[cfg(feature = "signatures")]
verifying_keys: self.verifying_keys.clone(),
}))
}
}
Expand All @@ -473,6 +495,8 @@ pub struct Update {
progress_chars: String,
auth_token: Option<String>,
custom_url: Option<String>,
#[cfg(feature = "signatures")]
verifying_keys: Vec<[u8; zipsign_api::PUBLIC_KEY_LENGTH]>,
}
impl Update {
/// Initialize a new `Update` builder
Expand Down Expand Up @@ -590,6 +614,11 @@ impl ReleaseUpdate for Update {
fn api_headers(&self, auth_token: &Option<String>) -> Result<HeaderMap> {
api_headers(auth_token)
}

#[cfg(feature = "signatures")]
fn verifying_keys(&self) -> &[[u8; zipsign_api::PUBLIC_KEY_LENGTH]] {
&self.verifying_keys
}
}

impl Default for UpdateBuilder {
Expand All @@ -611,6 +640,8 @@ impl Default for UpdateBuilder {
progress_chars: DEFAULT_PROGRESS_CHARS.to_string(),
auth_token: None,
custom_url: None,
#[cfg(feature = "signatures")]
verifying_keys: vec![],
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/backends/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ pub struct UpdateBuilder {
progress_template: String,
progress_chars: String,
auth_token: Option<String>,
#[cfg(feature = "signatures")]
verifying_keys: Vec<[u8; zipsign_api::PUBLIC_KEY_LENGTH]>,
}

impl UpdateBuilder {
Expand Down Expand Up @@ -382,6 +384,24 @@ impl UpdateBuilder {
self
}

/// Specify a slice of ed25519ph verifying keys to validate a download's authenticy
///
/// Unless the feature `"signatures"` is activated, this methods does nothing.
/// If the feature is activated AND at least one key was provided, a download is verifying.
/// At least one key has to match.
pub fn verifying_keys(
&mut self,
keys: impl Into<Vec<[u8; crate::PUBLIC_KEY_LENGTH]>>,
) -> &mut Self {
#[cfg(feature = "signatures")]
{
self.verifying_keys = keys.into();
}
#[cfg(not(feature = "signatures"))]
drop(keys);
self
}

/// Confirm config and create a ready-to-use `Update`
///
/// * Errors:
Expand Down Expand Up @@ -433,6 +453,8 @@ impl UpdateBuilder {
show_output: self.show_output,
no_confirm: self.no_confirm,
auth_token: self.auth_token.clone(),
#[cfg(feature = "signatures")]
verifying_keys: self.verifying_keys.clone(),
}))
}
}
Expand All @@ -455,6 +477,8 @@ pub struct Update {
progress_template: String,
progress_chars: String,
auth_token: Option<String>,
#[cfg(feature = "signatures")]
verifying_keys: Vec<[u8; zipsign_api::PUBLIC_KEY_LENGTH]>,
}
impl Update {
/// Initialize a new `Update` builder
Expand Down Expand Up @@ -564,6 +588,11 @@ impl ReleaseUpdate for Update {
fn api_headers(&self, auth_token: &Option<String>) -> Result<header::HeaderMap> {
api_headers(auth_token)
}

#[cfg(feature = "signatures")]
fn verifying_keys(&self) -> &[[u8; zipsign_api::PUBLIC_KEY_LENGTH]] {
&self.verifying_keys
}
}

impl Default for UpdateBuilder {
Expand All @@ -584,6 +613,8 @@ impl Default for UpdateBuilder {
progress_template: DEFAULT_PROGRESS_TEMPLATE.to_string(),
progress_chars: DEFAULT_PROGRESS_CHARS.to_string(),
auth_token: None,
#[cfg(feature = "signatures")]
verifying_keys: vec![],
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/backends/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ pub struct UpdateBuilder {
progress_template: String,
progress_chars: String,
auth_token: Option<String>,
#[cfg(feature = "signatures")]
verifying_keys: Vec<[u8; zipsign_api::PUBLIC_KEY_LENGTH]>,
}

impl Default for UpdateBuilder {
Expand All @@ -174,6 +176,8 @@ impl Default for UpdateBuilder {
progress_template: DEFAULT_PROGRESS_TEMPLATE.to_string(),
progress_chars: DEFAULT_PROGRESS_CHARS.to_string(),
auth_token: None,
#[cfg(feature = "signatures")]
verifying_keys: vec![],
}
}
}
Expand Down Expand Up @@ -318,6 +322,24 @@ impl UpdateBuilder {
self
}

/// Specify a slice of ed25519ph verifying keys to validate a download's authenticy
///
/// Unless the feature `"signatures"` is activated, this methods does nothing.
/// If the feature is activated AND at least one key was provided, a download is verifying.
/// At least one key has to match.
pub fn verifying_keys(
&mut self,
keys: impl Into<Vec<[u8; crate::PUBLIC_KEY_LENGTH]>>,
) -> &mut Self {
#[cfg(feature = "signatures")]
{
self.verifying_keys = keys.into();
}
#[cfg(not(feature = "signatures"))]
drop(keys);
self
}

/// Confirm config and create a ready-to-use `Update`
///
/// * Errors:
Expand Down Expand Up @@ -366,6 +388,8 @@ impl UpdateBuilder {
show_output: self.show_output,
no_confirm: self.no_confirm,
auth_token: self.auth_token.clone(),
#[cfg(feature = "signatures")]
verifying_keys: self.verifying_keys.clone(),
}))
}
}
Expand All @@ -389,6 +413,8 @@ pub struct Update {
progress_template: String,
progress_chars: String,
auth_token: Option<String>,
#[cfg(feature = "signatures")]
verifying_keys: Vec<[u8; zipsign_api::PUBLIC_KEY_LENGTH]>,
}

impl Update {
Expand Down Expand Up @@ -493,6 +519,11 @@ impl ReleaseUpdate for Update {
fn auth_token(&self) -> Option<String> {
self.auth_token.clone()
}

#[cfg(feature = "signatures")]
fn verifying_keys(&self) -> &[[u8; zipsign_api::PUBLIC_KEY_LENGTH]] {
&self.verifying_keys
}
}

/// Obtain list of releases from AWS S3 API, from bucket and region specified,
Expand Down
Loading