fix: resolve mnd and nestif linter errors

- Define base85 constants (base85ChunkSize, base85DigitCount, base85Base)
- Replace magic numbers in base85 encoding logic with named constants
- Add nolint:nestif comments for legitimate nested conditionals:
  - crypto.go: Clear separation between secret generation vs retrieval
  - secrets.go: Separate JSON and table output formatting logic
  - vault.go: Separate JSON and text output formatting logic
This commit is contained in:
2025-07-09 12:54:59 -07:00
parent 93a32217e0
commit 54fce0f187
4 changed files with 17 additions and 11 deletions

View File

@@ -355,24 +355,30 @@ func encodeBase85WithRFC1924Charset(data []byte) string {
// RFC1924 character set
charset := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"
const (
base85ChunkSize = 4 // Process 4 bytes at a time
base85DigitCount = 5 // Each chunk produces 5 digits
base85Base = 85 // Base85 encoding uses base 85
)
// Pad data to multiple of 4
padded := make([]byte, ((len(data)+3)/4)*4)
padded := make([]byte, ((len(data)+base85ChunkSize-1)/base85ChunkSize)*base85ChunkSize)
copy(padded, data)
var buf strings.Builder
buf.Grow(len(padded) * 5 / 4) // Each 4 bytes becomes 5 Base85 characters
buf.Grow(len(padded) * base85DigitCount / base85ChunkSize) // Each 4 bytes becomes 5 Base85 characters
// Process in 4-byte chunks
for i := 0; i < len(padded); i += 4 {
for i := 0; i < len(padded); i += base85ChunkSize {
// Convert 4 bytes to uint32 (big-endian)
chunk := binary.BigEndian.Uint32(padded[i : i+4])
chunk := binary.BigEndian.Uint32(padded[i : i+base85ChunkSize])
// Convert to 5 base-85 digits
digits := make([]byte, 5)
for j := 4; j >= 0; j-- {
idx := chunk % 85
digits := make([]byte, base85DigitCount)
for j := base85DigitCount - 1; j >= 0; j-- {
idx := chunk % base85Base
digits[j] = charset[idx]
chunk /= 85
chunk /= base85Base
}
buf.Write(digits)