Skip to content

Commit

Permalink
Prefer Either.catch over try/catch rethrowing CancellationException
Browse files Browse the repository at this point in the history
  • Loading branch information
dzarras committed Dec 17, 2024
1 parent c52d1cf commit 9e475ae
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package eu.europa.ec.eudi.verifier.endpoint.port.input

import arrow.core.Either
import arrow.core.getOrElse
import arrow.core.toNonEmptyListOrNull
import com.nimbusds.jose.proc.BadJOSEException
import eu.europa.ec.eudi.sdjwt.*
import eu.europa.ec.eudi.sdjwt.vc.SdJwtVcVerifier
import eu.europa.ec.eudi.sdjwt.vc.X509CertificateTrust
import eu.europa.ec.eudi.verifier.endpoint.adapter.out.cert.X5CShouldBe
import eu.europa.ec.eudi.verifier.endpoint.adapter.out.cert.X5CValidator
import eu.europa.ec.eudi.verifier.endpoint.domain.Nonce
import kotlinx.coroutines.CancellationException
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.buildJsonObject
Expand Down Expand Up @@ -103,22 +103,21 @@ internal class ValidateSdJwtVc(
put(Claims.Nonce, nonce.value)
}

return try {
return Either.catch {
val (presentation, keyBinding) = verifier.verifyPresentation(unverified, challenge).getOrThrow()
checkNotNull(keyBinding) { "KeyBinding JWT cannot be null" }

val payload = with(DefaultSdJwtOps) {
presentation.recreateClaims(visitor = null)
}
SdJwtVcValidationResult.Valid(payload)
} catch (cancellation: CancellationException) {
throw cancellation
} catch (verificationError: SdJwtVerificationException) {
log.error("SD-JWT-VC validation failed", verificationError)
SdJwtVcValidationResult.Invalid(verificationError.toSdJwtVcValidationErrorTO())
} catch (badJoseError: BadJOSEException) {
log.error("SD-JWT-VC validation failed", badJoseError)
SdJwtVcValidationResult.Invalid(SdJwtVcValidationErrorTO.Other)
}.getOrElse {
log.error("SD-JWT-VC validation failed", it)
if (it is SdJwtVerificationException) {
SdJwtVcValidationResult.Invalid(it.toSdJwtVcValidationErrorTO())
} else {
SdJwtVcValidationResult.Invalid(SdJwtVcValidationErrorTO.Other)
}
}
}
}
Expand Down

0 comments on commit 9e475ae

Please sign in to comment.