cynapse 0.1.0

Real-time, memory-resident binary integrity verification for Rust applications
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# Contributing to Cynapse

Thank you for your interest in contributing to Cynapse! We welcome contributions from the community.

---

## 📋 Table of Contents

- [Code of Conduct]#code-of-conduct
- [Getting Started]#getting-started
- [Development Workflow]#development-workflow
- [Coding Standards]#coding-standards
- [Testing]#testing
- [Documentation]#documentation
- [Submitting Changes]#submitting-changes
- [Release Process]#release-process

---

## Code of Conduct

We are committed to providing a welcoming and inclusive environment. Please:

- Be respectful and considerate
- Welcome newcomers and help them get started
- Focus on constructive feedback
- Assume good intentions

---

## Getting Started

### Prerequisites

- Rust 1.70 or later
- Git
- A GitLab account (for merge requests)

### Setting Up Your Development Environment

```bash
# Clone the repository
git clone https://gitlab.com/TIVisionOSS/crates/cynapse.git
cd cynapse

# Build the project
cargo build

# Run tests
cargo test

# Run tests with all features
cargo test --all-features

# Run clippy
cargo clippy --all-targets --all-features

# Format code
cargo fmt
```

---

## Development Workflow

### 1. Find an Issue

- Check the [issue tracker]https://gitlab.com/TIVisionOSS/crates/cynapse/-/issues
- Look for issues tagged `good-first-issue` or `help-wanted`
- Comment on the issue to let others know you're working on it

### 2. Create a Branch

```bash
# Create a new branch from main
git checkout -b feature/your-feature-name

# Or for bug fixes
git checkout -b fix/issue-number-description
```

### 3. Make Changes

- Write clean, idiomatic Rust code
- Follow the [Rust API Guidelines]https://rust-lang.github.io/api-guidelines/
- Add tests for new functionality
- Update documentation as needed

### 4. Commit Your Changes

```bash
# Stage changes
git add .

# Commit with descriptive message
git commit -m "feat: add new feature X"

# Or for bug fixes
git commit -m "fix: resolve issue #123"
```

**Commit Message Format:**

- `feat: description` — New feature
- `fix: description` — Bug fix
- `docs: description` — Documentation changes
- `test: description` — Test additions or changes
- `refactor: description` — Code refactoring
- `perf: description` — Performance improvements
- `chore: description` — Maintenance tasks

### 5. Push and Create Merge Request

```bash
# Push to your fork
git push origin feature/your-feature-name

# Create a merge request on GitLab
# Include a clear description of changes
# Reference related issues (e.g., "Closes #123")
```

---

## Coding Standards

### Rust Style

- Follow the [Rust Style Guide]https://doc.rust-lang.org/nightly/style-guide/
- Run `cargo fmt` before committing
- Ensure `cargo clippy` passes without warnings

### Code Organization

```
src/
├── lib.rs           # Public API and re-exports
├── core/            # Core functionality
│   ├── mapper.rs    # Memory mapping
│   ├── hasher.rs    # Hashing and Merkle trees
│   ├── monitor.rs   # Monitoring logic
│   └── ...
├── platform/        # Platform-specific code
│   ├── linux.rs
│   ├── windows.rs
│   └── macos.rs
└── utils/           # Utility functions
```

### Unsafe Code

- **Minimize unsafe:** Only use when absolutely necessary
- **Document safety:** Every unsafe block must have a `// SAFETY:` comment explaining why it's safe
- **Isolate unsafe:** Keep unsafe code in small, well-tested functions
- **Test with Miri:** Run `cargo +nightly miri test` to catch undefined behavior

Example:

```rust
// SAFETY: We're reading from our own process memory at a valid address.
// The caller must ensure the address range is valid and readable.
unsafe {
    std::ptr::copy_nonoverlapping(src, dst, size);
}
```

### Error Handling

- Use `Result<T, Error>` for fallible operations
- Provide descriptive error messages
- Use `thiserror` for error types
- Avoid panics in library code (use `Result` instead)

### Documentation

- Add doc comments (`///`) for all public items
- Include examples in doc comments
- Use `#[doc(hidden)]` for implementation details
- Write module-level documentation

Example:

