进行一个夹带私货

This commit is contained in:
shenjack-5600u 2024-01-28 11:43:51 +08:00
parent 26addf3fb1
commit be814a0614
Signed by: shenjack
GPG Key ID: FDF9864E11C7E79F
3 changed files with 7 additions and 13 deletions

View File

@ -106,7 +106,7 @@ mod tests {
#[derive(Deserialize)] #[derive(Deserialize)]
struct TestConfig { struct TestConfig {
pub cluster_port: u32, pub cluster_port: Option<u32>,
pub cluster_id: String, pub cluster_id: String,
pub cluster_secret: String, pub cluster_secret: String,
} }
@ -118,7 +118,7 @@ mod tests {
Config::new( Config::new(
None, None,
"".to_string(), None,
test_conf.cluster_port, test_conf.cluster_port,
test_conf.cluster_id, test_conf.cluster_id,
test_conf.cluster_secret, test_conf.cluster_secret,

View File

@ -2,6 +2,7 @@ use {
crate::fatal, crate::fatal,
log::{error, info, warn}, log::{error, info, warn},
std::{env, fs}, std::{env, fs},
serde::{Serialize, Deserialize}
}; };
const CONFIG_PATH: &str = "config.toml"; const CONFIG_PATH: &str = "config.toml";
@ -97,12 +98,6 @@ impl Config {
}); });
} }
pub fn load() -> Result<Self> {
toml::from_str(&self.load_raw()?).map_err(|err| {
fatal!("Failed to parse config file");
})
}
pub fn join_center_url(&self, path: &str) -> String { pub fn join_center_url(&self, path: &str) -> String {
format!("{}{}", self.center_url, path) format!("{}{}", self.center_url, path)
} }

View File

@ -45,8 +45,8 @@ impl IntoResponse for MeasureRes {
/// ///
/// export default MeasureRoute /// export default MeasureRoute
/// ``` /// ```
///
pub async fn measure(header: HeaderMap, Path(size): Path<u32>) -> MeasureRes { pub async fn measure(header: HeaderMap, Path(size): Path<u32>) -> MeasureRes {
let mut data: Vec<u8> = Vec::new();
match header.get("x-openbmclapi-secret") { match header.get("x-openbmclapi-secret") {
Some(secret) => { Some(secret) => {
if secret != "secret" { if secret != "secret" {
@ -55,10 +55,9 @@ pub async fn measure(header: HeaderMap, Path(size): Path<u32>) -> MeasureRes {
if size > 200 { if size > 200 {
return MeasureRes::BadResquest; return MeasureRes::BadResquest;
} }
let buffer: Vec<u8> = vec![0x00, 0x66, 0xcc, 0xff]; // size -> size * mb
for _ in 0..size { let mut data: Vec<u8> = Vec::with_capacity((size * 1024 * 1024) as usize);
data.extend(&buffer); data.fill(114_u8);
}
return MeasureRes::Data(data); return MeasureRes::Data(data);
} }
None => MeasureRes::Forbidden None => MeasureRes::Forbidden