diff options
| author | 2024-12-30 19:33:48 -0600 | |
|---|---|---|
| committer | 2024-12-30 19:33:48 -0600 | |
| commit | e62d05698ba6af03906fb79acee1da488e64871a (patch) | |
| tree | 000c2c5c1a682694d4dfadb809937a4edd14915b /src/launcher/version.rs | |
| parent | when the (diff) | |
some stuff has changed
Diffstat (limited to 'src/launcher/version.rs')
| -rw-r--r-- | src/launcher/version.rs | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/src/launcher/version.rs b/src/launcher/version.rs index 378e008..08c3bb5 100644 --- a/src/launcher/version.rs +++ b/src/launcher/version.rs @@ -3,13 +3,10 @@ use std::borrow::Cow; use std::collections::HashSet; use std::fmt::Display; use std::path::{Path, PathBuf}; -use chrono::{DateTime, Utc}; -use crypto::digest::Digest; -use crypto::sha1::Sha1; -use serde::{Serialize, Deserialize}; use log::{debug, info, warn}; - +use sha1_smol::Digest; +use crate::util; use crate::version::{*, manifest::*}; use super::constants::*; @@ -51,7 +48,7 @@ impl RemoteVersionList { let ver_text = reqwest::get(ver.url.as_str()).await?.error_for_status()?.text().await?; // make sure it's valid - ver.sha1.verify(ver_text.as_str()) + util::verify_sha1(ver.sha1, ver_text.as_str()) .map_err::<Box<dyn Error>, _>(|e| format!("downloaded version {} has wrong hash! (expect {}, got {})", ver.id.as_str(), &ver.sha1, e).as_str().into())?; // make sure it's well-formed @@ -70,7 +67,7 @@ struct LocalVersionList { #[derive(Debug)] enum LocalVersionError { - Sha1Mismatch { exp: Sha1Digest, got: Sha1Digest }, + Sha1Mismatch { exp: Digest, got: Digest }, VersionMismatch { fname: String, json: String }, Unknown(Box<dyn Error>) } @@ -78,10 +75,10 @@ enum LocalVersionError { impl Display for LocalVersionError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Sha1Mismatch { exp, got } => { + LocalVersionError::Sha1Mismatch { exp, got } => { write!(f, "sha1 mismatch (exp {exp}, got {got})") }, - VersionMismatch { fname, json } => { + LocalVersionError::VersionMismatch { fname, json } => { write!(f, "version ID mismatch (filename {fname}, json {json})") }, LocalVersionError::Unknown(err) => { @@ -94,12 +91,12 @@ impl Display for LocalVersionError { impl Error for LocalVersionError {} impl LocalVersionList { - async fn load_version(path: &Path, sha1: Option<&Sha1Digest>) -> Result<CompleteVersion, LocalVersionError> { + async fn load_version(path: &Path, sha1: Option<Digest>) -> Result<CompleteVersion, LocalVersionError> { // grumble grumble I don't like reading in the whole file at once let ver = tokio::fs::read_to_string(path).await.map_err(|e| LocalVersionError::Unknown(Box::new(e)))?; if let Some(digest_exp) = sha1 { - digest_exp.verify(ver.as_str()) - .map_err(|got| Sha1Mismatch { exp: digest_exp.to_owned(), got })?; + util::verify_sha1(digest_exp, ver.as_str()) + .map_err(|got| LocalVersionError::Sha1Mismatch { exp: digest_exp.to_owned(), got })?; } let ver: CompleteVersion = serde_json::from_str(ver.as_str()).map_err(|e| LocalVersionError::Unknown(Box::new(e)))?; @@ -112,7 +109,7 @@ impl LocalVersionList { if fname_id == ver.id.as_str() { Ok(ver) } else { - Err(VersionMismatch { fname: fname_id.to_owned(), json: ver.id }) + Err(LocalVersionError::VersionMismatch { fname: fname_id.to_owned(), json: ver.id }) } } @@ -199,10 +196,6 @@ pub enum VersionResolveError { Unknown(Box<dyn Error>) } -use crate::util::{Sha1Digest, SHA1_DIGEST_BYTES}; -use crate::launcher::version::LocalVersionError::{Sha1Mismatch, VersionMismatch}; -use crate::launcher::version::VersionResolveError::MissingVersion; - impl VersionList { pub async fn online(home: &Path) -> Result<VersionList, Box<dyn Error>> { let remote = RemoteVersionList::new().await?; @@ -247,7 +240,7 @@ impl VersionList { let mut ver_path = self.home.join(id); ver_path.push(format!("{id}.json")); - match LocalVersionList::load_version(ver_path.as_path(), Some(&ver.sha1)).await { + match LocalVersionList::load_version(ver_path.as_path(), Some(ver.sha1)).await { Ok(v) => return Ok(v), Err(e) => { info!("redownloading {id}, since the local copy could not be loaded: {e}"); @@ -275,7 +268,7 @@ impl VersionList { Cow::Owned(self.load_remote_version(v).await.map_err(|e| VersionResolveError::Unknown(e))?), VersionResult::None => { warn!("Cannot resolve version {}, it inherits an unknown version {inherit}", ver.id); - return Err(MissingVersion(inherit)); + return Err(VersionResolveError::MissingVersion(inherit)); } }; |
