test_class.file: java_src/src/test/java/com/google/crypto/tink/UtilTest.java
test_class.identifier: UtilTest
test_case.body: @Test
    public void testValidateKeyset_withDestroyedKey_shouldWork() throws Exception {
      String keyValue = "01234567890123456";
      Keyset validKeyset =
          TestUtil.createKeyset(
              TestUtil.createKey(
                  TestUtil.createHmacKeyData(keyValue.getBytes("UTF-8"), 16),
                  42,
                  KeyStatusType.ENABLED,
                  OutputPrefixType.TINK),
              TestUtil.createKey(
                  TestUtil.createHmacKeyData(keyValue.getBytes("UTF-8"), 16),
                  42,
                  KeyStatusType.DESTROYED,
                  OutputPrefixType.TINK));
      try {
        Util.validateKeyset(validKeyset);
      } catch (GeneralSecurityException e) {
        fail("Valid keyset, should not fail: " + e);
      }
    }
test_case.class_method_signature: UtilTest.testValidateKeyset_withDestroyedKey_shouldWork()
test_case.full_signature: @Test public void testValidateKeyset_withDestroyedKey_shouldWork()
test_case.identifier: testValidateKeyset_withDestroyedKey_shouldWork
test_case.invocations: createKeyset createKey createHmacKeyData getBytes createKey createHmacKeyData getBytes validateKeyset fail
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testValidateKeyset_withDestroyedKey_shouldWork()
focal_class.declarator: UTF_8 = Charset.forName("UTF-8")
focal_class.modifier: public static final
focal_class.original_string: public static final Charset UTF_8 = Charset.forName("UTF-8");
focal_class.type: Charset
focal_class.var_name: UTF_8
focal_class.file: java_src/src/main/java/com/google/crypto/tink/Util.java
focal_class.identifier: Util
focal_class.class_method_signature: Util.getKeysetInfo(Keyset keyset)
focal_class.full_signature: public static KeysetInfo getKeysetInfo(Keyset keyset)
focal_class.identifier: getKeysetInfo
focal_class.modifiers: public static
focal_class.parameters: (Keyset keyset)
focal_class.return: KeysetInfo
focal_class.signature: KeysetInfo getKeysetInfo(Keyset keyset)
focal_class.class_method_signature: Util.getKeyInfo(Keyset.Key key)
focal_class.full_signature: public static KeysetInfo.KeyInfo getKeyInfo(Keyset.Key key)
focal_class.identifier: getKeyInfo
focal_class.modifiers: public static
focal_class.parameters: (Keyset.Key key)
focal_class.return: KeysetInfo.KeyInfo
focal_class.signature: KeysetInfo.KeyInfo getKeyInfo(Keyset.Key key)
focal_class.class_method_signature: Util.validateKey(Keyset.Key key)
focal_class.full_signature: public static void validateKey(Keyset.Key key)
focal_class.identifier: validateKey
focal_class.modifiers: public static
focal_class.parameters: (Keyset.Key key)
focal_class.return: void
focal_class.signature: void validateKey(Keyset.Key key)
focal_class.class_method_signature: Util.validateKeyset(Keyset keyset)
focal_class.full_signature: public static void validateKeyset(Keyset keyset)
focal_class.identifier: validateKeyset
focal_class.modifiers: public static
focal_class.parameters: (Keyset keyset)
focal_class.return: void
focal_class.signature: void validateKeyset(Keyset keyset)
focal_class.class_method_signature: Util.readAll(InputStream inputStream)
focal_class.full_signature: public static byte[] readAll(InputStream inputStream)
focal_class.identifier: readAll
focal_class.modifiers: public static
focal_class.parameters: (InputStream inputStream)
focal_class.return: byte[]
focal_class.signature: byte[] readAll(InputStream inputStream)
focal_method.body: public static void validateKeyset(Keyset keyset) throws GeneralSecurityException {
      int primaryKeyId = keyset.getPrimaryKeyId();
      boolean hasPrimaryKey = false;
      boolean containsOnlyPublicKeyMaterial = true;
      int numEnabledKeys = 0;
      for (Keyset.Key key : keyset.getKeyList()) {
        if (key.getStatus() != KeyStatusType.ENABLED) {
          continue;
        }
        validateKey(key);
        if (key.getKeyId() == primaryKeyId) {
          if (hasPrimaryKey) {
            throw new GeneralSecurityException("keyset contains multiple primary keys");
          }
          hasPrimaryKey = true;
        }
        if (key.getKeyData().getKeyMaterialType() != KeyData.KeyMaterialType.ASYMMETRIC_PUBLIC) {
          containsOnlyPublicKeyMaterial = false;
        }
        numEnabledKeys++;
      }
      if (numEnabledKeys == 0) {
        throw new GeneralSecurityException("keyset must contain at least one ENABLED key");
      }
      // Checks that a keyset contains a primary key, except when it contains only public keys.
      if (!hasPrimaryKey && !containsOnlyPublicKeyMaterial) {
        throw new GeneralSecurityException("keyset doesn't contain a valid primary key");
      }
    }
focal_method.class_method_signature: Util.validateKeyset(Keyset keyset)
focal_method.full_signature: public static void validateKeyset(Keyset keyset)
focal_method.identifier: validateKeyset
focal_method.invocations: getPrimaryKeyId getKeyList getStatus validateKey getKeyId getKeyMaterialType getKeyData
focal_method.modifiers: public static
focal_method.parameters: (Keyset keyset)
focal_method.return: void
focal_method.signature: void validateKeyset(Keyset keyset)