Skip to content

Commit 748ca6d

Browse files
committed
docs: add CLAUDE.md for project guidelines and testing conventions
1 parent 1e1dfee commit 748ca6d

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Build and Test Commands
6+
7+
```shell
8+
# Run all tests with coverage
9+
go test -v -coverprofile=coverage.out ./...
10+
11+
# Run a single test
12+
go test -v -run TestName ./pkg/enchantrix
13+
14+
# Run tests with race detection (as CI does)
15+
go test -race -coverprofile=coverage.out -covermode=atomic ./...
16+
17+
# Run fuzz tests (CI runs 10s)
18+
go test -run=Fuzz -fuzz=Fuzz -fuzztime=10s ./pkg/trix
19+
20+
# Build
21+
go build -v ./...
22+
23+
# Vet
24+
go vet ./...
25+
26+
# Format
27+
go fmt ./...
28+
```
29+
30+
If Task is installed, these are available:
31+
- `task test` - Run tests with coverage
32+
- `task build` - Build project
33+
- `task fmt` - Format code
34+
- `task vet` - Run go vet
35+
36+
## Architecture
37+
38+
Enchantrix is an encryption library with a custom `.trix` file format and CLI tool.
39+
40+
### Core Packages
41+
42+
**pkg/enchantrix** - Core transformation framework
43+
- `Sigil` interface: defines `In(data)` and `Out(data)` for reversible/irreversible transforms
44+
- `Transmute()`: applies a chain of sigils to data
45+
- Built-in sigils: `reverse`, `hex`, `base64`, `gzip`, `json`, `json-indent`
46+
- Hash sigils: `md4`, `md5`, `sha1`, `sha224`, `sha256`, `sha384`, `sha512`, `ripemd160`, `sha3-*`, `sha512-*`, `blake2s-256`, `blake2b-*`
47+
- `NewSigil(name)`: factory function to create sigils by string name
48+
- `ChaChaPolySigil`: encryption sigil using XChaCha20-Poly1305 with pre-obfuscation layer
49+
50+
**pkg/trix** - Binary file format (.trix)
51+
- Format: `[4-byte magic][1-byte version][4-byte header len][JSON header][payload]`
52+
- `Encode()`: serializes Trix struct to binary
53+
- `Decode()`: deserializes binary to Trix struct
54+
- `Pack()`/`Unpack()`: apply/reverse sigils on payload
55+
- Supports optional checksums via `ChecksumAlgo` field
56+
57+
**pkg/crypt** - Cryptographic services facade
58+
- `Service`: aggregates hashing, checksums, RSA, and PGP operations
59+
- Hash types: `lthn` (custom), `sha512`, `sha256`, `sha1`, `md5`
60+
- Checksums: `Luhn()`, `Fletcher16/32/64()`
61+
- RSA: key generation, encrypt/decrypt via `pkg/crypt/std/rsa`
62+
- PGP: key generation, encrypt/decrypt, sign/verify, symmetric encrypt via `pkg/crypt/std/pgp`
63+
64+
**cmd/trix** - CLI tool (Cobra-based)
65+
- `trix encode --magic XXXX --output file [sigils...]`
66+
- `trix decode --magic XXXX --output file [sigils...]`
67+
- `trix hash [algorithm]`
68+
- `trix [sigil]` - apply any sigil directly
69+
70+
### Key Design Patterns
71+
72+
1. **Sigil Chain**: Transformations are composable. Encoding chains sigils in order; decoding reverses.
73+
2. **Pre-Obfuscation**: `ChaChaPolySigil` applies XOR or shuffle-mask obfuscation before encryption so raw plaintext never goes directly to CPU encryption routines.
74+
3. **Streaming Support**: `Encode()`/`Decode()` accept optional `io.Writer`/`io.Reader` for streaming.
75+
76+
## Testing Conventions
77+
78+
- Tests use `testify/assert` and `testify/require`
79+
- Test files follow `*_test.go` pattern adjacent to implementation
80+
- `examples_test.go` files contain example functions for godoc
81+
- Fuzz tests exist in `pkg/trix` (`go test -fuzz`)
82+
83+
## Go Version
84+
85+
Minimum Go 1.25. Uses `go.work` for workspace management.

go.work.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
github.com/bwesterb/go-ristretto v1.2.3 h1:1w53tCkGhCQ5djbat3+MH0BAQ5Kfgbt56UZQ/JMzngw=
12
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
3+
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
4+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
25
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
36
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
47
golang.org/x/net v0.45.0 h1:RLBg5JKixCy82FtLJpeNlVM0nrSqpCRYzVU1n8kj0tM=

0 commit comments

Comments
 (0)