Skip to content

Commit

Permalink
Merge pull request #114 from usefulness/v4
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkwiecinski authored Sep 10, 2022
2 parents 88c34f4 + 82787b1 commit d025edb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.jakewharton.diffuse.format

import com.android.apksig.ApkVerifier
import com.android.apksig.ApkVerifier.Result
import com.android.apksig.ApkVerifier.Result.V4SchemeSignerInfo
import com.android.apksig.util.DataSource
import com.android.apksig.util.DataSources
import com.jakewharton.diffuse.io.Input
Expand All @@ -16,6 +18,7 @@ data class Signatures(
val v1: List<ByteString>,
val v2: List<ByteString>,
val v3: List<ByteString>,
val v4: List<ByteString>,
) {
companion object {
@JvmStatic
Expand All @@ -27,6 +30,7 @@ data class Signatures(
result.v1SchemeSigners.map { it.certificate.encoded.toByteString().sha1() }.sorted(),
result.v2SchemeSigners.map { it.certificate.encoded.toByteString().sha1() }.sorted(),
result.v3SchemeSigners.map { it.certificate.encoded.toByteString().sha1() }.sorted(),
result.v4SchemeSigners.map { it.certificate.encoded.toByteString().sha1() }.sorted(),
)
}
}
Expand All @@ -50,5 +54,11 @@ data class Signatures(
closeable?.close()
}
}

@Suppress("UNCHECKED_CAST")
private val Result.v4SchemeSigners: List<V4SchemeSignerInfo>
get() = this::class.java
.getDeclaredMethod("getV4SchemeSigners").apply { isAccessible = true }
.invoke(this) as List<V4SchemeSignerInfo>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ internal fun SignaturesDiff.toDetailReport() = buildString {
cell(newSignatures.v3.joinToString("\n", transform = ByteString::hex))
}
}
if (oldSignatures.v4.isNotEmpty() || newSignatures.v4.isNotEmpty()) {
row {
cell("V4") {
alignment = TopRight
}
cell(oldSignatures.v4.joinToString("\n", transform = ByteString::hex))
cell(newSignatures.v4.joinToString("\n", transform = ByteString::hex))
}
}
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.jakewharton.diffuse.report
import com.jakewharton.diffuse.format.Signatures

internal fun Signatures.toSummaryString(): String {
if (v1.isEmpty() && v2.isEmpty() && v3.isEmpty()) {
if (v1.isEmpty() && v2.isEmpty() && v3.isEmpty() && v4.isEmpty()) {
return "none"
}
return buildString {
Expand Down Expand Up @@ -37,5 +37,16 @@ internal fun Signatures.toSummaryString(): String {
append(')')
}
}
if (v4.isNotEmpty()) {
if (length > 0) {
append(", ")
}
append("V4")
if (v4.size > 1) {
append(" (x")
append(v4.size)
append(')')
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class SignaturesDiffTest {
private val signatureEmpty = Signatures(emptyList(), emptyList(), emptyList())
private val signatureV1Only = Signatures(listOf("v1v1".encodeUtf8()), emptyList(), emptyList())
private val signatureV1AndV2 = Signatures(listOf("v1v1".encodeUtf8()), listOf("v2v2".encodeUtf8()), emptyList())
private val signatureV1AndV3 = Signatures(listOf("v1v1".encodeUtf8()), emptyList(), listOf("v3v3".encodeUtf8()))
private val signatureEmpty = Signatures(emptyList(), emptyList(), emptyList(), emptyList())
private val signatureV1Only = Signatures(listOf("v1v1".encodeUtf8()), emptyList(), emptyList(), emptyList())
private val signatureV1AndV2 = Signatures(listOf("v1v1".encodeUtf8()), listOf("v2v2".encodeUtf8()), emptyList(), emptyList())
private val signatureV1AndV3 = Signatures(listOf("v1v1".encodeUtf8()), emptyList(), listOf("v3v3".encodeUtf8()), emptyList())
private val signatureV3AndV4 = Signatures(emptyList(), emptyList(), listOf("v3v3".encodeUtf8()), listOf("v4v4".encodeUtf8()))

@Test fun emptyToV1() {
val diff = SignaturesDiff(signatureEmpty, signatureV1Only)
Expand Down Expand Up @@ -54,4 +55,20 @@ class SignaturesDiffTest {
""".trimMargin(),
)
}

@Test fun v1AndV2ToV3AndV4() {
val diff = SignaturesDiff(signatureV1AndV2, signatureV3AndV4)
assertThat(diff.toDetailReport()).isEqualTo(
"""
|
| SIGNATURES │ old │ new
|────────────┼──────────┼──────────
| V1 │ 76317631 │
| V2 │ 76327632 │
| V3 │ │ 76337633
| V4 │ │ 76347634
|
""".trimMargin(),
)
}
}

0 comments on commit d025edb

Please sign in to comment.