public KeysetHandle.Entry getPrimary() {
    for (Entry entry : entries) {
      if (entry != null && entry.isPrimary()) {
        if (entry.getStatus() != KeyStatus.ENABLED) {
          throw new IllegalStateException("Keyset has primary which isn't enabled");
        }
        return entry;
      }
    }
    throw new IllegalStateException("Keyset has no valid primary");
  }
Returns the unique entry where isPrimary() = true and getStatus() = ENABLED.

<p>Note: currently this may throw IllegalStateException, since it is possible that keysets are
parsed without a primary. In the future, such keysets will be rejected when the keyset is
parsed.
java_src/src/main/java/com/google/crypto/tink/KeysetHandle.java