Skip to content

Commit 830f74a

Browse files
committed
Resolve all Kotlin warnings
1 parent 2f649b1 commit 830f74a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

android/rustls-platform-verifier/src/main/java/org/rustls/platformverifier/CertificateVerifier.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.rustls.platformverifier
22

3+
import android.annotation.SuppressLint
34
import android.content.Context
45
import android.net.http.X509TrustManagerExtensions
56
import android.os.Build
@@ -53,6 +54,8 @@ private class VerificationResult(
5354
// Only JNI and test code calls this, so unused code warnings are suppressed.
5455
// Internal for test code - no other Kotlin code should use this object directly.
5556
@Suppress("unused")
57+
// We want to show a difference between Kotlin-side logs and those in Rust code
58+
@SuppressLint("LongLogTag")
5659
internal object CertificateVerifier {
5760
private const val TAG = "rustls-platform-verifier-android"
5861

@@ -161,7 +164,7 @@ internal object CertificateVerifier {
161164

162165
@get:Synchronized
163166
private var systemCertificateDirectory: File? = System.getenv("ANDROID_ROOT")?.let { rootPath ->
164-
File(rootPath + "/etc/security/cacerts")
167+
File("$rootPath/etc/security/cacerts")
165168
}
166169

167170
@get:Synchronized
@@ -196,7 +199,7 @@ internal object CertificateVerifier {
196199
certificateChain.add(certificate as X509Certificate)
197200
}
198201

199-
// Will never throw `ArrayIndexOutOfBoundsException` because `rustls`'s `ServerCertVerifer` trait
202+
// Will never throw `ArrayIndexOutOfBoundsException` because `rustls`'s `ServerCertVerifier` trait
200203
// has a mandatory `end_entity` parameter in `verify_server_cert`.
201204
val endEntity = certificateChain[0]
202205

@@ -251,7 +254,7 @@ internal object CertificateVerifier {
251254
}
252255

253256
// TEST ONLY: Mock test suite cannot attempt to check revocation status if no OSCP data has been stapled,
254-
// because Andriod requires certificates to an specify OCSP responder for network fetch in this case.
257+
// because Android requires certificates to an specify OCSP responder for network fetch in this case.
255258
// If in testing w/o OCSP stapled, short-circuit here - only prior checks apply.
256259
if ((mockKeystore.size() != 0) && (ocspResponse == null)) {
257260
return VerificationResult(StatusCode.Ok)
@@ -283,7 +286,7 @@ internal object CertificateVerifier {
283286
// 1. Known root + OSCP stapled -> Full-chain revocation, no extra network use
284287
// 2. Known root + no OSCP stapled -> Full-chain revocation, with extra network use
285288
// 3. Unknown root + OSCP stapled -> End-entity-only revocation, no extra network use
286-
// 4. Uknown root + no OSCP stapled -> End-entity-only revocation, with extra network use
289+
// 4. Unknown root + no OSCP stapled -> End-entity-only revocation, with extra network use
287290
val parameters = PKIXBuilderParameters(keystore, null)
288291

289292
val validator = CertPathValidator.getInstance("PKIX")
@@ -360,7 +363,7 @@ internal object CertificateVerifier {
360363
private fun hashPrincipal(principal: X500Principal): String {
361364
val hexDigits = "0123456789abcdef".toCharArray()
362365
val digest = MessageDigest.getInstance("MD5").digest(principal.encoded)
363-
var hexChars = CharArray(8)
366+
val hexChars = CharArray(8)
364367

365368
for (i in 0..3) {
366369
// Kotlin doesn't support bitwise operators for bytes, only Int and Long.
@@ -393,25 +396,25 @@ internal object CertificateVerifier {
393396
val hash = hashPrincipal(root.subjectX500Principal)
394397
var i = 0
395398
while (true) {
396-
val alias = hash + '.' + i
399+
val alias = "$hash.$i"
397400

398401
if (!File(loadedSystemCertificateDirectory, alias).exists()) {
399402
break
400403
}
401404

402-
val anchor = loadedSystemKeystore.getCertificate("system:" + alias)
405+
val anchor = loadedSystemKeystore.getCertificate("system:$alias")
403406

404407
// It's possible for `anchor` to be `null` if the user deleted a trust anchor.
405408
// Continue iterating as there may be further collisions after the deleted anchor.
406409
if (anchor == null) {
407410
continue
408411
// This should never happen
409412
} else if (anchor !is X509Certificate) {
410-
// SAFETY: This logs a unique identifer (hash value) only in cases where a file within the
413+
// SAFETY: This logs a unique identifier (hash value) only in cases where a file within the
411414
// system's root trust store is not a valid X509 certificate (extremely unlikely error).
412415
// The hash doesn't tell us any sensitive information about the invalid cert or reveal any of
413416
// its contents - it just lets us ID the bad file if a customer is having TLS failure issues.
414-
Log.e(TAG, "anchor is not a certificate, alias: " + alias)
417+
Log.e(TAG, "anchor is not a certificate, alias: $alias")
415418
continue
416419
// If subject and public key match, it's a system root.
417420
} else {

0 commit comments

Comments
 (0)