-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
39 changed files
with
2,019 additions
and
376 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
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/xinto/mauth/core/camera/ZxingEncoder.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,44 @@ | ||
package com.xinto.mauth.core.camera | ||
|
||
import android.graphics.Bitmap | ||
import androidx.annotation.ColorInt | ||
import com.google.zxing.BarcodeFormat | ||
import com.google.zxing.EncodeHintType | ||
import com.google.zxing.MultiFormatWriter | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import kotlin.coroutines.resume | ||
import kotlin.coroutines.suspendCoroutine | ||
|
||
object ZxingEncoder { | ||
|
||
private val writer = MultiFormatWriter() | ||
|
||
suspend fun encodeToBitmap( | ||
data: String, | ||
size: Int, | ||
@ColorInt backgroundColor: Int, | ||
@ColorInt dataColor: Int | ||
): Bitmap { | ||
return withContext(Dispatchers.IO){ | ||
suspendCoroutine { continuation -> | ||
val bitMatrix = writer.encode( | ||
/* contents = */ data, | ||
/* format = */ BarcodeFormat.QR_CODE, | ||
/* width = */ size, | ||
/* height = */ size, | ||
/* hints = */ mapOf(EncodeHintType.MARGIN to 2) | ||
) | ||
val bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888).apply { | ||
for (x in 0 until size) { | ||
for (y in 0 until size) { | ||
val hasData = bitMatrix.get(x, y) | ||
setPixel(x, y, if (hasData) dataColor else backgroundColor) | ||
} | ||
} | ||
} | ||
continuation.resume(bitmap) | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/xinto/mauth/core/otp/exporter/DefaultOtpExporter.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,35 @@ | ||
package com.xinto.mauth.core.otp.exporter | ||
|
||
import android.net.Uri | ||
import com.xinto.mauth.core.otp.model.OtpData | ||
import com.xinto.mauth.core.otp.model.OtpType | ||
|
||
class DefaultOtpExporter : OtpExporter { | ||
|
||
override fun exportOtp(data: OtpData): String { | ||
val uriBuilder = Uri.Builder() | ||
.scheme("otpauth") | ||
.appendPath(data.label) | ||
.appendQueryParameter("secret", data.secret) | ||
.appendQueryParameter("algorithm", data.algorithm.name) | ||
.appendQueryParameter("digits", data.digits.toString()) | ||
|
||
if (data.issuer.isNotBlank()) { | ||
uriBuilder.appendQueryParameter("issuer", data.issuer) | ||
} | ||
|
||
return when (data.type) { | ||
OtpType.TOTP -> { | ||
uriBuilder | ||
.authority("totp") | ||
.appendQueryParameter("period", data.period.toString()) | ||
} | ||
OtpType.HOTP -> { | ||
uriBuilder | ||
.authority("hotp") | ||
.appendQueryParameter("counter", data.period.toString()) | ||
} | ||
}.toString().also(::println) | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/xinto/mauth/core/otp/exporter/OtpExporter.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,9 @@ | ||
package com.xinto.mauth.core.otp.exporter | ||
|
||
import com.xinto.mauth.core.otp.model.OtpData | ||
|
||
interface OtpExporter { | ||
|
||
fun exportOtp(data: OtpData): String | ||
|
||
} |
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
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/xinto/mauth/domain/account/model/DomainExportAccount.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.xinto.mauth.domain.account.model | ||
|
||
import android.net.Uri | ||
import java.util.UUID | ||
|
||
data class DomainExportAccount( | ||
val id: UUID, | ||
val icon: Uri?, | ||
val label: String, | ||
val issuer: String, | ||
val url: String | ||
) { | ||
val shortLabel = label.take(1) | ||
} |
Oops, something went wrong.