Skip to content

Commit

Permalink
Port CICKind to Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Dec 15, 2023
1 parent 9cc190a commit 4ae9083
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 248 deletions.
238 changes: 0 additions & 238 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ crate-type = ["lib", "cdylib"]

[dependencies]
pyo3 = { version="0.20.0", features = ["extension-module"], optional = true }
thiserror = "1.0"
# thiserror = "1.0"

[dev-dependencies]
rstest = "0.18.2"
# [dev-dependencies]
# rstest = "0.18.2"

[features]
c_bindings = []
Expand Down
78 changes: 78 additions & 0 deletions src/rs/cickinds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* SPDX-FileCopyrightText: © 2023 Decompollaborate */
/* SPDX-License-Identifier: MIT */

#[cfg(feature = "python_bindings")]
use pyo3::prelude::*;

#[cfg_attr(feature = "python_bindings", pyclass(module = "ipl3checksum"))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum CICKind {
Cic6101,
Cic6102_7101,
Cic7102,
CicX103, // Both 6103 and 7103
// 6104/7104 does not exist
CicX105, // Both 6105 and 7105
CicX106, // Both 6106 and 7106
}

#[cfg_attr(feature = "python_bindings", pymethods)]
impl CICKind {
pub fn get_seed(&self) -> u32 {
match self {
CICKind::Cic6101 => 0x3F,
CICKind::Cic6102_7101 => 0x3F,
CICKind::Cic7102 => 0x3F,
CICKind::CicX103 => 0x78,
CICKind::CicX105 => 0x91,
CICKind::CicX106 => 0x85,
}
}

pub fn get_magic(&self) -> u32 {
match self {
CICKind::Cic6101 => 0x5D588B65,
CICKind::Cic6102_7101 => 0x5D588B65,
CICKind::Cic7102 => 0x5D588B65,
CICKind::CicX103 => 0x6C078965,
CICKind::CicX105 => 0x5D588B65,
CICKind::CicX106 => 0x6C078965,
}
}

pub fn get_hash_md5(&self) -> &str {
match self {
CICKind::Cic6101 => "900b4a5b68edb71f4c7ed52acd814fc5",
CICKind::Cic6102_7101 => "e24dd796b2fa16511521139d28c8356b",
CICKind::Cic7102 => "955894c2e40a698bf98a67b78a4e28fa",
CICKind::CicX103 => "319038097346e12c26c3c21b56f86f23",
CICKind::CicX105 => "ff22a296e55d34ab0a077dc2ba5f5796",
CICKind::CicX106 => "6460387749ac0bd925aa5430bc7864fe",
}
}

#[cfg(feature = "python_bindings")]
#[staticmethod]
pub fn from_value(value: usize) -> Option<CICKind> {
CICKind::from_value_impl(value)
}

#[cfg(not(feature = "python_bindings"))]
pub fn from_value(value: usize) -> Option<CICKind> {
CICKind::from_value_impl(value)
}
}

impl CICKind {
fn from_value_impl(value: usize) -> Option<CICKind> {
match value {
6101 => Some(CICKind::Cic6101),
6102 | 7101 => Some(CICKind::Cic6102_7101),
7102 => Some(CICKind::Cic7102),
6103 | 7103 => Some(CICKind::CicX103),
6105 | 7105 => Some(CICKind::CicX105),
6106 | 7106 => Some(CICKind::CicX106),
_ => None
}
}
}
Loading

0 comments on commit 4ae9083

Please sign in to comment.