29 lines
1.1 KiB
Go
29 lines
1.1 KiB
Go
package symm
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestAEADOptionsRequireNonce(t *testing.T) {
|
|
aesKey := []byte("0123456789abcdef")
|
|
sm4Key := []byte("0123456789abcdef")
|
|
plain := []byte("nonce-required")
|
|
|
|
gcmIVOnly := &CipherOptions{Mode: MODEGCM, IV: []byte("123456789012")}
|
|
if _, err := EncryptAesWithOptions(plain, aesKey, gcmIVOnly); !errors.Is(err, ErrInvalidGCMNonceLength) {
|
|
t.Fatalf("expected ErrInvalidGCMNonceLength for AES GCM with IV-only opts, got: %v", err)
|
|
}
|
|
if _, err := EncryptSM4WithOptions(plain, sm4Key, gcmIVOnly); !errors.Is(err, ErrInvalidGCMNonceLength) {
|
|
t.Fatalf("expected ErrInvalidGCMNonceLength for SM4 GCM with IV-only opts, got: %v", err)
|
|
}
|
|
|
|
ccmIVOnly := &CipherOptions{Mode: MODECCM, IV: []byte("123456789012")}
|
|
if _, err := EncryptAesWithOptions(plain, aesKey, ccmIVOnly); !errors.Is(err, ErrInvalidCCMNonceLength) {
|
|
t.Fatalf("expected ErrInvalidCCMNonceLength for AES CCM with IV-only opts, got: %v", err)
|
|
}
|
|
if _, err := EncryptSM4WithOptions(plain, sm4Key, ccmIVOnly); !errors.Is(err, ErrInvalidCCMNonceLength) {
|
|
t.Fatalf("expected ErrInvalidCCMNonceLength for SM4 CCM with IV-only opts, got: %v", err)
|
|
}
|
|
}
|