Skip to content

Commit

Permalink
schema: further decompose the digest grammar
Browse files Browse the repository at this point in the history
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 <stephen.day@docker.com>
  • Loading branch information
stevvooe committed May 4, 2017
1 parent 7637741 commit 9c6dd18
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
10 changes: 6 additions & 4 deletions descriptor.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ The _algorithm_ specifies the cryptographic hash function and encoding used for
A digest string MUST match the following grammar:

```
digest := algorithm ":" encoded
algorithm := /[a-z0-9]+(?:[+._-][a-z0-9]+)*/
encoded := /[a-zA-Z0-9_-]+/
digest := algorithm ":" encoded
algorithm := algorithm-component [algorithm-separator algorithm-component]*
algorithm-component := /[a-z0-9]+/
algorithm-separator := /[+._-]/
encoded := /[a-zA-Z0-9=_-]+/
```

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

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

Expand Down
2 changes: 1 addition & 1 deletion schema/defs-descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"digest": {
"description": "the cryptographic checksum digest of the object, in the pattern '<algorithm>:<encoded>'",
"type": "string",
"pattern": "^[a-z0-9]+(?:[+._-][a-z0-9]+)*:[a-zA-Z0-9_-]+$"
"pattern": "^[a-z0-9]+(?:[+._-][a-z0-9]+)*:[a-zA-Z0-9=_-]+$"
},
"urls": {
"description": "a list of urls from which this object may be downloaded",
Expand Down
10 changes: 9 additions & 1 deletion schema/descriptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,15 @@ func TestDescriptor(t *testing.T) {
},
{
descriptor: `{
"digest": "sha256+b64:LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564",
"digest": "sha256+b64u:LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564",
"size": 1000000,
"mediaType": "application/vnd.oci.image.config.v1+json"
}`,
},
{
// test for those who cannot use modulo arithmetic to recover padding.
descriptor: `{
"digest": "sha256+b64u.unknownlength:LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564=",
"size": 1000000,
"mediaType": "application/vnd.oci.image.config.v1+json"
}`,
Expand Down
20 changes: 10 additions & 10 deletions schema/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,17 @@ ERcrb5b9zhBc4s2zO7r2jN/2xKhin3+/McttXS9NB/Cle+p+BgAA///HjexwPQQAAA==

"/defs-descriptor.json": {
local: "defs-descriptor.json",
size: 921,
modtime: 1493324159,
size: 922,
modtime: 1493750367,
compressed: `
H4sIAAAAAAAA/6STX2/TMBTF3/spLl7FgDZN4QFp0TQ0sXcextOmrrqzb+I74j+yXU1l6ndHTrK0KwKB
9pDIPro+5/5unKcJgFAUZWCf2FlRgbiimi3nXQSPIbHctBggOfjmyX51NiFbCnA1HHMBrj1Jrlli5zHv
TUcXUUHOARCGFOP3radRAhCscqpOyceqLJ0nK58z4sKFpoxSk8GSDTZUqjG13LvNn71S7y1iCmybve4x
JQod3t3tZXGDxc9lcbbaL9+cTN8Wd+vFbPW0n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