Fix lint exception and run ktfmt
Bug: 292103206
Test: make
Change-Id: I0e8d2509cc2343d7167c7e8f9ffbe2cafabc519c
diff --git a/credentials/credentials/src/main/java/androidx/credentials/webauthn/Cbor.kt b/credentials/credentials/src/main/java/androidx/credentials/webauthn/Cbor.kt
index 4c6ae0d..0ef3b6b 100644
--- a/credentials/credentials/src/main/java/androidx/credentials/webauthn/Cbor.kt
+++ b/credentials/credentials/src/main/java/androidx/credentials/webauthn/Cbor.kt
@@ -76,20 +76,22 @@
}
var keysList = ArrayList<ByteArray>(byteMap.keys)
- keysList.sortedWith(Comparator<ByteArray> { a, b ->
- // If two keys have different lengths, the shorter one sorts earlier;
- // If two keys have the same length, the one with the lower value in (byte-wise)
- // lexical order sorts earlier.
- var aBytes = byteMap.get(a)!!
- var bBytes = byteMap.get(b)!!
+ keysList.sortedWith(
+ Comparator<ByteArray> { a, b ->
+ // If two keys have different lengths, the shorter one sorts earlier;
+ // If two keys have the same length, the one with the lower value in (byte-wise)
+ // lexical order sorts earlier.
+ var aBytes = byteMap.get(a)!!
+ var bBytes = byteMap.get(b)!!
when {
- a.size > b.size -> 1
- a.size < b.size -> -1
- aBytes.size > bBytes.size -> 1
- aBytes.size < bBytes.size -> -1
- else -> 0
+ a.size > b.size -> 1
+ a.size < b.size -> -1
+ aBytes.size > bBytes.size -> 1
+ aBytes.size < bBytes.size -> -1
+ else -> 0
}
- })
+ }
+ )
for (key in keysList) {
ret += key
diff --git a/credentials/credentials/src/main/java/androidx/credentials/webauthn/Util.kt b/credentials/credentials/src/main/java/androidx/credentials/webauthn/WebAuthnUtils.kt
similarity index 78%
rename from credentials/credentials/src/main/java/androidx/credentials/webauthn/Util.kt
rename to credentials/credentials/src/main/java/androidx/credentials/webauthn/WebAuthnUtils.kt
index f247a9c..b93398e 100644
--- a/credentials/credentials/src/main/java/androidx/credentials/webauthn/Util.kt
+++ b/credentials/credentials/src/main/java/androidx/credentials/webauthn/WebAuthnUtils.kt
@@ -16,12 +16,10 @@
package androidx.credentials.webauthn
-import android.annotation.SuppressLint
import android.os.Build
import android.util.Base64
import androidx.annotation.RestrictTo
import androidx.credentials.provider.CallingAppInfo
-import java.security.MessageDigest
@RestrictTo(RestrictTo.Scope.LIBRARY)
internal class WebAuthnUtils {
@@ -34,13 +32,9 @@
return Base64.encodeToString(data, Base64.NO_PADDING or Base64.NO_WRAP or Base64.URL_SAFE)
}
- @SuppressLint("ClassVerificationFailure")
fun appInfoToOrigin(info: CallingAppInfo): String {
if (Build.VERSION.SDK_INT >= 28) {
- val cert = info.signingInfo.apkContentsSigners[0].toByteArray()
- val md = MessageDigest.getInstance("SHA-256")
- val certHash = md.digest(cert)
- return "android:apk-key-hash:${b64Encode(certHash)}"
+ return WebAuthnUtilsApi28.appInfoToOrigin(info)
}
return ""
}
diff --git a/credentials/credentials/src/main/java/androidx/credentials/webauthn/WebAuthnUtilsApi28.kt b/credentials/credentials/src/main/java/androidx/credentials/webauthn/WebAuthnUtilsApi28.kt
new file mode 100644
index 0000000..32748e0
--- /dev/null
+++ b/credentials/credentials/src/main/java/androidx/credentials/webauthn/WebAuthnUtilsApi28.kt
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.credentials.webauthn
+
+import androidx.annotation.RequiresApi
+import androidx.annotation.RestrictTo
+import androidx.credentials.provider.CallingAppInfo
+import java.security.MessageDigest
+
+@RestrictTo(RestrictTo.Scope.LIBRARY)
+@RequiresApi(28)
+internal class WebAuthnUtilsApi28 {
+ companion object {
+ fun appInfoToOrigin(info: CallingAppInfo): String {
+ val cert = info.signingInfo.apkContentsSigners[0].toByteArray()
+ val md = MessageDigest.getInstance("SHA-256")
+ val certHash = md.digest(cert)
+ return "android:apk-key-hash:${WebAuthnUtils.b64Encode(certHash)}"
+ }
+ }
+}