Skip to content

Commit 6ac7283

Browse files
committed
Support no_std
1 parent 19e167d commit 6ac7283

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ repository = "https://github.com/mlafeldt/codebreaker-rs"
99
documentation = "https://docs.rs/codebreaker/"
1010
homepage = "https://crates.io/crates/codebreaker"
1111
keywords = ["codebreaker", "ps2", "gamehacking", "homebrew"]
12-
categories = ["algorithms", "cryptography"]
12+
categories = ["algorithms", "cryptography", "no-std"]
1313
edition = "2018"
1414

1515
[lib]
1616
name = "codebreaker"
1717

1818
[dependencies]
19-
num-bigint = "^0.2.4"
19+
num-bigint = { git = "https://github.com/rust-num/num-bigint", default-features = false }
20+
21+
[features]
22+
default = ["std"]
23+
std = ["num-bigint/std"]

src/cb1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const SEEDS: [[u32; 16]; 3] = [
9898
mod tests {
9999
use super::*;
100100
use crate::code;
101+
use crate::std_alloc::Vec;
101102

102103
struct Test {
103104
decrypted: &'static str,

src/cb7.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//! Encrypt and decrypt cheat codes for CodeBreaker PS2 v7+.
22
33
use crate::rc4::Rc4;
4+
use crate::std_alloc::Vec;
45

5-
use std::fmt;
6-
use std::mem::size_of;
7-
use std::slice;
6+
use core::fmt;
7+
use core::mem::size_of;
8+
use core::slice;
89

910
/// A processor for CB v7+ codes.
1011
#[derive(Clone, Copy)]
@@ -478,6 +479,7 @@ const SEEDS: [[u8; 256]; 5] = [
478479
mod tests {
479480
use super::*;
480481
use crate::code;
482+
use crate::std_alloc::Vec;
481483

482484
fn mul_tests() -> Vec<(u32, u32, u32)> {
483485
vec![

src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@
3030
#![deny(clippy::all, clippy::nursery)]
3131
#![deny(nonstandard_style, rust_2018_idioms)]
3232
#![deny(missing_docs, missing_debug_implementations)]
33+
#![no_std]
34+
35+
#[cfg(feature = "std")]
36+
#[macro_use]
37+
extern crate std;
38+
39+
#[cfg(feature = "std")]
40+
mod std_alloc {
41+
#[cfg(test)]
42+
pub(crate) use std::string::String;
43+
pub(crate) use std::vec::Vec;
44+
}
45+
46+
#[cfg(not(feature = "std"))]
47+
#[allow(unused_imports)]
48+
#[macro_use]
49+
extern crate alloc;
50+
51+
#[cfg(not(feature = "std"))]
52+
mod std_alloc {
53+
#[cfg(test)]
54+
pub(crate) use alloc::string::String;
55+
pub(crate) use alloc::vec::Vec;
56+
}
3357

3458
pub mod cb1;
3559
pub mod cb7;
@@ -286,6 +310,7 @@ fn num_code_lines(addr: u32) -> usize {
286310
#[cfg(test)]
287311
mod tests {
288312
use super::*;
313+
use crate::std_alloc::Vec;
289314

290315
struct Test {
291316
cb: Codebreaker,
@@ -491,6 +516,8 @@ mod tests {
491516

492517
#[cfg(test)]
493518
mod code {
519+
use crate::std_alloc::{String, Vec};
520+
494521
pub(crate) fn parse(line: &str) -> (u32, u32) {
495522
let code: Vec<u32> = line
496523
.splitn(2, ' ')

src/rc4.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl Rc4 {
3838
#[cfg(test)]
3939
mod tests {
4040
use super::*;
41+
use crate::std_alloc::Vec;
4142

4243
struct Test {
4344
key: &'static str,

0 commit comments

Comments
 (0)