Skip to content

Commit

Permalink
fix(model): Always use lowercase for serialized hash values
Browse files Browse the repository at this point in the history
Ensure `OrtResult`s remain identical if only the "case" of a hash value
changed, which also makes the functional tests tolerate that.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Feb 2, 2024
1 parent 4661582 commit cf5d3c3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions model/src/main/kotlin/Hash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

package org.ossreviewtoolkit.model

import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.databind.util.StdConverter

import java.io.File
import java.util.Base64

Expand All @@ -32,6 +35,7 @@ data class Hash(
/**
* The value calculated using the hash algorithm.
*/
@JsonSerialize(converter = StringLowercaseConverter::class)
val value: String,

/**
Expand Down Expand Up @@ -96,3 +100,7 @@ data class Hash(
*/
fun verify(hash: Hash): Boolean = algorithm == hash.algorithm && value.equals(hash.value, ignoreCase = true)
}

private class StringLowercaseConverter : StdConverter<String, String>() {
override fun convert(value: String): String = value.lowercase()
}

0 comments on commit cf5d3c3

Please sign in to comment.