arrow-refined-types / arrow.refinement.digests / SHA512

SHA512

class SHA512

SHA512 constrains String to be a valid hexadecimal String of length 128

Safe nullable construction

import arrow.refinement.digests.SHA512

SHA512.orNull("ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff")
// ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff
SHA512.orNull("not-sha512")

Resolved constraints

SHA512.constraints("ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff")
// [(true, Expected ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff to be a valid hexadecimal string), (true, Expected ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff to have length 128)]
SHA512.constraints("not-sha512")
// [(false, Expected not-sha512 to be a valid hexadecimal string), (false, Expected not-sha512 to have length 128)]
SHA512.isValid("ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff")
// true
SHA512.isValid("not-sha512")
// false

Folding validation

SHA512.fold("ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff", { "failed: $it" }, { "success: $it" })
// success: SHA512(value=ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff)
SHA512.fold("not-sha512", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected not-sha512 to be a valid hexadecimal string), (false, Expected not-sha512 to have length 128)]

Unsafe require

SHA512.require("ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff")
// ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff
try { SHA512.require("not-sha512") } catch (e: IllegalArgumentException) { e.message }
// Expected not-sha512 to be a valid hexadecimal string, Expected not-sha512 to have length 128

Types

Companion companion object Companion : Refined<String, SHA512>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<