func TestAESCTREncryptorIntegration(t *testing.T) {
	tests := []struct {
		name string
		want []byte
	}{
		{
			"Simple string",
			[]byte("i am a secret"),
		},
		{
			"Binary",
			[]byte{
				0xb0, 0x75, 0x11, 0x62, 0xa2, 0x3e, 0x5f, 0x2f,
				0xca, 0xa3, 0x00, 0x1d, 0x51, 0x89, 0xc8, 0xe7,
				0xb5, 0x15, 0xb9, 0x5c, 0x9b, 0x3e, 0x26, 0x5f,
				0xb2, 0x6b, 0x97, 0x41, 0x16, 0x2c, 0x47, 0x10,
			},
		},
	}
	for _, tt := range tests {
		e, err := NewAES([]byte("anAesTestKey1234"), []byte("hmacKey"))
		if err != nil {
			t.Errorf("%q. NewAES() = %s", tt.name, err)
			continue
		}
		encrypted, err := e.Encrypt(tt.want)
		if err != nil {
			t.Errorf("%q. Encrypt() = %s", tt.name, err)
			continue
		}
		got, err := e.Decrypt(encrypted)
		if err != nil {
			t.Errorf("%q. Decrypt() = %s", tt.name, err)
			continue
		}
		if !bytes.Equal(got, tt.want) {
			t.Errorf("%q. Secret mismatch, got %v, want %v", tt.name, string(got), string(tt.want))
		}
	}
}
TestAesCTREncryptorIntegration ensures Encrypt() and Decrypt() work together
to produce the same plain-text as the original input.
package encryptor
import (
	"bytes"
	"crypto/hmac"
	"crypto/sha256"
	"testing"
)
func TestNewAES(t *testing.T) {
	tests := []struct {
		name string
		aesKey  []byte
		hmacKey []byte
		want    AESCTREncryptor
		wantErr error
	}{
		{
			"Correct",
			[]byte("12345678901234567890123456789012"),
			[]byte("SECRETSM8"),
			AESCTREncryptor{
				aesKey:  []byte("12345678901234567890123456789012"),
				hmacKey: []byte("SECRETSM8"),
			},
			nil,
		},
		{
			"AES key required",
			[]byte{},
			[]byte("SECRETSM8"),
			AESCTREncryptor{},
			ErrKeyTooShort,
		},
		{
			"HMAC key required",
			[]byte("12345678901234567890123456789012"),
			[]byte{},
			AESCTREncryptor{},
			ErrHmacKeyTooShort,
		},
		{
			"Error with wrong AES key length",
			[]byte("short"),
			[]byte("SECRETSM8"),
			AESCTREncryptor{},
			ErrKeyTooShort,
		},
	}
	for _, tt := range tests {
		got, err := NewAES(tt.aesKey, tt.hmacKey)
		if err != tt.wantErr {
			t.Errorf("%q. NewAES() error = %v, wantErr %v", tt.name, err, tt.wantErr)
		}
		if err != nil {
			continue
		}
		if bytes.Compare(tt.want.aesKey, got.aesKey) != 0 {
			t.Errorf("%q. NewAES() easKey = %v, want %v", tt.name, got.aesKey, tt.want.aesKey)
		}
		if bytes.Compare(tt.want.hmacKey, got.hmacKey) != 0 {
			t.Errorf("%q. NewAES() easKey = %v, want %v", tt.name, got.hmacKey, tt.want.hmacKey)
		}
	}
}