From c6adf478d80c151ca6783b6b8626853ffe656aed Mon Sep 17 00:00:00 2001 From: Virgil Date: Tue, 31 Mar 2026 13:41:04 +0000 Subject: [PATCH] refactor(ax): rename nonce helper for clearer naming Co-Authored-By: Virgil --- datanode/medium.go | 4 ++-- docs/RFC.md | 6 +++--- sigil/crypto_sigil.go | 4 ++-- sigil/crypto_sigil_test.go | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/datanode/medium.go b/datanode/medium.go index 73c0f78..6896eb2 100644 --- a/datanode/medium.go +++ b/datanode/medium.go @@ -345,8 +345,8 @@ func (medium *Medium) List(filePath string) ([]fs.DirEntry, error) { prefix += "/" } seen := make(map[string]bool) - for _, e := range entries { - seen[e.Name()] = true + for _, entry := range entries { + seen[entry.Name()] = true } for directoryPath := range medium.directorySet { diff --git a/docs/RFC.md b/docs/RFC.md index adcbe42..9041f79 100644 --- a/docs/RFC.md +++ b/docs/RFC.md @@ -2359,7 +2359,7 @@ Returned when ciphertext is too short to decrypt. Example: ```go -_, err := sigil.GetNonceFromCiphertext([]byte("short")) +_, err := sigil.NonceFromCiphertext([]byte("short")) if errors.Is(err, sigil.CiphertextTooShortError) { // handle truncated payload } @@ -2503,7 +2503,7 @@ ob := &sigil.ShuffleMaskObfuscator{} s, _ := sigil.NewChaChaPolySigil(key, ob) ``` -### GetNonceFromCiphertext(ciphertext []byte) ([]byte, error) +### NonceFromCiphertext(ciphertext []byte) ([]byte, error) Extracts the XChaCha20 nonce from encrypted output. @@ -2512,5 +2512,5 @@ Example: key := make([]byte, 32) s, _ := sigil.NewChaChaPolySigil(key, nil) ciphertext, _ := s.In([]byte("hello")) -nonce, _ := sigil.GetNonceFromCiphertext(ciphertext) +nonce, _ := sigil.NonceFromCiphertext(ciphertext) ``` diff --git a/sigil/crypto_sigil.go b/sigil/crypto_sigil.go index e012974..e88e657 100644 --- a/sigil/crypto_sigil.go +++ b/sigil/crypto_sigil.go @@ -275,8 +275,8 @@ func (sigil *ChaChaPolySigil) Out(data []byte) ([]byte, error) { return plaintext, nil } -// Example: nonce, _ := sigil.GetNonceFromCiphertext(ciphertext) -func GetNonceFromCiphertext(ciphertext []byte) ([]byte, error) { +// Example: nonce, _ := sigil.NonceFromCiphertext(ciphertext) +func NonceFromCiphertext(ciphertext []byte) ([]byte, error) { nonceSize := chacha20poly1305.NonceSizeX if len(ciphertext) < nonceSize { return nil, CiphertextTooShortError diff --git a/sigil/crypto_sigil_test.go b/sigil/crypto_sigil_test.go index 31fb653..d7a2e29 100644 --- a/sigil/crypto_sigil_test.go +++ b/sigil/crypto_sigil_test.go @@ -362,28 +362,28 @@ func TestCryptoSigil_ChaChaPolySigil_NoObfuscator_Good(t *testing.T) { assert.Equal(t, plaintext, decrypted) } -func TestCryptoSigil_GetNonceFromCiphertext_Good(t *testing.T) { +func TestCryptoSigil_NonceFromCiphertext_Good(t *testing.T) { key := make([]byte, 32) _, _ = rand.Read(key) cipherSigil, _ := NewChaChaPolySigil(key, nil) ciphertext, _ := cipherSigil.In([]byte("nonce extraction test")) - nonce, err := GetNonceFromCiphertext(ciphertext) + nonce, err := NonceFromCiphertext(ciphertext) require.NoError(t, err) assert.Len(t, nonce, 24) assert.Equal(t, ciphertext[:24], nonce) } -func TestCryptoSigil_GetNonceFromCiphertext_NonceCopied_Good(t *testing.T) { +func TestCryptoSigil_NonceFromCiphertext_NonceCopied_Good(t *testing.T) { key := make([]byte, 32) _, _ = rand.Read(key) cipherSigil, _ := NewChaChaPolySigil(key, nil) ciphertext, _ := cipherSigil.In([]byte("data")) - nonce, _ := GetNonceFromCiphertext(ciphertext) + nonce, _ := NonceFromCiphertext(ciphertext) original := make([]byte, len(nonce)) copy(original, nonce) @@ -391,13 +391,13 @@ func TestCryptoSigil_GetNonceFromCiphertext_NonceCopied_Good(t *testing.T) { assert.Equal(t, original, ciphertext[:24]) } -func TestCryptoSigil_GetNonceFromCiphertext_TooShort_Bad(t *testing.T) { - _, err := GetNonceFromCiphertext([]byte("short")) +func TestCryptoSigil_NonceFromCiphertext_TooShort_Bad(t *testing.T) { + _, err := NonceFromCiphertext([]byte("short")) assert.ErrorIs(t, err, CiphertextTooShortError) } -func TestCryptoSigil_GetNonceFromCiphertext_Empty_Bad(t *testing.T) { - _, err := GetNonceFromCiphertext(nil) +func TestCryptoSigil_NonceFromCiphertext_Empty_Bad(t *testing.T) { + _, err := NonceFromCiphertext(nil) assert.ErrorIs(t, err, CiphertextTooShortError) }