Skip to content

Commit

Permalink
kotlinizing branch convert-identity-to-kotlin
Browse files Browse the repository at this point in the history
Signed-off-by: dritan-x <[email protected]>
  • Loading branch information
dritan-x authored and davidz25 committed Feb 13, 2024
1 parent 311b313 commit 8c85092
Show file tree
Hide file tree
Showing 26 changed files with 495 additions and 784 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Parcelable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import com.android.identity.securearea.EcCurve
import com.android.identity.securearea.SecureArea
import kotlinx.parcelize.Parcelize

@Stable
Expand All @@ -22,10 +21,7 @@ data class SettingsScreenState(
val debugEnabled: Boolean = true
) {

fun isBleEnabled(): Boolean {
return isBleDataRetrievalEnabled
|| isBlePeripheralModeEnabled
}
fun isBleEnabled(): Boolean = isBleDataRetrievalEnabled || isBlePeripheralModeEnabled

fun canToggleBleDataRetrievalMode(newBleCentralMode: Boolean): Boolean {
val updatedState = copy(isBleDataRetrievalEnabled = newBleCentralMode)
Expand All @@ -47,12 +43,11 @@ data class SettingsScreenState(
return updatedState.hasDataRetrieval()
}

private fun hasDataRetrieval(): Boolean {
return isBleDataRetrievalEnabled
private fun hasDataRetrieval(): Boolean =
isBleDataRetrievalEnabled
|| isBlePeripheralModeEnabled
|| wifiAwareEnabled
|| nfcEnabled
}

@Parcelize
enum class SessionEncryptionCurveOption : Parcelable {
Expand All @@ -66,9 +61,8 @@ data class SettingsScreenState(
X25519,
X448;

fun toEcCurve(): EcCurve {

return when (this) {
fun toEcCurve(): EcCurve =
when (this) {
P256 -> EcCurve.P256
P384 -> EcCurve.P384
P521 -> EcCurve.P521
Expand All @@ -79,11 +73,10 @@ data class SettingsScreenState(
X25519 -> EcCurve.X25519
X448 -> EcCurve.X448
}
}

companion object {
fun fromEcCurve(curve: EcCurve): SessionEncryptionCurveOption {
return when (curve) {
fun fromEcCurve(curve: EcCurve): SessionEncryptionCurveOption =
when (curve) {
EcCurve.P256 -> P256
EcCurve.P384 -> P384
EcCurve.P521 -> P521
Expand All @@ -95,7 +88,6 @@ data class SettingsScreenState(
EcCurve.X448 -> X448
else -> throw IllegalStateException("Unknown EcCurve")
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.android.identity.wallet.support

import com.android.identity.securearea.KeyPurpose
import com.android.identity.securearea.SecureArea
import com.android.identity.wallet.composables.state.MdocAuthStateOption

fun MdocAuthStateOption.toKeyPurpose(): KeyPurpose {
return if (this == MdocAuthStateOption.ECDSA) {
fun MdocAuthStateOption.toKeyPurpose(): KeyPurpose =
if (this == MdocAuthStateOption.ECDSA) {
KeyPurpose.SIGN
} else {
KeyPurpose.AGREE_KEY
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,15 @@ class SecureAreaSupportNull : SecureAreaSupport {
throw IllegalStateException("No implementation")
}

override fun getSecureAreaSupportState(): SecureAreaSupportState {
return state
}

override fun createAuthKeySettingsConfiguration(secureAreaSupportState: SecureAreaSupportState): ByteArray {
return ByteArray(0)
}
override fun getSecureAreaSupportState(): SecureAreaSupportState = state

override fun createAuthKeySettingsConfiguration(secureAreaSupportState: SecureAreaSupportState): ByteArray =
ByteArray(0)

override fun createAuthKeySettingsFromConfiguration(
encodedConfiguration: ByteArray,
challenge: ByteArray,
validFrom: Timestamp,
validUntil: Timestamp
): CreateKeySettings {
return CreateKeySettings(challenge)
}

): CreateKeySettings = CreateKeySettings(challenge)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import kotlinx.parcelize.Parcelize
enum class AndroidAuthKeyCurveOption : Parcelable {
P_256, Ed25519, X25519;

fun toEcCurve(): EcCurve {
return when (this) {
fun toEcCurve(): EcCurve =
when (this) {
P_256 -> EcCurve.P256
Ed25519 -> EcCurve.ED25519
X25519 -> EcCurve.X25519
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ enum class SoftwareAuthKeyCurveOption : Parcelable {
X25519,
X448;

fun toEcCurve(): EcCurve {
return when (this) {
fun toEcCurve(): EcCurve =
when (this) {
P256 -> EcCurve.P256
P384 -> EcCurve.P384
P521 -> EcCurve.P521
Expand All @@ -33,5 +33,4 @@ enum class SoftwareAuthKeyCurveOption : Parcelable {
X25519 -> EcCurve.X25519
X448 -> EcCurve.X448
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.SharedPreferences
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import com.android.identity.securearea.EcCurve
import com.android.identity.securearea.SecureArea
import com.android.identity.util.Logger
import java.io.File

Expand Down Expand Up @@ -38,84 +37,70 @@ object PreferencesHelper {
return storageDir;
}

fun isBleDataRetrievalEnabled(): Boolean {
return sharedPreferences.getBoolean(BLE_DATA_RETRIEVAL, true)
}
fun isBleDataRetrievalEnabled(): Boolean =
sharedPreferences.getBoolean(BLE_DATA_RETRIEVAL, true)

fun setBleDataRetrievalEnabled(enabled: Boolean) {
fun setBleDataRetrievalEnabled(enabled: Boolean) =
sharedPreferences.edit { putBoolean(BLE_DATA_RETRIEVAL, enabled) }
}

fun isBleDataRetrievalPeripheralModeEnabled(): Boolean {
return sharedPreferences.getBoolean(BLE_DATA_RETRIEVAL_PERIPHERAL_MODE, false)
}
fun isBleDataRetrievalPeripheralModeEnabled(): Boolean =
sharedPreferences.getBoolean(BLE_DATA_RETRIEVAL_PERIPHERAL_MODE, false)

fun setBlePeripheralDataRetrievalMode(enabled: Boolean) {
fun setBlePeripheralDataRetrievalMode(enabled: Boolean) =
sharedPreferences.edit { putBoolean(BLE_DATA_RETRIEVAL_PERIPHERAL_MODE, enabled) }
}

fun isBleL2capEnabled(): Boolean {
return sharedPreferences.getBoolean(BLE_DATA_L2CAP, false)
}
fun isBleL2capEnabled(): Boolean =
sharedPreferences.getBoolean(BLE_DATA_L2CAP, false)

fun setBleL2CAPEnabled(enabled: Boolean) {
fun setBleL2CAPEnabled(enabled: Boolean) =
sharedPreferences.edit { putBoolean(BLE_DATA_L2CAP, enabled) }
}

fun isBleClearCacheEnabled(): Boolean {
return sharedPreferences.getBoolean(BLE_CLEAR_CACHE, false)
}
fun isBleClearCacheEnabled(): Boolean =
sharedPreferences.getBoolean(BLE_CLEAR_CACHE, false)

fun setBleClearCacheEnabled(enabled: Boolean) {
fun setBleClearCacheEnabled(enabled: Boolean) =
sharedPreferences.edit { putBoolean(BLE_CLEAR_CACHE, enabled) }
}

fun isWifiDataRetrievalEnabled(): Boolean {
return sharedPreferences.getBoolean(WIFI_DATA_RETRIEVAL, false)
}
fun isWifiDataRetrievalEnabled(): Boolean =
sharedPreferences.getBoolean(WIFI_DATA_RETRIEVAL, false)

fun setWifiDataRetrievalEnabled(enabled: Boolean) {
fun setWifiDataRetrievalEnabled(enabled: Boolean) =
sharedPreferences.edit { putBoolean(WIFI_DATA_RETRIEVAL, enabled) }
}

fun isNfcDataRetrievalEnabled(): Boolean {
return sharedPreferences.getBoolean(NFC_DATA_RETRIEVAL, false)
}
fun isNfcDataRetrievalEnabled(): Boolean =
sharedPreferences.getBoolean(NFC_DATA_RETRIEVAL, false)

fun setNfcDataRetrievalEnabled(enabled: Boolean) {
fun setNfcDataRetrievalEnabled(enabled: Boolean) =
sharedPreferences.edit { putBoolean(NFC_DATA_RETRIEVAL, enabled) }
}

fun isConnectionAutoCloseEnabled(): Boolean {
return sharedPreferences.getBoolean(CONNECTION_AUTO_CLOSE, true)
}
fun isConnectionAutoCloseEnabled(): Boolean =
sharedPreferences.getBoolean(CONNECTION_AUTO_CLOSE, true)

fun setConnectionAutoCloseEnabled(enabled: Boolean) {
fun setConnectionAutoCloseEnabled(enabled: Boolean) =
sharedPreferences.edit { putBoolean(CONNECTION_AUTO_CLOSE, enabled) }
}

fun shouldUseStaticHandover(): Boolean {
return sharedPreferences.getBoolean(STATIC_HANDOVER, false)
}
fun shouldUseStaticHandover(): Boolean =
sharedPreferences.getBoolean(STATIC_HANDOVER, false)

fun setUseStaticHandover(enabled: Boolean) {
fun setUseStaticHandover(enabled: Boolean) =
sharedPreferences.edit { putBoolean(STATIC_HANDOVER, enabled) }
}

fun isDebugLoggingEnabled(): Boolean {
return sharedPreferences.getBoolean(DEBUG_LOG, true)
}
fun isDebugLoggingEnabled(): Boolean =
sharedPreferences.getBoolean(DEBUG_LOG, true)

fun setDebugLoggingEnabled(enabled: Boolean) {
sharedPreferences.edit { putBoolean(DEBUG_LOG, enabled) }
Logger.isDebugEnabled = enabled
}
fun setDebugLoggingEnabled(enabled: Boolean) =
sharedPreferences
.edit { putBoolean(DEBUG_LOG, enabled) }
.also { Logger.isDebugEnabled = enabled }

fun getEphemeralKeyCurveOption(): EcCurve {
return EcCurve.fromInt(sharedPreferences.getInt(EPHEMERAL_KEY_CURVE_OPTION, EcCurve.P256.coseCurveIdentifier))
}
fun getEphemeralKeyCurveOption(): EcCurve =
EcCurve.fromInt(
sharedPreferences.getInt(
EPHEMERAL_KEY_CURVE_OPTION,
EcCurve.P256.coseCurveIdentifier
)
)

fun setEphemeralKeyCurveOption(newValue: EcCurve) {
fun setEphemeralKeyCurveOption(newValue: EcCurve) =
sharedPreferences.edit { putInt(EPHEMERAL_KEY_CURVE_OPTION, newValue.coseCurveIdentifier) }
}
}
1 change: 1 addition & 0 deletions appverifier/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ dependencies {
implementation libs.bundles.compose
implementation libs.cbor
implementation libs.code.scanner
implementation libs.identity.credential

androidTestImplementation libs.bundles.ui.testing

Expand Down
Loading

0 comments on commit 8c85092

Please sign in to comment.