FixityAlgorithm.kt 598 Bytes
Newer Older
1 2 3 4 5 6 7
package org.chronopolis.rest.models.enums

/**
 * Supported message digest functions in Chronopolis
 *
 * @author shake
 */
8 9
enum class FixityAlgorithm(val canonical: String) {
    SHA_256("SHA-256"), UNSUPPORTED("unsupported");
10

Michael Ritter's avatar
Michael Ritter committed
11 12 13 14 15
    fun bagitPrefix(): String = when (this) {
        SHA_256 -> "sha256.txt"
        else -> ".txt"
    }

16 17 18 19 20 21 22 23 24
    companion object {
        fun fromString(algorithm: String): FixityAlgorithm {
            return when (algorithm.toLowerCase()) {
                "sha256", "sha-256", "sha_256" -> SHA_256
                else -> UNSUPPORTED
            }
        }
    }
}