mirror of
https://github.com/bitwarden/android.git
synced 2026-04-28 03:48:14 -05:00
[PM-19866] Migrate BaseEncryptedDiskSource to data module (#4991)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.bitwarden.data.datasource.disk
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import androidx.security.crypto.EncryptedSharedPreferences
|
||||
|
||||
/**
|
||||
* Base class for simplifying interactions with [SharedPreferences] and
|
||||
* [EncryptedSharedPreferences].
|
||||
*/
|
||||
@Suppress("UnnecessaryAbstractClass")
|
||||
abstract class BaseEncryptedDiskSource(
|
||||
sharedPreferences: SharedPreferences,
|
||||
private val encryptedSharedPreferences: SharedPreferences,
|
||||
) : BaseDiskSource(
|
||||
sharedPreferences = sharedPreferences,
|
||||
) {
|
||||
protected fun getEncryptedString(
|
||||
key: String,
|
||||
default: String? = null,
|
||||
): String? = encryptedSharedPreferences.getString(key.withBase(), default)
|
||||
|
||||
protected fun putEncryptedString(
|
||||
key: String,
|
||||
value: String?,
|
||||
): Unit = encryptedSharedPreferences.edit { putString(key.withBase(), value) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for prepending the key with the appropriate base storage key.
|
||||
*/
|
||||
private fun String.withBase(): String = "bwSecureStorage:$this"
|
||||
Reference in New Issue
Block a user