Skip to content

Commit

Permalink
Include sha256.
Browse files Browse the repository at this point in the history
  • Loading branch information
vikpe committed Jun 28, 2024
1 parent eee0ddc commit 20e40aa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ categories = ["parsing"]
keywords = ["bsp", "parser", "quake", "quakeworld"]
repository = "https://github.com/vikpe/bspparser"
authors = ["Viktor Persson"]
version = "0.2.0"
version = "0.3.0"
edition = "2021"
license = "MIT"
include = [
Expand All @@ -19,6 +19,7 @@ anyhow = "1.0.86"
bspparser = "0.2.0"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.118"
sha256 = { version = "1.5.0", features = [], default-features = false }

[dev-dependencies]
pretty_assertions = "1.4.0"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let info: BspInfo = quake_bspinfo::parse(&data)?;
struct BspInfo {
message: String,
size: u32,
sha256: String,
entity_count: EntityCount,
intermissions: Vec<Intermission>,
race_routes: Vec<RaceRoute>,
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use std::path::Path;

use anyhow::Result;
use serde::{Deserialize, Serialize};
use sha256::digest;

#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct BspInfo {
pub message: String,
pub size: u32,
pub sha256: String,
pub entity_count: EntityCount,
pub intermissions: Vec<Intermission>,
pub race_routes: Vec<RaceRoute>,
Expand All @@ -23,6 +25,7 @@ impl BspInfo {

let mut info = BspInfo {
size: bytes.len() as u32,
sha256: digest(bytes),
..Default::default()
};
let mut e: EntityCount = Default::default();
Expand Down Expand Up @@ -264,6 +267,7 @@ mod tests {
let mut expect = BspInfo {
message: "DMM4 Arena\\nBy Povo-Hat (http://povo-hat.besmella-quake.com)\\n".to_string(),
size: 130920,
sha256: "e4894f7d54e6293807c7dca201e2a93477362f6447224ca3baf4b3d26b71d35d".to_string(),
..Default::default()
};
expect.entity_count.spawns.start = 1;
Expand All @@ -280,6 +284,8 @@ mod tests {
let expect = BspInfo {
message: "The Abandoned Base".to_string(),
size: 1361880,
sha256: "cdad534cfbb7a584eda3a0c982b99174003a873aa5c44e1e7f75051fd48dd757"
.to_string(),
entity_count: EntityCount {
armors: Armors {
green_armor: 0,
Expand Down Expand Up @@ -359,6 +365,8 @@ mod tests {
let mut expect = BspInfo {
message: "anubis in hurry by anni (Apr 2021)".to_string(),
size: 1846812,
sha256: "5db3a0590f17b114ae6507b6e6b99437ad693ca4bc6547c8960eec6fb10dc94c"
.to_string(),
..Default::default()
};
expect.entity_count.spawns.start = 1;
Expand Down

0 comments on commit 20e40aa

Please sign in to comment.