Skip to content

Commit 69920f9

Browse files
authored
Merge pull request #14536 from NixOS/clamp-down-hash
JSON for `Hash` now has to be `Base16`
2 parents 29849af + bec3c5c commit 69920f9

36 files changed

+140
-161
lines changed

doc/manual/rl-next/json-format-changes.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ The store path info JSON format has been updated from version 1 to version 2:
1919
Content address is now a structured JSON object instead of a string:
2020

2121
- Old: `"ca": "fixed:r:sha256:1abc..."`
22-
- New: `"ca": {"method": "nar", "hash": {"algorithm": "sha256", "format": "base64", "hash": "EMIJ+giQ..."}}`
22+
- New: `"ca": {"method": "nar", "hash": {"algorithm": "sha256", "format": "base16", "hash": "10c209fa..."}}`
2323
- Still `null` values for input-addressed store objects
2424

2525
- **Structured hash fields**:
2626

2727
Hash values (`narHash` and `downloadHash`) are now structured JSON objects instead of strings:
2828

2929
- Old: `"narHash": "sha256:FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="`
30-
- New: `"narHash": {"algorithm": "sha256", "format": "base64", "hash": "FePFYIlM..."}`
30+
- New: `"narHash": {"algorithm": "sha256", "format": "base16", "hash": "15e3c5608946..."}`
3131
- Same structure applies to `downloadHash` in NAR info contexts
32+
- The `format` field is always `"base16"` (hexadecimal)
3233

3334
Nix currently only produces, and doesn't consume this format.
3435

@@ -48,8 +49,8 @@ The derivation JSON format has been updated from version 3 to version 4:
4849
- **Consistent content addresses**:
4950

5051
Floating content-addressed outputs now use structured JSON format.
51-
This is the same format as `ca` in in store path info (after the new version).
52+
This is the same format as `ca` in store path info (after the new version).
5253

5354
Version 3 and earlier formats are *not* accepted when reading.
5455

55-
**Affected command**: `nix derivation`, namely it's `show` and `add` sub-commands.
56+
**Affected command**: `nix derivation`, namely its `show` and `add` sub-commands.

doc/manual/source/protocols/json/hash.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,16 @@
22

33
## Examples
44

5-
### SHA-256 with Base64 encoding
6-
7-
```json
8-
{{#include schema/hash-v1/sha256-base64.json}}
9-
```
10-
11-
### SHA-256 with Base16 (hexadecimal) encoding
5+
### SHA-256
126

137
```json
148
{{#include schema/hash-v1/sha256-base16.json}}
159
```
1610

17-
### SHA-256 with Nix32 encoding
18-
19-
```json
20-
{{#include schema/hash-v1/sha256-nix32.json}}
21-
```
22-
23-
### BLAKE3 with Base64 encoding
11+
### BLAKE3
2412

2513
```json
26-
{{#include schema/hash-v1/blake3-base64.json}}
14+
{{#include schema/hash-v1/blake3-base16.json}}
2715
```
2816

2917
<!-- need to convert YAML to JSON first

doc/manual/source/protocols/json/schema/hash-v1.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@ properties:
1212
format:
1313
type: string
1414
enum:
15-
- base64
16-
- nix32
1715
- base16
18-
- sri
1916
title: Hash format
2017
description: |
2118
The encoding format of the hash value.
2219
23-
- `base64` uses standard Base64 encoding [RFC 4648, section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4)
24-
- `nix32` is Nix-specific base-32 encoding
25-
- `base16` is lowercase hexadecimal
26-
- `sri` is the [Subresource Integrity format](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity).
20+
`base16` (lowercase hexadecimal) is the only format that is currently supported for JSON serialization.
21+
This field exists primarily to reduce ambiguity about what the hash means.
22+
It would also help us support other formats in the future, but there are no concrete plans to do so at this.
2723
hash:
2824
type: string
2925
title: Hash

src/json-schema-checks/meson.build

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ schemas = [
3232
'stem' : 'hash',
3333
'schema' : schema_dir / 'hash-v1.yaml',
3434
'files' : [
35-
'sha256-base64.json',
3635
'sha256-base16.json',
37-
'sha256-nix32.json',
38-
'blake3-base64.json',
36+
'blake3-base16.json',
3937
],
4038
},
4139
{

src/libstore-tests/data/common-protocol/content-address.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
{
33
"hash": {
44
"algorithm": "sha256",
5-
"format": "base64",
6-
"hash": "+Xc9Ll6mcPltwaewrk/BAQ56Y3G5T//wzhKUc0zrYu0="
5+
"format": "base16",
6+
"hash": "f9773d2e5ea670f96dc1a7b0ae4fc1010e7a6371b94ffff0ce1294734ceb62ed"
77
},
88
"method": "text"
99
},
1010
{
1111
"hash": {
1212
"algorithm": "sha1",
13-
"format": "base64",
14-
"hash": "gGemBoenViNZM3hiwqns/Fgzqwo="
13+
"format": "base16",
14+
"hash": "8067a60687a7562359337862c2a9ecfc5833ab0a"
1515
},
1616
"method": "flat"
1717
},
1818
{
1919
"hash": {
2020
"algorithm": "sha256",
21-
"format": "base64",
22-
"hash": "EMIJ+giQ/gLIWoxmPKjno3zHZrxbGymgzGGyZvZBIdM="
21+
"format": "base16",
22+
"hash": "10c209fa0890fe02c85a8c663ca8e7a37cc766bc5b1b29a0cc61b266f64121d3"
2323
},
2424
"method": "nar"
2525
}

src/libstore-tests/data/common-protocol/optional-content-address.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{
44
"hash": {
55
"algorithm": "sha1",
6-
"format": "base64",
7-
"hash": "gGemBoenViNZM3hiwqns/Fgzqwo="
6+
"format": "base16",
7+
"hash": "8067a60687a7562359337862c2a9ecfc5833ab0a"
88
},
99
"method": "flat"
1010
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"hash": {
33
"algorithm": "sha256",
4-
"format": "base64",
5-
"hash": "9vLqj0XYoFfJVmoz+ZR02i5camYE1zYSFlDicwxvsKM="
4+
"format": "base16",
5+
"hash": "f6f2ea8f45d8a057c9566a33f99474da2e5c6a6604d736121650e2730c6fb0a3"
66
},
77
"method": "nar"
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"hash": {
33
"algorithm": "sha256",
4-
"format": "base64",
5-
"hash": "8OTC92xYkW7CWPJGhRvqCR0U1CR6L8PhhpRGGxgW4Ts="
4+
"format": "base16",
5+
"hash": "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b"
66
},
77
"method": "text"
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"hash": {
33
"algorithm": "sha256",
4-
"format": "base64",
5-
"hash": "iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8="
4+
"format": "base16",
5+
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f"
66
},
77
"method": "flat"
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"hash": {
33
"algorithm": "sha256",
4-
"format": "base64",
5-
"hash": "iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8="
4+
"format": "base16",
5+
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f"
66
},
77
"method": "nar"
88
}

0 commit comments

Comments
 (0)