```rust
/// Hash a memory page using the configured algorithm.
///
/// # Arguments
///
/// * `data` - The page contents to hash
/// * `address` - The memory address of the page
///
/// # Returns
///
/// A `HashedPage` containing the hash and metadata.
///
/// # Example
///
/// ```
/// use cynapse::core::hasher::{HashEngine, HashAlgorithm};
///
/// let engine = HashEngine::new(HashAlgorithm::Blake3);
/// let data = vec![0u8; 4096];
/// let page = engine.hash_page(&data, 0x1000).unwrap();
/// ```
pub fn hash_page(&self, data: &[u8], address: usize) -> Result<HashedPage> {
    // Implementation
}
```

---

## Testing

### Test Organization

```
tests/
├── integration/      # Integration tests
│   ├── basic_monitoring.rs
│   └── memory_operations.rs
└── platform/         # Platform-specific tests
    └── platform_tests.rs
```

### Writing Tests

```rust
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_feature_name() {
        // Arrange
        let input = create_test_input();

        // Act
        let result = function_under_test(input);

        // Assert
        assert_eq!(result, expected_output);
    }

    #[test]
    #[should_panic(expected = "error message")]
    fn test_error_condition() {
        // Test error handling
    }
}
```

### Running Tests

```bash
# Run all tests
cargo test

# Run specific test
cargo test test_name

# Run with output
cargo test -- --nocapture

# Run platform-specific tests
cargo test --test platform_tests

# Run with all features
cargo test --all-features

# Run benchmarks
cargo bench
```

### Test Coverage

- Aim for **80%+ code coverage**
- Test edge cases and error conditions
- Test platform-specific code on relevant platforms

---

## Documentation

### Building Documentation

```bash
# Build and open documentation
cargo doc --no-deps --open

# Build with all features
cargo doc --all-features --no-deps --open
```

### Documentation Checklist

- [ ] All public items have doc comments
- [ ] Examples are included and tested
- [ ] Module-level documentation explains purpose
- [ ] Links to related types and functions work
- [ ] README.md is updated if needed

---

## Submitting Changes

### Merge Request Checklist

Before submitting a merge request, ensure:

- [ ] Code follows Rust style guidelines
- [ ] `cargo fmt` has been run
- [ ] `cargo clippy` passes without warnings
- [ ] All tests pass (`cargo test --all-features`)
- [ ] New tests are added for new functionality
- [ ] Documentation is updated
- [ ] Commit messages are clear and descriptive
- [ ] No merge conflicts with `main`

### Merge Request Template

```markdown
## Description

Brief description of changes.

## Related Issues

Closes #123

## Type of Change

- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update

## Testing

Describe how you tested the changes.

## Checklist

- [ ] Tests pass
- [ ] Documentation updated
- [ ] Code formatted
- [ ] Clippy passes
```

### Review Process

1. Submit merge request
2. Automated CI checks run
3. Maintainers review code
4. Address feedback if needed
5. Merge after approval

---

## Platform-Specific Contributions

### Linux

- Test on recent kernel versions (5.x+)
- Consider different distributions
- Test with SELinux/AppArmor if applicable

### Windows

- Test on Windows 10/11
- Consider both x64 and x86
- Test with different Windows Security settings

### macOS

- Test on recent macOS versions (12+)
- Test on both Intel and Apple Silicon

---

## Adding New Features

### Feature Flags

When adding optional functionality:

1. Add feature flag to `Cargo.toml`:

```toml
[features]
new-feature = ["dep:new-dependency"]
```

2. Use `#[cfg(feature = "new-feature")]` for feature-gated code

3. Update documentation to mention the feature

4. Add tests that run with and without the feature

### Breaking Changes

- Avoid breaking changes if possible
- Document breaking changes clearly
- Follow semantic versioning
- Provide migration guide

---

## Release Process

### Version Numbering

We follow [Semantic Versioning](https://semver.org/):

- **MAJOR:** Breaking changes
- **MINOR:** New features (backward compatible)
- **PATCH:** Bug fixes (backward compatible)

### Release Checklist

1. Update version in `Cargo.toml`
2. Update `CHANGELOG.md`
3. Run full test suite
4. Build and test documentation
5. Tag release
6. Publish to crates.io
7. Announce release

---

## Community

### Getting Help

- **GitLab Issues:** Report bugs or request features
- **Discussions:** Ask questions or share ideas
- **Email:** Contact maintainers directly for sensitive topics

### Recognition

Contributors are recognized in:

- Release notes
- `CONTRIBUTORS.md` file
- Git commit history

---

## License

By contributing to Cynapse, you agree that your contributions will be licensed under the same dual MIT/Apache-2.0 license.

---

## Questions?

If you have questions about contributing, feel free to:

- Open an issue with the `question` label
- Start a discussion
- Contact the maintainers

Thank you for contributing to Cynapse! ðŸ§