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

SHA224

class SHA224

SHA224 constrains String to be a valid hexadecimal String of length 56

Safe nullable construction

import arrow.refinement.digests.SHA224

SHA224.orNull("90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809")
// 90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809
SHA224.orNull("not-sha224")

Resolved constraints

SHA224.constraints("90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809")
// [(true, Expected 90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809 to be a valid hexadecimal string), (true, Expected 90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809 to have length 56)]
SHA224.constraints("not-sha224")
// [(false, Expected not-sha224 to be a valid hexadecimal string), (false, Expected not-sha224 to have length 56)]
SHA224.isValid("90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809")
// true
SHA224.isValid("not-sha224")
// false

Folding validation

SHA224.fold("90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809", { "failed: $it" }, { "success: $it" })
// success: SHA224(value=90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809)
SHA224.fold("not-sha224", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected not-sha224 to be a valid hexadecimal string), (false, Expected not-sha224 to have length 56)]

Unsafe require

SHA224.require("90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809")
// 90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809
try { SHA224.require("not-sha224") } catch (e: IllegalArgumentException) { e.message }
// Expected not-sha224 to be a valid hexadecimal string, Expected not-sha224 to have length 56

Types

Companion companion object Companion : Refined<String, SHA224>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<