Skip to content

Commit

Permalink
digest: allow validation of urlsafe base64 encoding
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen J Day <stephen.day@docker.com>
  • Loading branch information
stevvooe committed May 10, 2017
1 parent 55f6758 commit 678a95e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewDigestFromEncoded(alg Algorithm, encoded string) Digest {
}

// DigestRegexp matches valid digest types.
var DigestRegexp = regexp.MustCompile(`[a-z0-9]+(?:[.+_-][a-z0-9]+)*:[a-zA-Z0-9]+`)
var DigestRegexp = regexp.MustCompile(`[a-z0-9]+(?:[.+_-][a-z0-9]+)*:[a-zA-Z0-9=_-]+`)

// DigestRegexpAnchored matches valid digest types, anchored to the start and end of the match.
var DigestRegexpAnchored = regexp.MustCompile(`^` + DigestRegexp.String() + `$`)
Expand Down
6 changes: 6 additions & 0 deletions digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func TestParseDigest(t *testing.T) {
encoded: "d3fc7881460b7e22e3d172954463dddd7866d17597e7248453c48b3e9d26d9596bf9c4a9cf8072c9d5bad76e19af801d",
err: ErrDigestUnsupported,
},
{
input: "sha256+b64:LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564",
algorithm: "sha256+b64",
encoded: "LCa0a2j_xo_5m0U8HTBBNBNCLXBkg7-g-YpeiGJm564",
err: ErrDigestUnsupported,
},
} {
digest, err := Parse(testcase.input)
if err != testcase.err {
Expand Down

0 comments on commit 678a95e

Please sign in to comment.