generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Users can export unencrypted data to JSON or CSV (#41)
- Loading branch information
1 parent
066d5c5
commit 66d834c
Showing
31 changed files
with
894 additions
and
145 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
app/src/main/kotlin/com/bitwarden/authenticator/data/authenticator/manager/FileManager.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,14 @@ | ||
package com.bitwarden.authenticator.data.authenticator.manager | ||
|
||
import android.net.Uri | ||
|
||
/** | ||
* Manages reading and writing files. | ||
*/ | ||
interface FileManager { | ||
|
||
/** | ||
* Writes the given [dataString] to disk at the provided [fileUri] | ||
*/ | ||
suspend fun stringToUri(fileUri: Uri, dataString: String): Boolean | ||
} |
29 changes: 29 additions & 0 deletions
29
...src/main/kotlin/com/bitwarden/authenticator/data/authenticator/manager/FileManagerImpl.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,29 @@ | ||
package com.bitwarden.authenticator.data.authenticator.manager | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import com.bitwarden.authenticator.data.platform.manager.DispatcherManager | ||
import kotlinx.coroutines.withContext | ||
|
||
class FileManagerImpl( | ||
private val context: Context, | ||
private val dispatcherManager: DispatcherManager, | ||
) : FileManager { | ||
|
||
override suspend fun stringToUri(fileUri: Uri, dataString: String): Boolean { | ||
@Suppress("TooGenericExceptionCaught") | ||
return try { | ||
withContext(dispatcherManager.io) { | ||
context | ||
.contentResolver | ||
.openOutputStream(fileUri) | ||
?.use { outputStream -> | ||
outputStream.write(dataString.toByteArray()) | ||
} | ||
} | ||
true | ||
} catch (exception: RuntimeException) { | ||
false | ||
} | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
...ain/kotlin/com/bitwarden/authenticator/data/authenticator/manager/model/ExportJsonData.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,51 @@ | ||
package com.bitwarden.authenticator.data.authenticator.manager.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Models exported authenticator data in JSON format. | ||
* | ||
* This model is loosely based off of Bitwarden's exported unencrypted vault data. | ||
*/ | ||
@Serializable | ||
data class ExportJsonData( | ||
val encrypted: Boolean, | ||
val items: List<ExportItem>, | ||
) { | ||
|
||
/** | ||
* Represents a single exported authenticator item. | ||
* | ||
* This model is loosely based off of Bitwarden's exported Cipher JSON. | ||
*/ | ||
@Serializable | ||
data class ExportItem( | ||
val id: String, | ||
val name: String, | ||
val folderId: String?, | ||
val organizationId: String?, | ||
val collectionIds: List<String>?, | ||
val notes: String?, | ||
val type: Int, | ||
val login: ItemLoginData, | ||
val favorite: Boolean, | ||
) { | ||
/** | ||
* Represents the login specific data of an exported item. | ||
* | ||
* This model is loosely based off of Bitwarden's Cipher.Login JSON. | ||
* | ||
* @property totp OTP secret used to generate a verification code. | ||
* @property issuer Optional issuer of the 2fa code. | ||
* @property period Optional refresh period in seconds. Default is 30. | ||
* @property digits Optional number of digits in the verification code. Default is 6 | ||
*/ | ||
@Serializable | ||
data class ItemLoginData( | ||
val totp: String, | ||
val issuer: String?, | ||
val period: Int, | ||
val digits: Int, | ||
) | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
...otlin/com/bitwarden/authenticator/data/authenticator/repository/model/ExportDataResult.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,12 @@ | ||
package com.bitwarden.authenticator.data.authenticator.repository.model | ||
|
||
/** | ||
* Represents the result of a data export operation. | ||
*/ | ||
sealed class ExportDataResult { | ||
|
||
data object Success : ExportDataResult() | ||
|
||
data object Error : ExportDataResult() | ||
|
||
} |
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
Oops, something went wrong.