# `Hash`

A SHA-256 digest: the 32 bytes `hash.sha256` gives.

Use it to spot changed content or to keep a fingerprint of a key. For a password, use [`PasswordHash`](/docs/types/type-password-hash.md). For a signature with a key, use [`Hmac`](/docs/types/type-hmac.md).

## Shape

One value, held as bytes, with no parts. As text it reads `ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=`.

## Example

```jadpo
Hash(hash.sha256("hello"))
```

`Hash(bytes)` checks them, and bytes that aren't one break the `format` rule.

`text.parse(raw, as: Hash)` reads one from text that comes from outside. Text that isn't one at all fails `malformed`.

## Good to know

- `==` on two of them takes the same time wherever they differ, so it leaks nothing.
- JSON sends it as Base64.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it.

## In JSON

A string, in a request, a response or `json.write`:

```json
"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="
"ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0="
```

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`Hash` is in the group Security, and has been in Jadpo since 0.1.0.

### Text form

`text.from` writes one standard text form, the same form `text.parse` reads back: `47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=` and `ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=`.

### How it is stored

It is stored in one column named for the field, of type `bytea`. `ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=` is stored as `E'\\xba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'::bytea`.

### How it is shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=` | `47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=` |
| `ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=` | `ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=` |

### Operations

It also takes `text.parse`, `text.from`, `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
