瀏覽代碼

refactor: simplify atr check (#252)

Reviewed-on: https://gitea.angry.im/PeterCxy/OpenEUICC/pulls/252
Co-authored-by: septs <github@septs.pw>
Co-committed-by: septs <github@septs.pw>
septs 2 月之前
父節點
當前提交
4d43ab4824
共有 1 個文件被更改,包括 4 次插入13 次删除
  1. 4 13
      app-common/src/main/java/im/angry/openeuicc/util/Vendors.kt

+ 4 - 13
app-common/src/main/java/im/angry/openeuicc/util/Vendors.kt

@@ -23,21 +23,12 @@ interface EuiccVendor {
 private class ESTKme : EuiccVendor {
     companion object {
         private val PRODUCT_AID = "A06573746B6D65FFFFFFFFFFFF6D6774".decodeHex()
-        private val PRODUCT_ATR_FPR = "estk.me".encodeToByteArray()
     }
 
-    private fun checkAtr(channel: EuiccChannel): Boolean {
-        val iface = channel.apduInterface
-        if (iface !is ApduInterfaceAtrProvider) return false
-        val atr = iface.atr ?: return false
-        for (index in atr.indices) {
-            if (atr.size - index < PRODUCT_ATR_FPR.size) break
-            if (atr.sliceArray(index until index + PRODUCT_ATR_FPR.size)
-                    .contentEquals(PRODUCT_ATR_FPR)
-            ) return true
-        }
-        return false
-    }
+    private fun checkAtr(channel: EuiccChannel): Boolean =
+        (channel.apduInterface as? ApduInterfaceAtrProvider)
+            ?.atr?.decodeToString()?.contains("estk.me")
+            ?: false
 
     private fun decodeAsn1String(b: ByteArray): String? {
         if (b.size < 2) return null