进行一个夹带私货

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)]
struct TestConfig {
pub cluster_port: u32,
pub cluster_port: Option<u32>,
pub cluster_id: String,
pub cluster_secret: String,
}
@ -118,7 +118,7 @@ mod tests {
Config::new(
None,
"".to_string(),
None,
test_conf.cluster_port,
test_conf.cluster_id,
test_conf.cluster_secret,

View File

@ -2,6 +2,7 @@ use {
crate::fatal,
log::{error, info, warn},
std::{env, fs},
serde::{Serialize, Deserialize}
};
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 {
format!("{}{}", self.center_url, path)
}

View File

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