Skip to content

Commit

Permalink
feat: implement xxhash support
Browse files Browse the repository at this point in the history
  • Loading branch information
krypt0nn committed Jan 20, 2024
1 parent c992944 commit 88a1b84
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ mlua = { version = "0.9.4", features = ["luajit", "vendored", "serialize"] }

md-5 = { version = "0.10.6", features = ["asm"] }
sha1 = { version = "0.10.6", features = ["asm"] }
xxhash-rust = { version = "0.8.8", features = ["xxh32", "xxh64", "xxh3"] }
crc32fast = "1.3.2"
2 changes: 1 addition & 1 deletion repository/integrations/V1_SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ type IntegrityInfo = {
### HashType

```ts
type HashType = 'md5' | 'sha1' | 'crc32' | 'xxhash32' | 'xxhash64';
type HashType = 'md5' | 'sha1' | 'crc32' | 'xxhash32' | 'xxhash64' | 'xxhash3/64' | 'xxhash3/128';
```

Launcher will try to use `v1_integrity_hash` if given hash doesn't belong to the `HashType` type
Expand Down
31 changes: 21 additions & 10 deletions src/games/integrations/standards/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ pub enum HashType {
Md5,
Sha1,
Crc32,

// Older generation xxhash-es
Xxhash32,
Xxhash64,

// New generation xxhash-es
Xxhash3_64,
Xxhash3_128,

Custom(String)
}

Expand All @@ -53,11 +60,13 @@ impl HashType {
match standard {
IntegrationStandard::V1 => {
match value.as_ref() {
"md5" => Ok(Self::Md5),
"sha1" => Ok(Self::Sha1),
"crc32" => Ok(Self::Crc32),
"xxhash32" => Ok(Self::Xxhash32),
"xxhash64" => Ok(Self::Xxhash64),
"md5" => Ok(Self::Md5),
"sha1" => Ok(Self::Sha1),
"crc32" => Ok(Self::Crc32),
"xxhash32" => Ok(Self::Xxhash32),
"xxhash64" => Ok(Self::Xxhash64),
"xxhash3/64" => Ok(Self::Xxhash3_64),
"xxhash3/128" => Ok(Self::Xxhash3_128),

name => Ok(Self::Custom(name.to_string()))
}
Expand All @@ -69,11 +78,13 @@ impl HashType {
match standard {
IntegrationStandard::V1 => {
match self {
Self::Md5 => "md5",
Self::Sha1 => "sha1",
Self::Crc32 => "crc32",
Self::Xxhash32 => "xxhash32",
Self::Xxhash64 => "xxhash64",
Self::Md5 => "md5",
Self::Sha1 => "sha1",
Self::Crc32 => "crc32",
Self::Xxhash32 => "xxhash32",
Self::Xxhash64 => "xxhash64",
Self::Xxhash3_64 => "xxhash3/64",
Self::Xxhash3_128 => "xxhash3/128",

Self::Custom(name) => name
}
Expand Down
5 changes: 5 additions & 0 deletions src/ui/components/tasks_queue/verify_integrity_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ impl QueuedTask for VerifyIntegrityQueuedTask {
hasher.finalize().to_string()
}

HashType::Xxhash32 => format!("{:x}", xxhash_rust::xxh32::xxh32(&data, 0)),
HashType::Xxhash64 => format!("{:x}", xxhash_rust::xxh64::xxh64(&data, 0)),
HashType::Xxhash3_64 => format!("{:x}", xxhash_rust::xxh3::xxh3_64(&data)),
HashType::Xxhash3_128 => format!("{:x}", xxhash_rust::xxh3::xxh3_128(&data)),

HashType::Custom(name) if has_integrity_hash => {
game.driver.integrity_hash(&name, data)?
}
Expand Down

0 comments on commit 88a1b84

Please sign in to comment.