1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-25 12:27:58 +01:00

Use IntRange for Trustworthiness range check

This commit is contained in:
Paul Schaub 2023-08-23 13:28:38 +02:00
parent 717a59c7e7
commit ee44bf7473
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -62,11 +62,13 @@ class Trustworthiness(amount: Int, depth: Int) {
fun canIntroduce(other: Trustworthiness) = canIntroduce(other.depth) fun canIntroduce(other: Trustworthiness) = canIntroduce(other.depth)
companion object { companion object {
const val THRESHOLD_FULLY_CONVINCED = 120 // greater or equal is fully trusted const val THRESHOLD_FULLY_CONVINCED = 120 // greater or equal is fully trusted
const val MARGINALLY_CONVINCED = 60 // default value for marginally convinced const val MARGINALLY_CONVINCED = 60 // default value for marginally convinced
const val NOT_TRUSTED = 0 // 0 is not trusted 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. * This means that we are fully convinced of the trustworthiness of the key.
* *
@ -94,7 +96,7 @@ class Trustworthiness(amount: Int, depth: Int) {
@JvmStatic @JvmStatic
private fun capAmount(amount: Int): Int { 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") throw IllegalArgumentException("Trust amount MUST be a value between 0 and 255")
} }
return amount return amount
@ -102,7 +104,7 @@ class Trustworthiness(amount: Int, depth: Int) {
@JvmStatic @JvmStatic
private fun capDepth(depth: Int): Int { 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") throw IllegalArgumentException("Trust depth MUST be a value between 0 and 255")
} }
return depth return depth