Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
186e9509
Commit
186e9509
authored
Jul 14, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/common: support sha1/sha256 hashes
parent
ec2e347f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
+32
-0
builder/common/download.go
builder/common/download.go
+6
-0
builder/common/download_test.go
builder/common/download_test.go
+26
-0
No files found.
builder/common/download.go
View file @
186e9509
...
@@ -3,6 +3,8 @@ package common
...
@@ -3,6 +3,8 @@ package common
import
(
import
(
"bytes"
"bytes"
"crypto/md5"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
"encoding/hex"
"errors"
"errors"
"fmt"
"fmt"
...
@@ -53,6 +55,10 @@ func HashForType(t string) hash.Hash {
...
@@ -53,6 +55,10 @@ func HashForType(t string) hash.Hash {
switch
t
{
switch
t
{
case
"md5"
:
case
"md5"
:
return
md5
.
New
()
return
md5
.
New
()
case
"sha1"
:
return
sha1
.
New
()
case
"sha256"
:
return
sha256
.
New
()
default
:
default
:
return
nil
return
nil
}
}
...
...
builder/common/download_test.go
View file @
186e9509
...
@@ -55,6 +55,32 @@ func TestHashForType(t *testing.T) {
...
@@ -55,6 +55,32 @@ func TestHashForType(t *testing.T) {
}
}
}
}
if
h
:=
HashForType
(
"sha1"
);
h
==
nil
{
t
.
Fatalf
(
"sha1 hash is nil"
)
}
else
{
h
.
Write
([]
byte
(
"foo"
))
result
:=
h
.
Sum
(
nil
)
expected
:=
"0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"
actual
:=
hex
.
EncodeToString
(
result
)
if
actual
!=
expected
{
t
.
Fatalf
(
"bad hash: %s"
,
actual
)
}
}
if
h
:=
HashForType
(
"sha256"
);
h
==
nil
{
t
.
Fatalf
(
"sha256 hash is nil"
)
}
else
{
h
.
Write
([]
byte
(
"foo"
))
result
:=
h
.
Sum
(
nil
)
expected
:=
"2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"
actual
:=
hex
.
EncodeToString
(
result
)
if
actual
!=
expected
{
t
.
Fatalf
(
"bad hash: %s"
,
actual
)
}
}
if
HashForType
(
"fake"
)
!=
nil
{
if
HashForType
(
"fake"
)
!=
nil
{
t
.
Fatalf
(
"fake hash is not nil"
)
t
.
Fatalf
(
"fake hash is not nil"
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment