Skip to content

Commit

Permalink
[BWA-61] Fix pre-existing detekt issues (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintPatrck authored Sep 3, 2024
1 parent 5758b34 commit e90c41a
Show file tree
Hide file tree
Showing 83 changed files with 656 additions and 789 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ dependencies {
}

detekt {
autoCorrect = true
config.from(files("$rootDir/detekt-config.yml"))
baseline = file("$rootDir/detekt-baseline.xml")
}

kover {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.bitwarden.authenticator.data.platform.manager.CrashLogsManager
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject

/**
* Custom application class.
*/
@HiltAndroidApp
class AuthenticatorApplication : Application() {
// Inject classes here that must be triggered on startup but are not otherwise consumed by
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/kotlin/com/bitwarden/authenticator/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

/**
* Primary entry point for the application.
*/
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

Expand All @@ -33,20 +36,20 @@ class MainActivity : AppCompatActivity() {
if (savedInstanceState == null) {
mainViewModel.trySendAction(
MainAction.ReceiveFirstIntent(
intent = intent
)
intent = intent,
),
)
}

setContent {
val state by mainViewModel.stateFlow.collectAsStateWithLifecycle()

AuthenticatorTheme(
theme = state.theme
theme = state.theme,
) {
RootNavScreen(
onSplashScreenRemoved = { shouldShowSplashScreen = false },
onExitApplication = { finishAffinity() }
onExitApplication = { finishAffinity() },
)
}
}
Expand All @@ -56,7 +59,7 @@ class MainActivity : AppCompatActivity() {
super.onNewIntent(intent)
sanitizeIntent()
mainViewModel.trySendAction(
MainAction.ReceiveNewIntent(intent = intent)
MainAction.ReceiveNewIntent(intent = intent),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class MainViewModel @Inject constructor(
settingsRepository: SettingsRepository,
) : BaseViewModel<MainState, MainEvent, MainAction>(
MainState(
theme = settingsRepository.appTheme
)
theme = settingsRepository.appTheme,
),
) {

init {
Expand Down Expand Up @@ -71,7 +71,6 @@ class MainViewModel @Inject constructor(
) {
// RFU
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import android.os.SystemClock
import com.bitwarden.authenticator.data.auth.datasource.disk.AuthDiskSource
import javax.inject.Inject

/**
* Default implementation of [AuthRepository].
*/
class AuthRepositoryImpl @Inject constructor(
private val authDiskSource: AuthDiskSource,
private val elapsedRealtimeMillisProvider: () -> Long = { SystemClock.elapsedRealtime() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ object AuthRepositoryModule {
fun provideAuthRepository(
authDiskSource: AuthDiskSource,
): AuthRepository = AuthRepositoryImpl(
authDiskSource = authDiskSource
authDiskSource = authDiskSource,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ interface AuthenticatorDiskSource {
* Deletes an authenticator item from the data source with the given [itemId].
*/
suspend fun deleteItem(itemId: String)

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.merge
import javax.inject.Inject

/**
* Default implementation of [AuthenticatorDiskSource].
*/
class AuthenticatorDiskSourceImpl @Inject constructor(
private val itemDao: ItemDao,
) : AuthenticatorDiskSource {
Expand All @@ -19,7 +22,7 @@ class AuthenticatorDiskSourceImpl @Inject constructor(

override fun getItems(): Flow<List<AuthenticatorItemEntity>> = merge(
forceItemsFlow,
itemDao.getAllItems()
itemDao.getAllItems(),
)

override suspend fun deleteItem(itemId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.bitwarden.authenticator.data.authenticator.datasource.disk.entity.Aut
*/
@Database(
entities = [
AuthenticatorItemEntity::class
AuthenticatorItemEntity::class,
],
autoMigrations = [
AutoMigration(from = 1, to = 2),
Expand All @@ -32,5 +32,4 @@ abstract class AuthenticatorDatabase : RoomDatabase() {
* Provide the DAO for accessing authenticator item data.
*/
abstract fun itemDao(): ItemDao

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object AuthenticatorDiskModule {
.databaseBuilder(
context = app,
klass = AuthenticatorDatabase::class.java,
name = "authenticator_database"
name = "authenticator_database",
)
.fallbackToDestructiveMigration()
.addTypeConverter(AuthenticatorItemTypeConverter())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ enum class AuthenticatorItemAlgorithm {
;

companion object {
/**
* Returns a [AuthenticatorItemAlgorithm] with a name matching [value], or null.
*/
fun fromStringOrNull(value: String): AuthenticatorItemAlgorithm? =
entries.find { it.name.equals(value, ignoreCase = true) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ data class AuthenticatorItemEntity(
@ColumnInfo(name = "favorite", defaultValue = "0")
val favorite: Boolean,
) {
/**
* Returns the OTP data in a string formatted to match the Google Authenticator specification,
* https://github.com/google/google-authenticator/wiki/Key-Uri-Format
*/
fun toOtpAuthUriString(): String {
return when (type) {
AuthenticatorItemType.TOTP -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bitwarden.authenticator.data.authenticator.datasource.disk.entity

/**
* Enum representing the main type options for authenticator items.
* Enum representing the supported "type" options for authenticator items.
*/
enum class AuthenticatorItemType {

Expand All @@ -17,6 +17,10 @@ enum class AuthenticatorItemType {
;

companion object {

/**
* Returns the [AuthenticatorItemType] matching [value], or null.
*/
fun fromStringOrNull(value: String): AuthenticatorItemType? =
entries.find { it.name.equals(value, ignoreCase = true) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ interface AuthenticatorSdkSource {
time: DateTime,
): Result<TotpResponse>

/**
* Generate a random key for seeding biometrics.
*/
suspend fun generateBiometricsKey(): Result<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import com.bitwarden.generators.PasswordGeneratorRequest
import com.bitwarden.sdk.Client
import javax.inject.Inject

/**
* Default implementation of [AuthenticatorSdkSource].
*/
class AuthenticatorSdkSourceImpl @Inject constructor(
private val sdkClientManager: SdkClientManager,
) : AuthenticatorSdkSource {
Expand Down Expand Up @@ -38,11 +41,10 @@ class AuthenticatorSdkSourceImpl @Inject constructor(
minLowercase = null,
minUppercase = null,
minNumber = null,
minSpecial = null
)
minSpecial = null,
),
)
}

private suspend fun getClient(): Client = sdkClientManager.getOrCreateClient()

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ object AuthenticatorSdkModule {
fun provideAuthenticatorSdkSource(
sdkClientManager: SdkClientManager,
): AuthenticatorSdkSource = AuthenticatorSdkSourceImpl(sdkClientManager)

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import java.io.ByteArrayOutputStream
*/
private const val BUFFER_SIZE: Int = 1024

/**
* Manages reading and writing files.
*/
class FileManagerImpl(
private val context: Context,
private val dispatcherManager: DispatcherManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ interface TotpCodeManager {
const val STEAM_CODE_PREFIX = "steam://"
const val GOOGLE_EXPORT_PREFIX = "otpauth-migration://"
const val TOTP_DIGITS_DEFAULT = 6
const val TOTP_DIGITS_MIN = 5
const val TOTP_DIGITS_MAX = 10
const val STEAM_DIGITS_DEFAULT = 5
const val PERIOD_SECONDS_DEFAULT = 30
val TOTP_DIGITS_RANGE = TOTP_DIGITS_MIN..TOTP_DIGITS_MAX
val ALGORITHM_DEFAULT = AuthenticatorItemAlgorithm.SHA1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object AuthenticatorManagerModule {
fun providerFileManager(
@ApplicationContext context: Context,
dispatcherManager: DispatcherManager,
) : FileManager = FileManagerImpl(
): FileManager = FileManagerImpl(
context = context,
dispatcherManager = dispatcherManager,
)
Expand All @@ -41,7 +41,6 @@ object AuthenticatorManagerModule {
): TotpCodeManager = TotpCodeManagerImpl(
authenticatorSdkSource = authenticatorSdkSource,
dispatcherManager = dispatcherManager,
clock = clock
clock = clock,
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import com.bitwarden.authenticator.data.authenticator.repository.model.CreateIte
import com.bitwarden.authenticator.data.authenticator.repository.model.DeleteItemResult
import com.bitwarden.authenticator.data.authenticator.repository.model.ExportDataResult
import com.bitwarden.authenticator.data.authenticator.repository.model.TotpCodeResult
import com.bitwarden.authenticator.data.authenticator.repository.model.UpdateItemRequest
import com.bitwarden.authenticator.data.authenticator.repository.model.UpdateItemResult
import com.bitwarden.authenticator.data.platform.manager.imports.model.ImportDataResult
import com.bitwarden.authenticator.data.platform.manager.imports.model.ImportFileFormat
import com.bitwarden.authenticator.data.platform.repository.model.DataState
import com.bitwarden.authenticator.ui.platform.feature.settings.export.model.ExportFormat
import com.bitwarden.authenticator.ui.platform.feature.settings.export.model.ExportVaultFormat
import com.bitwarden.authenticator.ui.platform.manager.intent.IntentManager
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
Expand Down Expand Up @@ -82,18 +80,10 @@ interface AuthenticatorRepository {
*/
suspend fun hardDeleteItem(itemId: String): DeleteItemResult

/**
* Attempt to update a cipher.
*/
suspend fun updateItem(
itemId: String,
updateItemRequest: UpdateItemRequest,
): UpdateItemResult

/**
* Attempt to get the user's data for export.
*/
suspend fun exportVaultData(format: ExportFormat, fileUri: Uri): ExportDataResult
suspend fun exportVaultData(format: ExportVaultFormat, fileUri: Uri): ExportDataResult

/**
* Attempt to read the user's data from a file
Expand Down
Loading

0 comments on commit e90c41a

Please sign in to comment.