scorex.crypto.hash.CommutativeHash.scala Maven / Gradle / Ivy
package scorex.crypto.hash
import scorex.utils.ByteArray
class CommutativeHash[HashFn <: CryptographicHash](hf: HashFn) extends CryptographicHash {
override val DigestSize: Int = hf.DigestSize
override def hash(input: Message): Digest = hf.hash(input)
def apply(x: Message, y:Message): Digest = hash(x, y)
def hash(x: Message, y: Message): Digest = if (ByteArray.compare(x, y) > 0) hash(x ++ y) else hash(y ++ x)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy