This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 494
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 #280 from corona-warn-app/dev
0.8.9
- Loading branch information
Showing
52 changed files
with
1,006 additions
and
454 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
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
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
2 changes: 1 addition & 1 deletion
2
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/submission/TanConstants.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,6 +1,6 @@ | ||
package de.rki.coronawarnapp.ui.submission | ||
|
||
object TanConstants { | ||
const val MAX_LENGTH = 7 | ||
const val MAX_LENGTH = 10 | ||
val ALPHA_NUMERIC_CHARS = ('a'..'z').plus('A'..'Z').plus('0'..'9') | ||
} |
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
35 changes: 35 additions & 0 deletions
35
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/TanHelper.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 de.rki.coronawarnapp.util | ||
|
||
import de.rki.coronawarnapp.ui.submission.TanConstants.MAX_LENGTH | ||
import java.nio.charset.StandardCharsets | ||
import java.security.MessageDigest | ||
import java.util.Locale | ||
|
||
object TanHelper { | ||
private const val VALID_CHARACTERS = "23456789ABCDEFGHJKMNPQRSTUVWXYZ" | ||
|
||
fun isChecksumValid(tan: String): Boolean { | ||
if (tan.trim().length != MAX_LENGTH) | ||
return false | ||
val subTan = tan.substring(0, MAX_LENGTH - 1).toUpperCase(Locale.ROOT) | ||
val tanDigest = MessageDigest.getInstance("SHA-256") | ||
.digest(subTan.toByteArray(StandardCharsets.US_ASCII)) | ||
var checkChar = "%02x".format(tanDigest[0])[0] | ||
if (checkChar == '0') checkChar = 'G' | ||
if (checkChar == '1') checkChar = 'H' | ||
|
||
return checkChar.toUpperCase() == tan.last().toUpperCase() | ||
} | ||
|
||
fun allCharactersValid(tan: String): Boolean { | ||
for (character in tan) { | ||
if (!isTanCharacterValid(character.toString())) | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
fun isTanCharacterValid(character: String): Boolean { | ||
return VALID_CHARACTERS.contains(character) | ||
} | ||
} |
Oops, something went wrong.