Skip to content

Commit da0323b

Browse files
authored
Merge pull request #188 from hashicorp/export_checksum_file_code
export checksum code
2 parents bda54e2 + 025d982 commit da0323b

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

checksum.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
urlhelper "github.com/hashicorp/go-getter/helper/url"
2020
)
2121

22-
// fileChecksum helps verifying the checksum for a file.
23-
type fileChecksum struct {
22+
// FileChecksum helps verifying the checksum for a file.
23+
type FileChecksum struct {
2424
Type string
2525
Hash hash.Hash
2626
Value []byte
@@ -50,7 +50,7 @@ func (cerr *ChecksumError) Error() string {
5050

5151
// checksum is a simple method to compute the checksum of a source file
5252
// and compare it to the given expected value.
53-
func (c *fileChecksum) checksum(source string) error {
53+
func (c *FileChecksum) checksum(source string) error {
5454
f, err := os.Open(source)
5555
if err != nil {
5656
return fmt.Errorf("Failed to open file for checksum: %s", err)
@@ -74,7 +74,7 @@ func (c *fileChecksum) checksum(source string) error {
7474
return nil
7575
}
7676

77-
// extractChecksum will return a fileChecksum based on the 'checksum'
77+
// extractChecksum will return a FileChecksum based on the 'checksum'
7878
// parameter of u.
7979
// ex:
8080
// http://hashicorp.com/terraform?checksum=<checksumValue>
@@ -93,7 +93,7 @@ func (c *fileChecksum) checksum(source string) error {
9393
// <checksum> *file2
9494
//
9595
// see parseChecksumLine for more detail on checksum file parsing
96-
func (c *Client) extractChecksum(u *url.URL) (*fileChecksum, error) {
96+
func (c *Client) extractChecksum(u *url.URL) (*FileChecksum, error) {
9797
q := u.Query()
9898
v := q.Get("checksum")
9999

@@ -115,14 +115,14 @@ func (c *Client) extractChecksum(u *url.URL) (*fileChecksum, error) {
115115

116116
switch checksumType {
117117
case "file":
118-
return c.checksumFromFile(checksumValue, u)
118+
return c.ChecksumFromFile(checksumValue, u)
119119
default:
120120
return newChecksumFromType(checksumType, checksumValue, filepath.Base(u.EscapedPath()))
121121
}
122122
}
123123

124-
func newChecksum(checksumValue, filename string) (*fileChecksum, error) {
125-
c := &fileChecksum{
124+
func newChecksum(checksumValue, filename string) (*FileChecksum, error) {
125+
c := &FileChecksum{
126126
Filename: filename,
127127
}
128128
var err error
@@ -133,7 +133,7 @@ func newChecksum(checksumValue, filename string) (*fileChecksum, error) {
133133
return c, nil
134134
}
135135

136-
func newChecksumFromType(checksumType, checksumValue, filename string) (*fileChecksum, error) {
136+
func newChecksumFromType(checksumType, checksumValue, filename string) (*FileChecksum, error) {
137137
c, err := newChecksum(checksumValue, filename)
138138
if err != nil {
139139
return nil, err
@@ -157,7 +157,7 @@ func newChecksumFromType(checksumType, checksumValue, filename string) (*fileChe
157157
return c, nil
158158
}
159159

160-
func newChecksumFromValue(checksumValue, filename string) (*fileChecksum, error) {
160+
func newChecksumFromValue(checksumValue, filename string) (*FileChecksum, error) {
161161
c, err := newChecksum(checksumValue, filename)
162162
if err != nil {
163163
return nil, err
@@ -183,14 +183,14 @@ func newChecksumFromValue(checksumValue, filename string) (*fileChecksum, error)
183183
return c, nil
184184
}
185185

186-
// checksumsFromFile will return all the fileChecksums found in file
186+
// ChecksumFromFile will return all the FileChecksums found in file
187187
//
188-
// checksumsFromFile will try to guess the hashing algorithm based on content
188+
// ChecksumFromFile will try to guess the hashing algorithm based on content
189189
// of checksum file
190190
//
191-
// checksumsFromFile will only return checksums for files that match file
191+
// ChecksumFromFile will only return checksums for files that match file
192192
// behind src
193-
func (c *Client) checksumFromFile(checksumFile string, src *url.URL) (*fileChecksum, error) {
193+
func (c *Client) ChecksumFromFile(checksumFile string, src *url.URL) (*FileChecksum, error) {
194194
checksumFileURL, err := urlhelper.Parse(checksumFile)
195195
if err != nil {
196196
return nil, err
@@ -286,7 +286,7 @@ func (c *Client) checksumFromFile(checksumFile string, src *url.URL) (*fileCheck
286286
// of a line.
287287
// for BSD type sums parseChecksumLine guesses the hashing algorithm
288288
// by checking the length of the checksum.
289-
func parseChecksumLine(line string) (*fileChecksum, error) {
289+
func parseChecksumLine(line string) (*FileChecksum, error) {
290290
parts := strings.Fields(line)
291291

292292
switch len(parts) {

0 commit comments

Comments
 (0)