Skip to content

Commit 3cc513a

Browse files
agxpcopybara-github
authored andcommitted
Add @immutable annotations to VerificationResult and its subclasses.
This change marks the VerificationResult sealed interface and all its concrete data classes as immutable. Suppressions are added for types like PublicKey and Exception, which are effectively immutable for the purposes of this class but not formally annotated as such. PiperOrigin-RevId: 855770774
1 parent 851433e commit 3cc513a

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

src/main/kotlin/Verifier.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.android.keyattestation.verifier.provider.ProvisioningMethod
2323
import com.android.keyattestation.verifier.provider.RevocationChecker
2424
import com.google.common.collect.ImmutableList
2525
import com.google.common.util.concurrent.ListenableFuture
26+
import com.google.errorprone.annotations.Immutable
2627
import com.google.errorprone.annotations.ThreadSafe
2728
import com.google.protobuf.ByteString
2829
import com.google.protobuf.kotlin.toByteString
@@ -42,8 +43,13 @@ import kotlinx.coroutines.guava.future
4243
import kotlinx.coroutines.runBlocking
4344

4445
/** The result of verifying an Android Key Attestation certificate chain. */
46+
@Immutable
4547
sealed interface VerificationResult {
48+
@Immutable
4649
data class Success(
50+
@SuppressWarnings(
51+
"Immutable"
52+
) // PublicKey implementations are immutable but not marked as such.
4753
val publicKey: PublicKey,
4854
val challenge: ByteString,
4955
val securityLevel: SecurityLevel,
@@ -52,18 +58,31 @@ sealed interface VerificationResult {
5258
val attestedDeviceIds: DeviceIdentity,
5359
) : VerificationResult
5460

55-
data object ChallengeMismatch : VerificationResult
61+
@Immutable data object ChallengeMismatch : VerificationResult
5662

57-
data class PathValidationFailure(val cause: CertPathValidatorException) : VerificationResult
63+
@Immutable
64+
data class PathValidationFailure(
65+
@SuppressWarnings("Immutable") // Exceptions are not deeply immutable.
66+
val cause: CertPathValidatorException
67+
) : VerificationResult
5868

59-
data class ChainParsingFailure(val cause: Exception) : VerificationResult
69+
@Immutable
70+
data class ChainParsingFailure(
71+
@SuppressWarnings("Immutable") // Exceptions are not deeply immutable.
72+
val cause: Exception
73+
) : VerificationResult
6074

61-
data class ExtensionParsingFailure(val cause: ExtensionParsingException) : VerificationResult
75+
@Immutable
76+
data class ExtensionParsingFailure(
77+
@SuppressWarnings("Immutable") // Exceptions are not deeply immutable.
78+
val cause: ExtensionParsingException
79+
) : VerificationResult
6280

81+
@Immutable
6382
data class ExtensionConstraintViolation(val cause: String, val reason: KeyAttestationReason) :
6483
VerificationResult
6584

66-
data object SoftwareAttestationUnsupported : VerificationResult
85+
@Immutable data object SoftwareAttestationUnsupported : VerificationResult
6786
}
6887

6988
/**

0 commit comments

Comments
 (0)