Validators { public static void validateAesKeySize(int sizeInBytes) throws InvalidAlgorithmParameterException { if (sizeInBytes != 16 && sizeInBytes != 32) { throw new InvalidAlgorithmParameterException( String.format( "invalid key size %d; only 128-bit and 256-bit AES keys are supported", sizeInBytes * 8)); } } private  Validators(); static void validateTypeUrl(String typeUrl); static void validateAesKeySize(int sizeInBytes); static void validateVersion(int candidate, int maxExpected); static void validateSignatureHash(HashType hash); static void validateRsaModulusSize(int modulusSize); static void validateRsaPublicExponent(
      BigInteger publicExponent); static void validateNotExists(File f); static void validateExists(File f); static String validateKmsKeyUriAndRemovePrefix(String expectedPrefix, String kmsKeyUri); static void validateCryptoKeyUri(String kmsKeyUri);  }
@Test public void testValidateAesKeySize() throws Exception { Validators.validateAesKeySize(16); Validators.validateAesKeySize(32); try { Validators.validateAesKeySize(24); fail("Invalid AES key size, should have thrown exception."); } catch (GeneralSecurityException e) { TestUtil.assertExceptionContains(e, "invalid"); TestUtil.assertExceptionContains(e, "key size"); } int count = 0; for (int i = -100; i <= 100; i++) { if ((i != 16) && (i != 32)) { try { Validators.validateAesKeySize(i); fail("Invalid AES key size, should have thrown exception."); } catch (GeneralSecurityException e) { count++; TestUtil.assertExceptionContains(e, "invalid"); TestUtil.assertExceptionContains(e, "key size"); } } } assertEquals(201 - 2, count); }