fromBoolean

fun fromBoolean(value: Boolean, challenge: ByteArray): Attestation

Factory method to create an attestation instance based on a boolean condition.

This convenience method simplifies attestation selection by allowing callers to specify whether hardware attestation should be used via a boolean parameter. It's particularly useful when attestation requirements are determined dynamically based on device capabilities, security policies, or configuration settings.

The method automatically handles challenge management:

  • When value is true, creates Default attestation with the provided challenge

  • When value is false, creates None attestation (challenge is ignored)

Common usage patterns:

// Based on device capability detection
val attestation = Attestation.fromBoolean(
value = deviceHasHardwareAttestation(),
challenge = serverChallenge
)

// Based on application security policy
val attestation = Attestation.fromBoolean(
value = requireHighSecurity,
challenge = authChallenge
)

// Based on user preference or admin setting
val attestation = Attestation.fromBoolean(
value = userSettings.enableHardwareAttestation,
challenge = challenge
)

Return

Default attestation instance if value is true, None otherwise

Parameters

value

Boolean flag indicating whether hardware attestation should be used. - true: Returns Default attestation with challenge verification - false: Returns None attestation (no hardware verification)

challenge

Cryptographic challenge for attestation verification. Required when value is true, ignored when value is false. Should be cryptographically random and provided by the relying party.

See also