Skip to content

Commit

Permalink
Merge pull request #188 from hashicorp/export_checksum_file_code
Browse files Browse the repository at this point in the history
export checksum code
  • Loading branch information
SwampDragons authored Jun 27, 2019
2 parents bda54e2 + 025d982 commit da0323b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
urlhelper "github.com/hashicorp/go-getter/helper/url"
)

// fileChecksum helps verifying the checksum for a file.
type fileChecksum struct {
// FileChecksum helps verifying the checksum for a file.
type FileChecksum struct {
Type string
Hash hash.Hash
Value []byte
Expand Down Expand Up @@ -50,7 +50,7 @@ func (cerr *ChecksumError) Error() string {

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

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

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

switch checksumType {
case "file":
return c.checksumFromFile(checksumValue, u)
return c.ChecksumFromFile(checksumValue, u)
default:
return newChecksumFromType(checksumType, checksumValue, filepath.Base(u.EscapedPath()))
}
}

func newChecksum(checksumValue, filename string) (*fileChecksum, error) {
c := &fileChecksum{
func newChecksum(checksumValue, filename string) (*FileChecksum, error) {
c := &FileChecksum{
Filename: filename,
}
var err error
Expand All @@ -133,7 +133,7 @@ func newChecksum(checksumValue, filename string) (*fileChecksum, error) {
return c, nil
}

func newChecksumFromType(checksumType, checksumValue, filename string) (*fileChecksum, error) {
func newChecksumFromType(checksumType, checksumValue, filename string) (*FileChecksum, error) {
c, err := newChecksum(checksumValue, filename)
if err != nil {
return nil, err
Expand All @@ -157,7 +157,7 @@ func newChecksumFromType(checksumType, checksumValue, filename string) (*fileChe
return c, nil
}

func newChecksumFromValue(checksumValue, filename string) (*fileChecksum, error) {
func newChecksumFromValue(checksumValue, filename string) (*FileChecksum, error) {
c, err := newChecksum(checksumValue, filename)
if err != nil {
return nil, err
Expand All @@ -183,14 +183,14 @@ func newChecksumFromValue(checksumValue, filename string) (*fileChecksum, error)
return c, nil
}

// checksumsFromFile will return all the fileChecksums found in file
// ChecksumFromFile will return all the FileChecksums found in file
//
// checksumsFromFile will try to guess the hashing algorithm based on content
// ChecksumFromFile will try to guess the hashing algorithm based on content
// of checksum file
//
// checksumsFromFile will only return checksums for files that match file
// ChecksumFromFile will only return checksums for files that match file
// behind src
func (c *Client) checksumFromFile(checksumFile string, src *url.URL) (*fileChecksum, error) {
func (c *Client) ChecksumFromFile(checksumFile string, src *url.URL) (*FileChecksum, error) {
checksumFileURL, err := urlhelper.Parse(checksumFile)
if err != nil {
return nil, err
Expand Down Expand Up @@ -286,7 +286,7 @@ func (c *Client) checksumFromFile(checksumFile string, src *url.URL) (*fileCheck
// of a line.
// for BSD type sums parseChecksumLine guesses the hashing algorithm
// by checking the length of the checksum.
func parseChecksumLine(line string) (*fileChecksum, error) {
func parseChecksumLine(line string) (*FileChecksum, error) {
parts := strings.Fields(line)

switch len(parts) {
Expand Down

0 comments on commit da0323b

Please sign in to comment.