@@ -58,10 +58,14 @@ import org.bouncycastle.asn1.DERSet
5858import org.bouncycastle.asn1.DERTaggedObject
5959import org.bouncycastle.asn1.x509.Extension
6060
61- @Immutable
6261@RequiresApi(24 )
63- data class ExtensionParsingException (val msg : String , val reason : KeyAttestationReason ? = null ) :
64- Exception (msg)
62+ data class ExtensionParsingException
63+ @JvmOverloads
64+ constructor (
65+ override val message: String ,
66+ val reason: KeyAttestationReason ? = null ,
67+ override val cause: Throwable ? = null ,
68+ ) : Exception (message, cause)
6569
6670@Immutable
6771data class ProvisioningInfoMap (
@@ -444,13 +448,12 @@ data class AuthorizationList(
444448 }
445449
446450 fun from (seq : ASN1Sequence , logFn : (String ) -> Unit = { _ -> }): AuthorizationList {
447- val objects =
448- seq.associate {
449- require(it is ASN1TaggedObject ) {
450- " Must be an ASN1TaggedObject, was ${it::class .simpleName} "
451- }
452- KeyMintTag .from(it.tagNo) to it.explicitBaseObject
451+ val objects = seq.associate {
452+ require(it is ASN1TaggedObject ) {
453+ " Must be an ASN1TaggedObject, was ${it::class .simpleName} "
453454 }
455+ KeyMintTag .from(it.tagNo) to it.explicitBaseObject
456+ }
454457
455458 /* *
456459 * X.680 section 8.6
@@ -775,11 +778,15 @@ private inline fun <reified T> ASN1Encodable.toSet(): Set<T> {
775778
776779@RequiresApi(24 )
777780private fun ASN1Encodable.toStr () =
778- UTF_8 .newDecoder()
779- .onMalformedInput(CodingErrorAction .REPORT )
780- .onUnmappableCharacter(CodingErrorAction .REPORT )
781- .decode(this .toByteBuffer())
782- .toString()
781+ try {
782+ UTF_8 .newDecoder()
783+ .onMalformedInput(CodingErrorAction .REPORT )
784+ .onUnmappableCharacter(CodingErrorAction .REPORT )
785+ .decode(this .toByteBuffer())
786+ .toString()
787+ } catch (e: CharacterCodingException ) {
788+ throw ExtensionParsingException (" error decoding ASN.1: ${e.message} " , cause = e)
789+ }
783790
784791private fun ASN1Encodable.toTaggedObject (tag : KeyMintTag ) = DERTaggedObject (tag.value, this )
785792
0 commit comments