rust-license-key 0.1.0

A production-grade Rust library for creating and validating offline software licenses using Ed25519 cryptography
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# Contributing

Thank you for your interest in contributing to rust-license-key! This document provides guidelines and information for contributors.

## Table of Contents

1. [Code of Conduct]#code-of-conduct
2. [Getting Started]#getting-started
3. [Development Setup]#development-setup
4. [Making Changes]#making-changes
5. [Code Style]#code-style
6. [Testing]#testing
7. [Documentation]#documentation
8. [Pull Request Process]#pull-request-process
9. [Security Issues]#security-issues

---

## Code of Conduct

This project follows the [Rust Code of Conduct](https://www.rust-lang.org/policies/code-of-conduct). Please be respectful and constructive in all interactions.

---

## Getting Started

### Types of Contributions

We welcome various types of contributions:

| Type | Description |
|------|-------------|
| Bug Reports | Report issues with detailed reproduction steps |
| Bug Fixes | Fix reported issues |
| Features | Propose and implement new features |
| Documentation | Improve or expand documentation |
| Tests | Add test coverage |
| Performance | Optimize code without changing behavior |
| Security | Report or fix security vulnerabilities |

### Before You Start

1. **Check existing issues**: Someone may already be working on it
2. **Open an issue first**: For significant changes, discuss before coding
3. **Read the architecture docs**: Understand the codebase design

---

## Development Setup

### Prerequisites

- Rust 1.70 or later
- Git

### Clone and Build

```bash
# Clone the repository
git clone https://github.com/Simon-Stephan/rust-license-key.git
cd rust-license-key

# Build
cargo build

# Run tests
cargo test

# Run clippy
cargo clippy

# Format code
cargo fmt
```

### IDE Setup

**VS Code with rust-analyzer (recommended):**

```json
// .vscode/settings.json
{
    "rust-analyzer.checkOnSave.command": "clippy",
    "editor.formatOnSave": true
}
```

---

## Making Changes

### Branch Naming

Use descriptive branch names:

```
feature/add-hostname-wildcards
fix/expired-license-validation
docs/improve-security-guide
test/add-edge-case-coverage
```

### Commit Messages

Follow conventional commit format:

```
type(scope): short description

Longer description if needed.

Fixes #123
```

**Types:**
- `feat`: New feature
- `fix`: Bug fix
- `docs`: Documentation
- `test`: Tests
- `refactor`: Code restructuring
- `perf`: Performance improvement
- `chore`: Maintenance

**Examples:**
```
feat(builder): add wildcard hostname support

Add ability to use wildcards like *.example.com in
allowed_hostnames constraint.

Fixes #42
```

```
fix(validator): correctly handle timezone in expiration check

The expiration check was comparing naive datetimes, which could
cause incorrect validation when server timezone differs from UTC.

Fixes #87
```

---

## Code Style

### Formatting

All code must pass `cargo fmt`:

```bash
cargo fmt --check
```

### Linting

All code must pass `cargo clippy` without warnings:

```bash
cargo clippy -- -D warnings
```

### Naming Conventions

| Element | Convention | Example |
|---------|------------|---------|
| Types | PascalCase | `LicensePayload` |
| Functions | snake_case | `validate_license` |
| Variables | snake_case | `license_json` |
| Constants | SCREAMING_SNAKE_CASE | `LICENSE_FORMAT_VERSION` |
| Modules | snake_case | `license_builder` |

### Code Organization

```rust
// 1. Module documentation
//! This module provides...

// 2. Imports (grouped and sorted)
use std::collections::HashMap;
use chrono::DateTime;
use serde::{Deserialize, Serialize};

use crate::error::LicenseError;

// 3. Constants
const MAX_PAYLOAD_SIZE: usize = 1024 * 1024;

// 4. Type definitions
pub struct MyType { ... }

// 5. Implementations
impl MyType {
    // Public methods first
    pub fn new() -> Self { ... }

    // Private methods after
    fn internal_helper(&self) { ... }
}

// 6. Tests
#[cfg(test)]
mod tests { ... }
```

### Documentation

All public items must have rustdoc comments:

```rust
/// Creates a new license builder.
///
/// # Example
///
/// ```
/// use rust_license_key::builder::LicenseBuilder;
///
/// let builder = LicenseBuilder::new()
///     .license_id("LIC-001");
/// ```
pub fn new() -> Self {
    // ...
}
```

### Error Handling

- No `unwrap()` or `expect()` in library code (except tests)
- Return `Result` for all fallible operations
- Provide descriptive error context

```rust
// Bad
let key = BASE64.decode(input).unwrap();

// Good
let key = BASE64.decode(input).map_err(|e| {
    LicenseError::InvalidPublicKey {
        reason: format!("invalid base64 encoding: {}", e),
    }
})?;
```

---

## Testing

### Running Tests

```bash
# All tests
cargo test

# Specific test
cargo test test_name

# With output
cargo test -- --nocapture

# Only integration tests
cargo test --test integration_tests
```

### Writing Tests

#### Unit Tests

Place in the same file as the code:

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

    #[test]
    fn test_specific_behavior() {
        // Arrange
        let input = prepare_input();

        // Act
        let result = function_under_test(input);

        // Assert
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), expected);
    }
}
```

#### Integration Tests

Place in `tests/` directory:

```rust
// tests/my_feature_tests.rs
use rust_license_key::prelude::*;

#[test]
fn test_complete_workflow() {
    // Test end-to-end functionality
}
```

### Test Coverage Requirements

- All new public functions must have tests
- All bug fixes must include a regression test
- Aim for >90% line coverage on critical paths

### Test Naming

```rust
#[test]
fn test_<function>_<scenario>_<expected_outcome>() { }

// Examples
fn test_validate_expired_license_returns_failure() { }
fn test_builder_missing_customer_id_fails() { }
fn test_parse_valid_json_succeeds() { }
```

---

## Documentation

### Types of Documentation

| Location | Purpose |
|----------|---------|
| `src/*.rs` | Rustdoc for API documentation |
| `docs/` | User guides and tutorials |
| `CHANGELOG.md` | Version history |
| `README.md` | Project overview |

### Rustdoc Guidelines

```rust
/// Brief one-line description.
///
/// Longer description with details about behavior,
/// use cases, and important notes.
///
/// # Arguments
///
/// * `param1` - Description of first parameter
/// * `param2` - Description of second parameter
///
/// # Returns
///
/// Description of return value.
///
/// # Errors
///
/// Returns `LicenseError::X` when Y happens.
///
/// # Example
///
/// ```
/// // Working example code
/// ```
///
/// # Panics
///
/// This function never panics. (or describe panic conditions)
///
/// # Security
///
/// Important security considerations.
pub fn function_name(...) { }
```

### Building Documentation

```bash
# Build and open docs
cargo doc --open

# Include private items
cargo doc --document-private-items
```

---

## Pull Request Process

### Before Submitting

1. **Rebase on main**: Ensure your branch is up to date
2. **Run all checks**:
   ```bash
   cargo fmt --check
   cargo clippy -- -D warnings
   cargo test
   ```
3. **Update documentation**: If applicable
4. **Add changelog entry**: For user-facing changes

### PR Template

```markdown
## Description

Brief description of changes.

## Type of Change

- [ ] Bug fix
- [ ] New feature
- [ ] Documentation
- [ ] Other (describe)

## Checklist

- [ ] Code follows project style guidelines
- [ ] Tests pass locally
- [ ] Added tests for new functionality
- [ ] Updated documentation
- [ ] Added changelog entry

## Related Issues

Fixes #123
```

### Review Process

1. **Automated checks**: CI must pass
2. **Code review**: At least one maintainer approval
3. **Documentation review**: For significant changes
4. **Security review**: For crypto or validation changes

### After Merge

- Delete your branch
- Verify the change in the next release

---

## Security Issues

### Reporting Security Vulnerabilities

**Do NOT open a public issue for security vulnerabilities.**

Instead, please use GitHub's private vulnerability reporting or contact the maintainer directly.

Include:
- Description of the vulnerability
- Steps to reproduce
- Potential impact
- Suggested fix (if any)

### Security Review Process

Security-related PRs require:
1. Review by a maintainer with security experience
2. Verification of cryptographic correctness
3. Consideration of backward compatibility

### Areas of Special Concern

Changes to these areas require extra scrutiny:

- `crypto.rs`: All cryptographic operations
- `parser.rs`: Signature verification logic
- `validator.rs`: Constraint checking logic
- Any changes affecting the license format

---

## Getting Help

- **Questions**: Open a GitHub Discussion
- **Bugs**: Open a GitHub Issue
- **Security**: Use GitHub's private vulnerability reporting

Thank you for contributing to rust-license-key!

---

**Previous:** [Architecture]./architecture.md | **Home:** [Documentation]./README.md