Skip to content

Commit 2a1bb66

Browse files
committed
More rustdoc improvements
1 parent 00e2614 commit 2a1bb66

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,23 @@ Now you can start decrypting some codes:
2222
```rust
2323
use codebreaker::Codebreaker;
2424

25-
let mut encrypted: Vec<(u32, u32)> = vec![
26-
(0x2AFF014C, 0x2411FFFF),
25+
let input: Vec<(u32, u32)> = vec![
26+
(0x2043AFCC, 0x2411FFFF),
27+
(0x2A973DBD, 0x00000000),
2728
(0xB4336FA9, 0x4DFEFB79),
2829
(0x973E0B2A, 0xA7D4AF10),
2930
];
30-
let decrypted: Vec<(u32, u32)> = vec![
31+
let output: Vec<(u32, u32)> = vec![
3132
(0x2043AFCC, 0x2411FFFF),
33+
(0x201F6024, 0x00000000),
3234
(0xBEEFC0DE, 0x00000000),
3335
(0x2096F5B8, 0x000000BE),
3436
];
3537

3638
let mut cb = Codebreaker::new();
37-
for code in encrypted.iter_mut() {
38-
cb.decrypt_code_mut(&mut code.0, &mut code.1);
39+
for (i, code) in input.iter().enumerate() {
40+
assert_eq!(output[i], cb.auto_decrypt_code(code.0, code.1));
3941
}
40-
assert_eq!(decrypted, encrypted);
4142
```
4243

4344
Read the [full documentation](https://docs.rs/codebreaker) for more examples.

src/cb7.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::fmt;
66
use std::mem::size_of;
77
use std::slice;
88

9-
/// Represents the current state of the encryption scheme.
9+
/// A processor for CB v7+ codes.
1010
pub struct Cb7 {
1111
seeds: [[u8; 256]; 5],
1212
key: [u32; 5],
@@ -37,7 +37,8 @@ impl fmt::Debug for Cb7 {
3737
}
3838

3939
impl Cb7 {
40-
/// Allows to encrypt and decrypt codes for CB v7+.
40+
/// Returns a new processor for encrypting and decrypting a list of CB v7+
41+
/// codes.
4142
pub fn new() -> Cb7 {
4243
Cb7 {
4344
seeds: ZERO_SEEDS,
@@ -47,8 +48,9 @@ impl Cb7 {
4748
}
4849
}
4950

50-
/// Generates or changes the encryption key and seeds. Needs to be called
51-
/// for every "beefcode", which comes in two flavors:
51+
/// Generates or changes the encryption key and seeds.
52+
///
53+
/// Needs to be called for every "beefcode", which comes in two flavors:
5254
///
5355
/// ```text
5456
/// BEEFC0DE vvvvvvvv

src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@
88
//! ```
99
//! use codebreaker::Codebreaker;
1010
//!
11-
//! let mut encrypted: Vec<(u32, u32)> = vec![
12-
//! (0x2AFF014C, 0x2411FFFF),
11+
//! let input: Vec<(u32, u32)> = vec![
12+
//! (0x2043AFCC, 0x2411FFFF),
13+
//! (0x2A973DBD, 0x00000000),
1314
//! (0xB4336FA9, 0x4DFEFB79),
1415
//! (0x973E0B2A, 0xA7D4AF10),
1516
//! ];
16-
//! let decrypted: Vec<(u32, u32)> = vec![
17+
//! let output: Vec<(u32, u32)> = vec![
1718
//! (0x2043AFCC, 0x2411FFFF),
19+
//! (0x201F6024, 0x00000000),
1820
//! (0xBEEFC0DE, 0x00000000),
1921
//! (0x2096F5B8, 0x000000BE),
2022
//! ];
2123
//!
2224
//! let mut cb = Codebreaker::new();
23-
//! for code in encrypted.iter_mut() {
24-
//! cb.decrypt_code_mut(&mut code.0, &mut code.1);
25+
//! for (i, code) in input.iter().enumerate() {
26+
//! assert_eq!(output[i], cb.auto_decrypt_code(code.0, code.1));
2527
//! }
26-
//! assert_eq!(decrypted, encrypted);
2728
//! ```
2829
2930
// Enforce rustdoc
@@ -43,7 +44,7 @@ enum Scheme {
4344
V7,
4445
}
4546

46-
/// Represents the current state of the code processor.
47+
/// A processor for CB v1 and v7 codes.
4748
#[derive(Debug)]
4849
pub struct Codebreaker {
4950
scheme: Scheme,
@@ -59,7 +60,8 @@ impl Default for Codebreaker {
5960
}
6061

6162
impl Codebreaker {
62-
/// Allows to encrypt and decrypt all CB v1 and v7 codes.
63+
/// Returns a new processor for encrypting and decrypting a list of CB v1
64+
/// and v7 codes.
6365
pub fn new() -> Codebreaker {
6466
Codebreaker {
6567
scheme: Scheme::RAW,
@@ -68,7 +70,7 @@ impl Codebreaker {
6870
}
6971
}
7072

71-
/// Allows to encrypt and decrypt any CB v7 code published on CMGSCCC.com.
73+
/// Returns a new processor for all CB v7 codes published on CMGSCCC.com.
7274
///
7375
/// Lets you omit `B4336FA9 4DFEFB79` as the first code in the list.
7476
pub fn new_v7() -> Codebreaker {

0 commit comments

Comments
 (0)