summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/launcher.rs5
-rw-r--r--src/launcher/instance.rs9
-rw-r--r--src/launcher/profile.rs8
-rw-r--r--src/launcher/version.rs31
-rw-r--r--src/main.rs3
-rw-r--r--src/util.rs131
-rw-r--r--src/version.rs5
-rw-r--r--src/version/manifest.rs4
8 files changed, 107 insertions, 89 deletions
diff --git a/src/launcher.rs b/src/launcher.rs
index d99a294..70c313c 100644
--- a/src/launcher.rs
+++ b/src/launcher.rs
@@ -1,11 +1,14 @@
mod constants;
mod version;
+mod instance;
+mod profile;
use std::error::Error;
-pub use version::VersionList;
+use version::VersionList;
pub struct Launcher {
pub versions: VersionList
+
}
impl Launcher {
diff --git a/src/launcher/instance.rs b/src/launcher/instance.rs
new file mode 100644
index 0000000..3e62990
--- /dev/null
+++ b/src/launcher/instance.rs
@@ -0,0 +1,9 @@
+use std::path::PathBuf;
+use serde::Deserialize;
+use uuid::Uuid;
+
+#[derive(Deserialize, Debug, Clone)]
+pub struct Instance {
+ pub uuid: Uuid,
+ pub path: PathBuf
+}
diff --git a/src/launcher/profile.rs b/src/launcher/profile.rs
new file mode 100644
index 0000000..835d912
--- /dev/null
+++ b/src/launcher/profile.rs
@@ -0,0 +1,8 @@
+use super::instance::Instance;
+
+struct Profile<'l> {
+ name: String,
+ version_id: String,
+ java_runtime: Option<String>,
+ instance: &'l Instance
+} \ No newline at end of file
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));
}
};
diff --git a/src/main.rs b/src/main.rs
deleted file mode 100644
index 2a778e4..0000000
--- a/src/main.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-fn main() {
-
-}
diff --git a/src/util.rs b/src/util.rs
index 428990c..c6739b6 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,68 +1,77 @@
-use std::fmt::{Debug, Display, Formatter, Pointer};
-use std::ops::Deref;
-use crypto::digest::Digest;
-use crypto::sha1::Sha1;
-use serde::{Deserialize, Deserializer};
-use serde::de::{Error, Visitor};
-use hex::{FromHex, ToHex};
+// use std::fmt::{Debug, Display, Formatter};
+// use serde::{Deserialize, Deserializer};
+// use serde::de::{Error, Visitor};
+// use hex::{FromHex, FromHexError, ToHex};
+// use sha1_smol::Sha1;
+//
+// // sha1 digests are 20 bytes long
+// pub use sha1_smol::DIGEST_LENGTH;
+// pub type Sha1DigestBytes = [u8; DIGEST_LENGTH];
+//
+// #[derive(PartialEq, Eq, PartialOrd, Ord, Clone)]
+// pub struct Sha1Digest(pub Sha1DigestBytes);
+//
+// impl Debug for Sha1Digest {
+// fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+// write!(f, "Sha1Digest {{{}}}", self.0.encode_hex::<String>())
+// }
+// }
+//
+// impl Display for Sha1Digest {
+// fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+// f.write_str(&self.0.encode_hex::<String>())
+// }
+// }
+//
+// impl Sha1Digest {
+// pub fn from_hex(s: &str) -> Result<Sha1Digest, FromHexError> {
+//
+// }
+//
-// sha1 digests are 20 bytes long
-pub const SHA1_DIGEST_BYTES: usize = 20;
-pub type Sha1DigestBytes = [u8; SHA1_DIGEST_BYTES];
+use sha1_smol::{Digest, Sha1};
-#[derive(PartialEq, Eq, PartialOrd, Ord, Clone)]
-pub struct Sha1Digest(pub Sha1DigestBytes);
+pub fn verify_sha1(expect: Digest, s: &str) -> Result<(), Digest> {
+ let dig = Sha1::from(s).digest();
-impl Debug for Sha1Digest {
- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- write!(f, "Sha1Digest {{{}}}", self.0.encode_hex::<String>())
+ if dig == expect {
+ return Ok(());
}
-}
-
-impl Display for Sha1Digest {
- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- f.write_str(&self.0.encode_hex::<String>())
- }
-}
-
-impl Sha1Digest {
- pub fn verify(&self, s: &str) -> Result<(), Sha1Digest> {
- let mut st = Sha1::new();
- let mut dig = [0u8; SHA1_DIGEST_BYTES];
-
- st.input_str(s);
- st.result(&mut dig);
-
- if self.0 == dig {
- return Ok(());
- }
-
- Err(Sha1Digest(dig))
- }
-}
-
-struct Sha1DigestVisitor;
-
-impl <'a> Visitor<'a> for Sha1DigestVisitor {
- type Value = Sha1Digest;
- fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
- write!(formatter, "a valid SHA-1 digest (40-character hex string)")
- }
-
- fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
- where
- E: Error,
- {
- Sha1DigestBytes::from_hex(v).map_err(|e| E::custom(e)).map(Sha1Digest)
- }
+ Err(dig)
}
-impl<'a> Deserialize<'a> for Sha1Digest {
- fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
- where
- D: Deserializer<'a>,
- {
- deserializer.deserialize_any(Sha1DigestVisitor)
- }
-} \ No newline at end of file
+//
+// pub fn as_hex(&self) -> String {
+// // allocate the string with capacity first so we only do one heap alloc
+// let mut s: String = String::with_capacity(2 * self.0.len());
+// self.0.iter().for_each(|b| s.push_str(&format!("{:02x}", b)));
+// s
+// }
+// }
+//
+// struct Sha1DigestVisitor;
+//
+// impl <'a> Visitor<'a> for Sha1DigestVisitor {
+// type Value = Sha1Digest;
+//
+// fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
+// write!(formatter, "a valid SHA-1 digest (40-character hex string)")
+// }
+//
+// fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
+// where
+// E: Error,
+// {
+// Sha1DigestBytes::from_hex(v).map_err(|e| E::custom(e)).map(Sha1Digest)
+// }
+// }
+//
+// impl<'a> Deserialize<'a> for Sha1Digest {
+// fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+// where
+// D: Deserializer<'a>,
+// {
+// deserializer.deserialize_any(Sha1DigestVisitor)
+// }
+// } \ No newline at end of file
diff --git a/src/version.rs b/src/version.rs
index 190dd72..188b88a 100644
--- a/src/version.rs
+++ b/src/version.rs
@@ -1,15 +1,14 @@
use core::fmt;
use std::{collections::BTreeMap, convert::Infallible, marker::PhantomData, ops::Deref, str::FromStr};
-use std::ascii::AsciiExt;
use std::collections::HashMap;
use chrono::{DateTime, Utc};
use regex::Regex;
use serde::{de::{self, Visitor}, Deserialize, Deserializer};
use serde::de::SeqAccess;
+use sha1_smol::Digest;
pub mod manifest;
use manifest::*;
-use crate::util::Sha1Digest;
#[derive(Deserialize, Debug, Clone, Copy)]
#[serde(rename_all = "lowercase")]
@@ -169,7 +168,7 @@ pub enum DownloadType {
#[derive(Deserialize, Debug, Clone)]
pub struct DownloadInfo {
- pub sha1: Option<Sha1Digest>,
+ pub sha1: Option<Digest>,
pub size: Option<usize>,
pub total_size: Option<usize>, // available for asset index
pub url: Option<String>, // may not be present for libraries
diff --git a/src/version/manifest.rs b/src/version/manifest.rs
index 437daf6..598cc91 100644
--- a/src/version/manifest.rs
+++ b/src/version/manifest.rs
@@ -2,7 +2,7 @@ use core::fmt;
use chrono::{DateTime, Utc};
use serde::{de::Visitor, Deserialize};
-use crate::util::Sha1Digest;
+use sha1_smol::Digest;
#[derive(Deserialize, Debug)]
pub struct LatestVersions {
@@ -59,7 +59,7 @@ pub struct VersionManifestVersion {
pub url: String,
pub time: DateTime<Utc>,
pub release_time: DateTime<Utc>,
- pub sha1: Sha1Digest,
+ pub sha1: Digest,
pub compliance_level: u32
}