ax(mining): rename abbreviated variables b and h to randomBytes and digest in auth.go
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

AX Principle 1 — predictable names over short names. Single-letter variables
b (random byte buffer) and h (MD5 digest array) require mental mapping; full
names make intent self-evident without comments.

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 09:46:32 +01:00
parent 840418c33e
commit cb44a640cb
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -199,13 +199,13 @@ func (da *DigestAuth) validateBasic(c *gin.Context, authHeader string) bool {
// nonce := da.generateNonce() // 32-char hex string, cryptographically random
func (da *DigestAuth) generateNonce() string {
b := make([]byte, 16)
if _, err := rand.Read(b); err != nil {
randomBytes := make([]byte, 16)
if _, err := rand.Read(randomBytes); err != nil {
// Cryptographic failure is critical - fall back to time-based nonce
// This should never happen on a properly configured system
return hex.EncodeToString([]byte(fmt.Sprintf("%d", time.Now().UnixNano())))
}
return hex.EncodeToString(b)
return hex.EncodeToString(randomBytes)
}
// opaque := da.generateOpaque() // MD5 of realm, stable per auth instance
@ -261,6 +261,6 @@ func parseDigestParams(header string) map[string]string {
// h := md5Hash("user:realm:pass") // "5f4dcc3b5aa765d61d8327deb882cf99"
func md5Hash(s string) string {
h := md5.Sum([]byte(s))
return hex.EncodeToString(h[:])
digest := md5.Sum([]byte(s))
return hex.EncodeToString(digest[:])
}