Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ jobs:
run:
name: Run
runs-on: ubuntu-latest
strategy:
matrix:
features: [--all-features, --no-default-features]
steps:
- name: Install Rust stable
uses: actions-rs/toolchain@v1
Expand All @@ -22,16 +25,16 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --workspace
args: --workspace ${{ matrix.features }}

- name: Lint
uses: actions-rs/cargo@v1
with:
command: clippy
args: --workspace -- -D warnings
args: --workspace ${{ matrix.features }} -- -D warnings

- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace
args: --workspace ${{ matrix.features }}
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ repository = "https://github.com/mlafeldt/codebreaker-rs"
documentation = "https://docs.rs/codebreaker/"
homepage = "https://crates.io/crates/codebreaker"
keywords = ["codebreaker", "ps2", "gamehacking", "homebrew"]
categories = ["algorithms", "cryptography"]
categories = ["algorithms", "cryptography", "no-std"]
edition = "2018"

[lib]
name = "codebreaker"

[dependencies]
num-bigint = "^0.2.4"
num-bigint = "0.3"

[features]
default = ["std"]
std = ["num-bigint/std"]
1 change: 1 addition & 0 deletions src/cb1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const SEEDS: [[u32; 16]; 3] = [
mod tests {
use super::*;
use crate::code;
use crate::std_alloc::Vec;

struct Test {
decrypted: &'static str,
Expand Down
8 changes: 5 additions & 3 deletions src/cb7.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! Encrypt and decrypt cheat codes for CodeBreaker PS2 v7+.

use crate::rc4::Rc4;
use crate::std_alloc::Vec;

use std::fmt;
use std::mem::size_of;
use std::slice;
use core::fmt;
use core::mem::size_of;
use core::slice;

/// A processor for CB v7+ codes.
#[derive(Clone, Copy)]
Expand Down Expand Up @@ -466,6 +467,7 @@ const SEEDS: [[u8; 256]; 5] = [
mod tests {
use super::*;
use crate::code;
use crate::std_alloc::Vec;

fn mul_tests() -> Vec<(u32, u32, u32)> {
vec![
Expand Down
31 changes: 29 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@
#![deny(clippy::all, clippy::nursery)]
#![deny(nonstandard_style, rust_2018_idioms)]
#![deny(missing_docs, missing_debug_implementations)]
#![no_std]

#[cfg(feature = "std")]
#[macro_use]
extern crate std;

#[cfg(feature = "std")]
mod std_alloc {
#[cfg(test)]
pub use std::string::String;
pub use std::vec::Vec;
}

#[cfg(not(feature = "std"))]
#[allow(unused_imports)]
#[macro_use]
extern crate alloc;

#[cfg(not(feature = "std"))]
mod std_alloc {
#[cfg(test)]
pub use alloc::string::String;
pub use alloc::vec::Vec;
}

pub mod cb1;
pub mod cb7;
Expand Down Expand Up @@ -286,6 +310,7 @@ fn num_code_lines(addr: u32) -> usize {
#[cfg(test)]
mod tests {
use super::*;
use crate::std_alloc::Vec;

struct Test {
cb: Codebreaker,
Expand Down Expand Up @@ -491,15 +516,17 @@ mod tests {

#[cfg(test)]
mod code {
pub(crate) fn parse(line: &str) -> (u32, u32) {
use crate::std_alloc::{String, Vec};

pub fn parse(line: &str) -> (u32, u32) {
let code: Vec<u32> = line
.splitn(2, ' ')
.map(|v| u32::from_str_radix(v, 16).unwrap())
.collect();
(code[0], code[1])
}

pub(crate) fn format(code: (u32, u32)) -> String {
pub fn format(code: (u32, u32)) -> String {
format!("{:08X} {:08X}", code.0, code.1)
}
}
1 change: 1 addition & 0 deletions src/rc4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl Rc4 {
#[cfg(test)]
mod tests {
use super::*;
use crate::std_alloc::Vec;

struct Test {
key: &'static str,
Expand Down