3 KiB
3 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Build and Test Commands
# Run all tests with coverage
go test -v -coverprofile=coverage.out ./...
# Run a single test
go test -v -run TestName ./pkg/enchantrix
# Run tests with race detection (as CI does)
go test -race -coverprofile=coverage.out -covermode=atomic ./...
# Run fuzz tests (CI runs 10s)
go test -run=Fuzz -fuzz=Fuzz -fuzztime=10s ./pkg/trix
# Build
go build -v ./...
# Vet
go vet ./...
# Format
go fmt ./...
If Task is installed, these are available:
task test- Run tests with coveragetask build- Build projecttask fmt- Format codetask vet- Run go vet
Architecture
Enchantrix is an encryption library with a custom .trix file format and CLI tool.
Core Packages
pkg/enchantrix - Core transformation framework
Sigilinterface: definesIn(data)andOut(data)for reversible/irreversible transformsTransmute(): applies a chain of sigils to data- Built-in sigils:
reverse,hex,base64,gzip,json,json-indent - Hash sigils:
md4,md5,sha1,sha224,sha256,sha384,sha512,ripemd160,sha3-*,sha512-*,blake2s-256,blake2b-* NewSigil(name): factory function to create sigils by string nameChaChaPolySigil: encryption sigil using XChaCha20-Poly1305 with pre-obfuscation layer
pkg/trix - Binary file format (.trix)
- Format:
[4-byte magic][1-byte version][4-byte header len][JSON header][payload] Encode(): serializes Trix struct to binaryDecode(): deserializes binary to Trix structPack()/Unpack(): apply/reverse sigils on payload- Supports optional checksums via
ChecksumAlgofield
pkg/crypt - Cryptographic services facade
Service: aggregates hashing, checksums, RSA, and PGP operations- Hash types:
lthn(custom),sha512,sha256,sha1,md5 - Checksums:
Luhn(),Fletcher16/32/64() - RSA: key generation, encrypt/decrypt via
pkg/crypt/std/rsa - PGP: key generation, encrypt/decrypt, sign/verify, symmetric encrypt via
pkg/crypt/std/pgp
cmd/trix - CLI tool (Cobra-based)
trix encode --magic XXXX --output file [sigils...]trix decode --magic XXXX --output file [sigils...]trix hash [algorithm]trix [sigil]- apply any sigil directly
Key Design Patterns
- Sigil Chain: Transformations are composable. Encoding chains sigils in order; decoding reverses.
- Pre-Obfuscation:
ChaChaPolySigilapplies XOR or shuffle-mask obfuscation before encryption so raw plaintext never goes directly to CPU encryption routines. - Streaming Support:
Encode()/Decode()accept optionalio.Writer/io.Readerfor streaming.
Testing Conventions
- Tests use
testify/assertandtestify/require - Test files follow
*_test.gopattern adjacent to implementation examples_test.gofiles contain example functions for godoc- Fuzz tests exist in
pkg/trix(go test -fuzz)
Go Version
Minimum Go 1.25. Uses go.work for workspace management.