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

SHA384

class SHA384

SHA384 constrains String to be a valid hexadecimal String of length 96

Safe nullable construction

import arrow.refinement.digests.SHA384

SHA384.orNull("768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9")
// 768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9
SHA384.orNull("not-sha384")

Resolved constraints

SHA384.constraints("768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9")
// [(true, Expected 768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9 to be a valid hexadecimal string), (true, Expected 768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9 to have length 96)]
SHA384.constraints("not-sha384")
// [(false, Expected not-sha384 to be a valid hexadecimal string), (false, Expected not-sha384 to have length 96)]
SHA384.isValid("768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9")
// true
SHA384.isValid("not-sha384")
// false

Folding validation

SHA384.fold("768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9", { "failed: $it" }, { "success: $it" })
// success: SHA384(value=768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9)
SHA384.fold("not-sha384", { "failed: $it" }, { "success: $it" })
// failed: [(false, Expected not-sha384 to be a valid hexadecimal string), (false, Expected not-sha384 to have length 96)]

Unsafe require

SHA384.require("768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9")
// 768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9
try { SHA384.require("not-sha384") } catch (e: IllegalArgumentException) { e.message }
// Expected not-sha384 to be a valid hexadecimal string, Expected not-sha384 to have length 96

Types

Companion companion object Companion : Refined<String, SHA384>

Properties

value val value: String

Do you like Arrow?

Arrow Org
<