-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from Team-B1ND/feature/160-keystore-ios-logic
[KeyStore] iOS Logic
- Loading branch information
Showing
29 changed files
with
488 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// swift-tools-version: 5.7 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Keystore", | ||
platforms: [.iOS(.v14)], | ||
products: [ | ||
.library( | ||
name: "Keystore", | ||
targets: ["Keystore"] | ||
) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ore/src/androidMain/kotlin/com/b1nd/dodam/datastore/repository/DataStoreRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.b1nd.dodam.datastore.repository | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import com.b1nd.dodam.datastore.model.User | ||
import com.b1nd.dodam.keystore.KeyStoreManager | ||
import kotlinx.coroutines.flow.map | ||
|
||
class DataStoreRepositoryImpl constructor( | ||
private val dataStore: DataStore<Preferences>, | ||
private val keyStoreManager: KeyStoreManager, | ||
) : DataStoreRepository { | ||
private val tokenKey = stringPreferencesKey("token") | ||
private val idKey = stringPreferencesKey("id") | ||
private val pwKey = stringPreferencesKey("pw") | ||
|
||
override val user = dataStore.data.map { | ||
User( | ||
id = keyStoreManager.decrypt(it[idKey] ?: ""), | ||
pw = keyStoreManager.decrypt(it[pwKey] ?: ""), | ||
token = it[tokenKey] ?: "", | ||
) | ||
} | ||
|
||
override val token = dataStore.data.map { | ||
it[tokenKey] ?: "" | ||
} | ||
|
||
override suspend fun saveUser(id: String, pw: String, token: String) { | ||
dataStore.edit { | ||
it[idKey] = keyStoreManager.encrypt(id) | ||
it[pwKey] = keyStoreManager.encrypt(pw) | ||
it[tokenKey] = token | ||
} | ||
} | ||
|
||
override suspend fun saveToken(token: String) { | ||
dataStore.edit { | ||
it[tokenKey] = token | ||
} | ||
} | ||
|
||
override suspend fun deleteUser() { | ||
dataStore.edit { | ||
it[idKey] = "" | ||
it[pwKey] = "" | ||
it[tokenKey] = "" | ||
} | ||
} | ||
} |
49 changes: 7 additions & 42 deletions
49
datastore/src/commonMain/kotlin/com/b1nd/dodam/datastore/repository/DatastoreRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,17 @@ | ||
package com.b1nd.dodam.datastore.repository | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import com.b1nd.dodam.datastore.model.User | ||
import com.b1nd.dodam.keystore.KeyStoreManager | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
class DatastoreRepository constructor( | ||
private val dataStore: DataStore<Preferences>, | ||
private val keyStoreManager: KeyStoreManager, | ||
) { | ||
private val tokenKey = stringPreferencesKey("token") | ||
private val idKey = stringPreferencesKey("id") | ||
private val pwKey = stringPreferencesKey("pw") | ||
interface DataStoreRepository { | ||
|
||
val user = dataStore.data.map { | ||
User( | ||
id = keyStoreManager.decrypt(it[idKey] ?: ""), | ||
pw = keyStoreManager.decrypt(it[pwKey] ?: ""), | ||
token = it[tokenKey] ?: "", | ||
) | ||
} | ||
val user: Flow<User> | ||
|
||
val token = dataStore.data.map { | ||
it[tokenKey] ?: "" | ||
} | ||
val token: Flow<String> | ||
|
||
suspend fun saveUser(id: String, pw: String, token: String) { | ||
dataStore.edit { | ||
it[idKey] = keyStoreManager.encrypt(id) | ||
it[pwKey] = keyStoreManager.encrypt(pw) | ||
it[tokenKey] = token | ||
} | ||
} | ||
suspend fun saveUser(id: String, pw: String, token: String) | ||
|
||
suspend fun saveToken(token: String) { | ||
dataStore.edit { | ||
it[tokenKey] = token | ||
} | ||
} | ||
suspend fun saveToken(token: String) | ||
|
||
suspend fun deleteUser() { | ||
dataStore.edit { | ||
it[idKey] = "" | ||
it[pwKey] = "" | ||
it[tokenKey] = "" | ||
} | ||
} | ||
suspend fun deleteUser() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.