public final class ProtectionReport

  1. Object
  2. ProtectionReport

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.

Nested types

class ProtectionReport.BuilderAccumulates the answers for a ProtectionReport.

Fields

public static final int YES = 1The protection is provided.
public static final int NO = 0The protection is not provided.
public static final int UNKNOWN = -1The platform cannot say.

Methods

public static ProtectionReport.Builder builder()Starts building a report.
public static ProtectionReport none()A report that answers NO to everything.
public static ProtectionReport unknown()A report that answers UNKNOWN to everything.
public int answer(Protection protection)The answer for one protection: YES, NO or UNKNOWN.
public boolean provides(Protection protection)Whether this report provides the protection, with UNKNOWN counting as no.
public boolean satisfies(Protection[] required)Whether every requirement in required is answered YES.
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.
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.

Inherited methods

Field details

YES

public static final int YES = 1
The protection is provided.

NO

public static final int NO = 0
The protection is not provided.

UNKNOWN

public static final int UNKNOWN = -1
The platform cannot say. Treat as not provided when a guarantee is required.

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 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 Protection[]
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 Protection[]
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.