Class ProtectionReport

java.lang.Object
com.codename1.security.vault.ProtectionReport

public final class ProtectionReport extends Object

What a store, a key or a vault actually provides, one Protection at a time.

Three answers rather than two. UNKNOWN is what a port returns when the platform will not tell it -- a browser has no way to learn whether a CryptoKey ended up in a secure element, and the honest report of that is not NO (which would understate an authenticator that does use one) and certainly not YES. Callers that need a guarantee must treat UNKNOWN as "not provided"; callers that are only describing the state to a user can say so.

A report describes what was observed, not what an API exists for. A port that finds crypto.subtle present but cannot complete a round trip through it reports Protection.ENCRYPTED_AT_REST as NO.

  • Field Details

    • YES

      public static final int YES
      The protection is provided.
      See Also:
    • NO

      public static final int NO
      The protection is not provided.
      See Also:
    • UNKNOWN

      public static final int UNKNOWN
      The platform cannot say. Treat as not provided when a guarantee is required.
      See Also:
  • Method Details

    • builder

      public static ProtectionReport.Builder builder()
      Starts building a report. Every protection not explicitly set answers UNKNOWN, which is the correct default for a port that has not considered the question.
    • none

      public static ProtectionReport none()
      A report that answers NO to everything. What the fallback returns on a platform with no secure store at all.
    • unknown

      public static ProtectionReport unknown()
      A report that answers UNKNOWN to everything. What to return when the store could not be reached at all, as distinct from a store that was reached and provides nothing.
    • answer

      public int answer(Protection protection)

      The answer for one protection: YES, NO or UNKNOWN.

      Parameters
      • protection: the protection to ask about
      Returns

      one of the three answers, never an exception for an unconsidered protection

    • provides

      public boolean provides(Protection protection)

      Whether this report provides the protection, with UNKNOWN counting as no.

      The method to call when a policy has to be enforced. Use answer(Protection) when the difference between "no" and "cannot say" matters to the caller, which it does when the answer is being shown to a user.

    • satisfies

      public boolean satisfies(Protection[] required)

      Whether every requirement in required is answered YES.

      Parameters
      • required: the protections a caller insists on, may be null or empty
      Returns

      true when all of them are provided

    • firstUnmet

      public Protection firstUnmet(Protection[] required)

      The first requirement this report does not provide, for an error message that names the thing that was missing rather than saying the request was refused.

      Parameters
      • required: the protections a caller insists on, may be null
      Returns

      the unmet protection, or null when everything is provided

    • toString

      public String toString()
      A human readable line per protection, for diagnostics and for the "what protects this" screen an application that cares about this will end up writing.
      Overrides:
      toString in class Object