Skip to content

Commit

Permalink
Fix different checksum calculation in RecordArtifact
Browse files Browse the repository at this point in the history
This adds a bytes.ReplaceAll directive in the RecordArtifact function,
that replaces all CRLF line separators with LF line separators.
We see LF line separators as our normalized format.
  • Loading branch information
shibumi committed Aug 26, 2020
1 parent 18a4116 commit 04b13d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 4 additions & 0 deletions in_toto/runlib.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package in_toto

import (
"bytes"
"errors"
"io/ioutil"
"os"
Expand Down Expand Up @@ -41,6 +42,9 @@ func RecordArtifact(path string) (map[string]interface{}, error) {
if err != nil {
return nil, err
}
// "Normalize" file contents. We convert all line separators to '\n'
// for keeping operating system independence
contents = bytes.ReplaceAll(contents, []byte("\r\n"), []byte("\n"))

// Create a map of all the hashes present in the hash_func list
hashFunc := []string{"sha256"}
Expand Down
1 change: 0 additions & 1 deletion test/data/.gitattributes

This file was deleted.

2 comments on commit 04b13d5

@lukpueh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool stuff. FYI, the reference implementation provides a flag to toggle this (see in-toto/in-toto#230). I don't think this is necessary for now, but we should definitely document the behavior in RecordArtifact's docstring.

@shibumi
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukpueh I have added a few sentences in the RecordArtifact docstrings. You might want to have a look :)

Please sign in to comment.