-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release-app_5.19' into merge_5.18_5.19
- Loading branch information
Showing
12 changed files
with
345 additions
and
69 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
6 changes: 5 additions & 1 deletion
6
tangem-sdk-core/src/main/java/com/tangem/common/SuccessResponse.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,7 +1,11 @@ | ||
package com.tangem.common | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
import com.tangem.operations.CommandResponse | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class SuccessResponse(val cardId: String) : CommandResponse | ||
data class SuccessResponse( | ||
@Json(name = "cardId") | ||
val cardId: String, | ||
) : CommandResponse |
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
25 changes: 25 additions & 0 deletions
25
tangem-sdk-core/src/main/java/com/tangem/operations/sign/ChunkHashesUtils.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,25 @@ | ||
package com.tangem.operations.sign | ||
|
||
internal object ChunkHashesUtils { | ||
// The max answer is 1152 bytes (unencrypted) and 1120 (encrypted). | ||
// The worst case is 8 hashes * 64 bytes for ed + 512 bytes of signatures + cardId, SignedHashes + TLV + SW is ok. | ||
private const val PACKAGE_SIZE = 512 | ||
// Card limitation | ||
private const val MAX_CHUNK_SIZE = 10 | ||
|
||
fun chunkHashes(hashesRaw: Array<ByteArray>): List<Chunk> { | ||
val hashes = hashesRaw.mapIndexed { index, hash -> Hash(index = index, data = hash) } | ||
val hashesBySize = hashes.groupBy { it.data.size } | ||
|
||
return hashesBySize.flatMap { hashesGroup -> | ||
val hashSize = hashesGroup.key | ||
val chunkSize = getChunkSize(hashSize) | ||
|
||
hashesGroup.value | ||
.chunked(chunkSize) | ||
.map { Chunk(hashSize, it) } | ||
} | ||
} | ||
|
||
private fun getChunkSize(hashSize: Int) = (PACKAGE_SIZE / hashSize).coerceIn(1, MAX_CHUNK_SIZE) | ||
} |
30 changes: 30 additions & 0 deletions
30
tangem-sdk-core/src/main/java/com/tangem/operations/sign/ChunkedHashesContainer.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,30 @@ | ||
package com.tangem.operations.sign | ||
|
||
class ChunkedHashesContainer( | ||
hashes: Array<ByteArray>, | ||
) { | ||
val isEmpty: Boolean = hashes.isEmpty() | ||
var currentChunkIndex: Int = 0 | ||
private set | ||
|
||
private val chunks = ChunkHashesUtils.chunkHashes(hashes) | ||
val chunksCount = chunks.size | ||
|
||
private var signedChunks: MutableList<SignedChunk> = mutableListOf() | ||
|
||
fun getCurrentChunk(): Chunk { | ||
return chunks[currentChunkIndex] | ||
} | ||
|
||
fun addSignedChunk(signedChunk: SignedChunk) { | ||
signedChunks.add(signedChunk) | ||
currentChunkIndex++ | ||
} | ||
|
||
fun getSignatures(): List<ByteArray> { | ||
return signedChunks | ||
.flatMap { it.signedHashes } | ||
.sortedBy { it.index } | ||
.map { it.signature } | ||
} | ||
} |
Oops, something went wrong.