-
Notifications
You must be signed in to change notification settings - Fork 64
digest: promote blake3 to first-class digest #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stevvooe
wants to merge
1
commit into
opencontainers:master
Choose a base branch
from
stevvooe:blake3-first-class
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// Copyright 2019, 2020 OCI Contributors | ||
// Copyright 2017 Docker, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package digest | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestParseDigest(t *testing.T) { | ||
for _, testcase := range []struct { | ||
input string | ||
err error | ||
algorithm Algorithm | ||
encoded string | ||
}{ | ||
{ | ||
input: "sha256:e58fcf7418d4390dec8e8fb69d88c06ec07039d651fedd3aa72af9972e7d046b", | ||
algorithm: "sha256", | ||
encoded: "e58fcf7418d4390dec8e8fb69d88c06ec07039d651fedd3aa72af9972e7d046b", | ||
}, | ||
{ | ||
input: "sha384:d3fc7881460b7e22e3d172954463dddd7866d17597e7248453c48b3e9d26d9596bf9c4a9cf8072c9d5bad76e19af801d", | ||
algorithm: "sha384", | ||
encoded: "d3fc7881460b7e22e3d172954463dddd7866d17597e7248453c48b3e9d26d9596bf9c4a9cf8072c9d5bad76e19af801d", | ||
}, | ||
{ | ||
input: "blake3:af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262", | ||
algorithm: "blake3", | ||
encoded: "af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262", | ||
}, | ||
{ | ||
// empty | ||
input: "", | ||
err: ErrDigestInvalidFormat, | ||
}, | ||
{ | ||
// whitespace only | ||
input: " ", | ||
err: ErrDigestInvalidFormat, | ||
}, | ||
{ | ||
// empty hex | ||
input: "sha256:", | ||
err: ErrDigestInvalidFormat, | ||
}, | ||
{ | ||
// hex with correct length, but whitespace only | ||
input: "sha256: ", | ||
err: ErrDigestInvalidFormat, | ||
}, | ||
{ | ||
// empty hex | ||
input: ":", | ||
err: ErrDigestInvalidFormat, | ||
}, | ||
{ | ||
// just hex | ||
input: "d41d8cd98f00b204e9800998ecf8427e", | ||
err: ErrDigestInvalidFormat, | ||
}, | ||
{ | ||
// not hex | ||
input: "sha256:d41d8cd98f00b204e9800m98ecf8427e", | ||
err: ErrDigestInvalidLength, | ||
}, | ||
{ | ||
// too short | ||
input: "sha256:abcdef0123456789", | ||
err: ErrDigestInvalidLength, | ||
}, | ||
{ | ||
// too short (from different algorithm) | ||
input: "sha512:abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789", | ||
err: ErrDigestInvalidLength, | ||
}, | ||
{ | ||
input: "foo:d41d8cd98f00b204e9800998ecf8427e", | ||
err: ErrDigestUnsupported, | ||
}, | ||
{ | ||
// repeated separators | ||
input: "sha384__foo+bar:d3fc7881460b7e22e3d172954463dddd7866d17597e7248453c48b3e9d26d9596bf9c4a9cf8072c9d5bad76e19af801d", | ||
err: ErrDigestInvalidFormat, | ||
}, | ||
{ | ||
// ensure that we parse, but we don't have support for the algorithm | ||
input: "sha384.foo+bar:d3fc7881460b7e22e3d172954463dddd7866d17597e7248453c48b3e9d26d9596bf9c4a9cf8072c9d5bad76e19af801d", | ||
algorithm: "sha384.foo+bar", | ||
encoded: "d3fc7881460b7e22e3d172954463dddd7866d17597e7248453c48b3e9d26d9596bf9c4a9cf8072c9d5bad76e19af801d", | ||
err: ErrDigestUnsupported, | ||
}, | ||
{ | ||
input: "sha384_foo+bar:d3fc7881460b7e22e3d172954463dddd7866d17597e7248453c48b3e9d26d9596bf9c4a9cf8072c9d5bad76e19af801d", | ||
algorithm: "sha384_foo+bar", | ||
encoded: "d3fc7881460b7e22e3d172954463dddd7866d17597e7248453c48b3e9d26d9596bf9c4a9cf8072c9d5bad76e19af801d", | ||
err: ErrDigestUnsupported, | ||
}, | ||
{ | ||
input: "sha256+b64:LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564", | ||
algorithm: "sha256+b64", | ||
encoded: "LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564", | ||
err: ErrDigestUnsupported, | ||
}, | ||
{ | ||
input: "sha256:E58FCF7418D4390DEC8E8FB69D88C06EC07039D651FEDD3AA72AF9972E7D046B", | ||
err: ErrDigestInvalidFormat, | ||
}, | ||
} { | ||
t.Run(testcase.input, func(t *testing.T) { | ||
digest, err := Parse(testcase.input) | ||
if err != testcase.err { | ||
t.Fatalf("error differed from expected while parsing %q: %v != %v", testcase.input, err, testcase.err) | ||
} | ||
|
||
if testcase.err != nil { | ||
return | ||
} | ||
|
||
if digest.Algorithm() != testcase.algorithm { | ||
t.Fatalf("incorrect algorithm for parsed digest: %q != %q", digest.Algorithm(), testcase.algorithm) | ||
} | ||
|
||
if digest.Encoded() != testcase.encoded { | ||
t.Fatalf("incorrect hex for parsed digest: %q != %q", digest.Encoded(), testcase.encoded) | ||
} | ||
|
||
// Parse string return value and check equality | ||
newParsed, err := Parse(digest.String()) | ||
|
||
if err != nil { | ||
t.Fatalf("unexpected error parsing input %q: %v", testcase.input, err) | ||
} | ||
|
||
if newParsed != digest { | ||
t.Fatalf("expected equal: %q != %q", newParsed, digest) | ||
} | ||
|
||
newFromHex := NewDigestFromEncoded(newParsed.Algorithm(), newParsed.Encoded()) | ||
if newFromHex != digest { | ||
t.Fatalf("%v != %v", newFromHex, digest) | ||
} | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/opencontainers/go-digest | ||
|
||
go 1.13 | ||
|
||
require github.com/zeebo/blake3 v0.2.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
github.com/zeebo/assert v1.1.0 h1:hU1L1vLTHsnO8x8c9KAR5GmM5QscxHg5RNU5z5qbUWY= | ||
github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0= | ||
github.com/zeebo/blake3 v0.1.1 h1:Nbsts7DdKThRHHd+YNlqiGlRqGEF2bE2eXN+xQ1hsEs= | ||
github.com/zeebo/blake3 v0.1.1/go.mod h1:G9pM4qQwjRzF1/v7+vabMj/c5mWpGZ2Wzo3Eb4z0pb4= | ||
github.com/zeebo/blake3 v0.2.0 h1:1SGx3IvKWFUU/xl+/7kjdcjjMcvVSm+3dMo/N42afC8= | ||
github.com/zeebo/blake3 v0.2.0/go.mod h1:G9pM4qQwjRzF1/v7+vabMj/c5mWpGZ2Wzo3Eb4z0pb4= | ||
github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0= | ||
github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= | ||
golang.org/x/sys v0.0.0-20201014080544-cc95f250f6bc h1:HVFDs9bKvTxP6bh1Rj9MCSo+UmafQtI8ZWDPVwVk9g4= | ||
golang.org/x/sys v0.0.0-20201014080544-cc95f250f6bc/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now at 0.2.4