Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea committed Sep 16, 2023
1 parent 1dc48b5 commit 39b8927
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions app/src/main/java/tech/relaycorp/letro/utils/asn1/ASN1Utils.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tech.relaycorp.letro.utils.asn1

import java.io.IOException
import org.bouncycastle.asn1.ASN1Encodable
import org.bouncycastle.asn1.ASN1EncodableVector
import org.bouncycastle.asn1.ASN1InputStream
Expand All @@ -11,11 +10,14 @@ import org.bouncycastle.asn1.ASN1VisibleString
import org.bouncycastle.asn1.DEROctetString
import org.bouncycastle.asn1.DERSequence
import org.bouncycastle.asn1.DERTaggedObject
import java.io.IOException

internal object ASN1Utils {
fun makeSequence(items: List<ASN1Encodable>, explicitTagging: Boolean = true): DERSequence {
val messagesVector = ASN1EncodableVector(items.size)
val finalItems = if (explicitTagging) items else items.mapIndexed { index, item ->
val finalItems = if (explicitTagging) {
items
} else items.mapIndexed { index, item ->
DERTaggedObject(false, index, item)
}
finalItems.forEach { messagesVector.add(it) }
Expand Down Expand Up @@ -46,14 +48,14 @@ internal object ASN1Utils {

@Throws(ASN1Exception::class)
inline fun <reified T : ASN1Encodable> deserializeHomogeneousSequence(
serialization: ByteArray
serialization: ByteArray,
): Array<T> {
val sequence = deserializeSequence(serialization)
return sequence.map {
if (it !is T) {
throw ASN1Exception(
"Sequence contains an item of an unexpected type " +
"(${it::class.java.simpleName})"
"(${it::class.java.simpleName})",
)
}
@Suppress("USELESS_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal class ASN1UtilsTest {
val item2 = sequence.readObject()
item2 should beInstanceOf<DEROctetStringParser>()
octetString.octets shouldBe
((item2 as DEROctetStringParser).loadedObject as DEROctetString).octets
((item2 as DEROctetStringParser).loadedObject as DEROctetString).octets
}

@Test
Expand Down Expand Up @@ -138,8 +138,8 @@ internal class ASN1UtilsTest {
}

exception.message shouldBe
"Sequence contains an item of an unexpected type " +
"(${octetString::class.java.simpleName})"
"Sequence contains an item of an unexpected type " +
"(${octetString::class.java.simpleName})"
}

@Test
Expand All @@ -151,7 +151,7 @@ internal class ASN1UtilsTest {

2 shouldBe sequence.size
visibleString.octets shouldBe
ASN1Utils.getVisibleString(sequence.first()).octets
ASN1Utils.getVisibleString(sequence.first()).octets
octetString.octets shouldBe ASN1Utils.getOctetString(sequence[1]).octets
}
}
Expand Down

0 comments on commit 39b8927

Please sign in to comment.