Skip to content

Commit 9c6dd18

Browse files
committed
schema: further decompose the digest grammar
The digest grammar is now further decomposed into compontents to remove reliance on regex grouping syntax. We also extend the character set to include `=` sign which enables variable length base64 encoding. Signed-off-by: Stephen J Day <[email protected]>
1 parent 7637741 commit 9c6dd18

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

descriptor.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ The _algorithm_ specifies the cryptographic hash function and encoding used for
6969
A digest string MUST match the following grammar:
7070

7171
```
72-
digest := algorithm ":" encoded
73-
algorithm := /[a-z0-9]+(?:[+._-][a-z0-9]+)*/
74-
encoded := /[a-zA-Z0-9_-]+/
72+
digest := algorithm ":" encoded
73+
algorithm := algorithm-component [algorithm-separator algorithm-component]*
74+
algorithm-component := /[a-z0-9]+/
75+
algorithm-separator := /[+._-]/
76+
encoded := /[a-zA-Z0-9=_-]+/
7577
```
7678

7779
Some example digest strings include the following:
@@ -81,7 +83,7 @@ digest | algori
8183
sha256:6c3c624b58dbbcd3c0dd82b4c53f04194d1247c6eebdaab7c610cf7d66709b3b | [SHA-256](#sha-256) | Yes |
8284
sha512:401b09eab3c013d4ca54922bb802bec8fd5318192b0a75f201d8b3727429080fb337591abd3e44453b954555b7a0812e1081c39b740293f765eae731f5a65ed1 | [SHA-256](#sha-512) | Yes |
8385
multihash+base58:QmRZxt2b1FVZPNqd8hsiykDL3TdBDeTSPX9Kv46HmX4Gx8` | Multihash | No |
84-
sha256+b64:LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564 | SHA-256 with base64 | No |
86+
sha256+b64u:LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564 | SHA-256 with urlsafe base64 | No |
8587

8688
Please see [Registered Algorithms](#registered-identifiers) for a list of supported algorithms.
8789

schema/defs-descriptor.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"digest": {
1010
"description": "the cryptographic checksum digest of the object, in the pattern '<algorithm>:<encoded>'",
1111
"type": "string",
12-
"pattern": "^[a-z0-9]+(?:[+._-][a-z0-9]+)*:[a-zA-Z0-9_-]+$"
12+
"pattern": "^[a-z0-9]+(?:[+._-][a-z0-9]+)*:[a-zA-Z0-9=_-]+$"
1313
},
1414
"urls": {
1515
"description": "a list of urls from which this object may be downloaded",

schema/descriptor_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,15 @@ func TestDescriptor(t *testing.T) {
278278
},
279279
{
280280
descriptor: `{
281-
"digest": "sha256+b64:LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564",
281+
"digest": "sha256+b64u:LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564",
282+
"size": 1000000,
283+
"mediaType": "application/vnd.oci.image.config.v1+json"
284+
}`,
285+
},
286+
{
287+
// test for those who cannot use modulo arithmetic to recover padding.
288+
descriptor: `{
289+
"digest": "sha256+b64u.unknownlength:LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564=",
282290
"size": 1000000,
283291
"mediaType": "application/vnd.oci.image.config.v1+json"
284292
}`,

schema/fs.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,17 @@ ERcrb5b9zhBc4s2zO7r2jN/2xKhin3+/McttXS9NB/Cle+p+BgAA///HjexwPQQAAA==
237237

238238
"/defs-descriptor.json": {
239239
local: "defs-descriptor.json",
240-
size: 921,
241-
modtime: 1493324159,
240+
size: 922,
241+
modtime: 1493750367,
242242
compressed: `
243-
H4sIAAAAAAAA/6STX2/TMBTF3/spLl7FgDZN4QFp0TQ0sXcextOmrrqzb+I74j+yXU1l6ndHTrK0KwKB
244-
9pDIPro+5/5unKcJgFAUZWCf2FlRgbiimi3nXQSPIbHctBggOfjmyX51NiFbCnA1HHMBrj1Jrlli5zHv
245-
TUcXUUHOARCGFOP3radRAhCscqpOyceqLJ0nK58z4sKFpoxSk8GSDTZUqjG13LvNn71S7y1iCmybve4x
246-
JQod3t3tZXGDxc9lcbbaL9+cTN8Wd+vFbPW0nH/89HlX/lvZVHQRuz5JKG4opkO6o+EmTSDD1ifXBPSa
247-
JUhN8kfcGOjPgqshF7n7B5JpDmy77QAAp+fYNi5w0uaiOs+jUqQuTv9zAgPX7N2X6na2WBerUXn/ocrr
248-
y+JmWZyti9XsCHAT2vgXPISWe4ZcCHVwBh41Sw1JcxygwOAW7gmUe7StQ0Xq9/YxBNzuZU5kDnP/DAog
249-
ahcM5o8gNoHFoO9eYKC1LuHL2/maq3joNzY9DVRnP0V1XDxEZ0/Kg7+iNOivu9779zDnSX52k18BAAD/
250-
/7fEAguZAwAA
243+
H4sIAAAAAAAA/6STX2/TMBTF3/spLl7FgDZN4QFp0Ria2DsP42lTV93ZN/Ed8R/ZrqYy9bsjJ1naFYFA
244+
PCSyj67Pub8b52kCIBRFGdgndlZUIK6oZst5F8FjSCw3LQZIDr56sl+cTciWAlwNx1yAa0+Sa5bYecx7
245+
09FFVJBzAIQhxfht62mUAASrnKpT8rEqS+fJyueMuHChKaPUZLBkgw2Vakwt927zZ6/Ue4uYAttmr3tM
246+
iUKHd3d7Wdxg8WNZnK32y1cn09fF3XoxWz0t5+8/fNyVf1c2FV3Erk8SihuK6ZDuaLhJE8iw9ck1Ab1m
247+
CVKT/B43Bvqz4GrIRe7+gWSaA9tuOwDA6Tm2jQuctLmozvOoFKmL03+cwMA1e/O5up0t1sVqVN6+q/L6
248+
srhZFmef1sVqdkS4CW38Ax9Cyz1ELoQ6OAOPmqWGpDkOVGBwC/cEyj3a1qEi9Wv/GAJu9zInMoe5vycF
249+
ELULBvNXEJvAYtB3LzDQWpfw5fX8n7t46Dc2PQ1UZz9FdVw8RGdPyoPfojTor7ve+/cw50l+dpOfAQAA
250+
//8aH/C2mgMAAA==
251251
`,
252252
},
253253

0 commit comments

Comments
 (0)