Skip to content

Commit

Permalink
write some bindings for cickind methods
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Dec 16, 2023
1 parent ae6eb6f commit 826a3c9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
19 changes: 19 additions & 0 deletions bindings/c/include/ipl3checksum/cickinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#define IPL3CHECKSUM_CICKINDS_H
#pragma once

#include <stddef.h>
#include <stdint.h>

#include "error.h"

#ifdef __cplusplus
extern "C"
{
Expand All @@ -18,6 +23,20 @@ typedef enum Ipl3Checksum_CICKind {
Ipl3Checksum_CICKind_CIC_X106, // Both 6106 and 7106
} Ipl3Checksum_CICKind;

uint32_t ipl3checksum_cickind_get_seed(Ipl3Checksum_CICKind self);

uint32_t ipl3checksum_cickind_get_magic(Ipl3Checksum_CICKind self);

// const char *ipl3checksum_cickind_get_hash_md5(Ipl3Checksum_CICKind self);

// Ipl3Checksum_Error ipl3checksum_cickind_from_hash_md5(Ipl3Checksum_CICKind *kind_dst, const char *hash_str);

// const char *ipl3checksum_cickind_get_name(Ipl3Checksum_CICKind self);

// Ipl3Checksum_Error ipl3checksum_cickind_from_name(Ipl3Checksum_CICKind *kind_dst, const char *name);

Ipl3Checksum_Error ipl3checksum_cickind_from_value(Ipl3Checksum_CICKind *kind_dst, size_t value);

#ifdef __cplusplus
}
#endif
Expand Down
71 changes: 71 additions & 0 deletions src/rs/cickinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,74 @@ mod python_bindings {
}
}
}

#[cfg(feature = "c_bindings")]
mod c_bindings {
use crate::{CICKind, Ipl3ChecksumError};

#[no_mangle]
pub extern "C" fn ipl3checksum_cickind_get_seed(
kind: CICKind
) -> u32 {
kind.get_seed()
}

#[no_mangle]
pub extern "C" fn ipl3checksum_cickind_get_magic(
kind: CICKind
) -> u32 {
kind.get_magic()
}

/*
#[no_mangle]
pub extern "C" fn ipl3checksum_cickind_get_hash_md5(
kind: CICKind
) -> *const core::ffi::c_char {
std::ffi::CString::new(kind.get_hash_md5()).unwrap().as_ptr()
}
*/

/*
#[no_mangle]
pub extern "C" fn ipl3checksum_cickind_from_hash_md5(
kind: CICKind
) -> {
}
*/

/*
#[no_mangle]
pub extern "C" fn ipl3checksum_cickind_get_name(
kind: CICKind
) -> {
}
*/

/*
#[no_mangle]
pub extern "C" fn ipl3checksum_cickind_from_name(
kind: CICKind
) -> {
}
*/

#[no_mangle]
pub extern "C" fn ipl3checksum_cickind_from_value(
kind_dst: *mut CICKind,
value: usize
) -> Ipl3ChecksumError {
if kind_dst.is_null() {
return Ipl3ChecksumError::NullPointer;
}

let kind = match CICKind::from_value(value) {
Some(k) => k,
None => return Ipl3ChecksumError::UnableToDetectCIC,
};

unsafe { *kind_dst = kind };

Ipl3ChecksumError::Okay
}
}
2 changes: 1 addition & 1 deletion src/rs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub enum Ipl3ChecksumError {
buffer_len: usize,
expected_len: usize,
},
#[error("Unable to detect the CIC variant because the computed hash did not match any of the known variants")]
#[error("Unable to detect CIC variant")]
UnableToDetectCIC,
}

Expand Down

0 comments on commit 826a3c9

Please sign in to comment.