refactor(ax): rename nonce helper for clearer naming
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
50bb356c7c
commit
c6adf478d8
4 changed files with 15 additions and 15 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
```
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue