All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sop.MicAlg.kt Maven / Gradle / Ivy

There is a newer version: 10.0.3
Show newest version
// SPDX-FileCopyrightText: 2023 Paul Schaub 
//
// SPDX-License-Identifier: Apache-2.0

package sop

import java.io.OutputStream
import java.io.PrintWriter

data class MicAlg(val micAlg: String) {

    fun writeTo(outputStream: OutputStream) {
        PrintWriter(outputStream).use { it.write(micAlg) }
    }

    companion object {
        @JvmStatic fun empty() = MicAlg("")

        @JvmStatic
        fun fromHashAlgorithmId(id: Int) =
            when (id) {
                1 -> "pgp-md5"
                2 -> "pgp-sha1"
                3 -> "pgp-ripemd160"
                8 -> "pgp-sha256"
                9 -> "pgp-sha384"
                10 -> "pgp-sha512"
                11 -> "pgp-sha224"
                12 -> "pgp-sha3-256"
                14 -> "pgp-sha3-512"
                else -> throw IllegalArgumentException("Unsupported hash algorithm ID: $id")
            }.let { MicAlg(it) }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy