From 39c5d12096cf27258ba7bd31092d821fe09b6f4a Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 23 Aug 2023 13:28:38 +0200 Subject: [PATCH] Use IntRange for Trustworthiness range check --- .../kotlin/org/pgpainless/algorithm/Trustworthiness.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/algorithm/Trustworthiness.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/algorithm/Trustworthiness.kt index b1a1b7dd..695632a2 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/algorithm/Trustworthiness.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/algorithm/Trustworthiness.kt @@ -62,11 +62,13 @@ class Trustworthiness(amount: Int, depth: Int) { fun canIntroduce(other: Trustworthiness) = canIntroduce(other.depth) companion object { - const val THRESHOLD_FULLY_CONVINCED = 120 // greater or equal is fully trusted const val MARGINALLY_CONVINCED = 60 // default value for marginally convinced const val NOT_TRUSTED = 0 // 0 is not trusted + @JvmStatic + private val validRange = 0..255 + /** * This means that we are fully convinced of the trustworthiness of the key. * @@ -94,7 +96,7 @@ class Trustworthiness(amount: Int, depth: Int) { @JvmStatic private fun capAmount(amount: Int): Int { - if (amount !in 0..255) { + if (amount !in validRange) { throw IllegalArgumentException("Trust amount MUST be a value between 0 and 255") } return amount @@ -102,7 +104,7 @@ class Trustworthiness(amount: Int, depth: Int) { @JvmStatic private fun capDepth(depth: Int): Int { - if (depth !in 0..255) { + if (depth !in validRange) { throw IllegalArgumentException("Trust depth MUST be a value between 0 and 255") } return depth