github.com/trustbloc/kms-go@v1.1.2/crypto/tinkcrypto/primitive/aead/subtle/subtle_test.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package subtle_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/require"
    13  
    14  	"github.com/trustbloc/kms-go/crypto/tinkcrypto/primitive/aead/subtle"
    15  )
    16  
    17  func TestValidateAESKeySize(t *testing.T) {
    18  	var i uint32
    19  	for i = 0; i < 65; i++ {
    20  		err := subtle.ValidateAESKeySize(i)
    21  
    22  		switch i {
    23  		case 16, 24, 32: // Valid key sizes.
    24  			require.NoError(t, err)
    25  
    26  		default:
    27  			// Invalid key sizes.
    28  			require.Errorf(t, err, "invalid key size (%d) should not be accepted", i)
    29  
    30  			require.Contains(t, err.Error(), "invalid AES key size; want 16, 24 or 32")
    31  		}
    32  	}
    33  }