-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stdlibs): import crypto/sha256 (#580)
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package sha256 | ||
|
||
import ( | ||
isha256 "internal/crypto/sha256" | ||
) | ||
|
||
const Size = 32 | ||
|
||
// Sum returns the SHA-256 checksum of the data. | ||
func Sum256(data []byte) [Size]byte { | ||
return isha256.Sum256(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package sha256 | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"std" | ||
"testing" | ||
) | ||
|
||
func TestSha256Sum(t *testing.T) { | ||
got := sha256.Sum256([]byte("sha256 this string"))[:] | ||
expected := "1af1dfa857bf1d8814fe1af8983c18080019922e557f15a8a0d3db739d77aacb" | ||
|
||
if hex.EncodeToString(got) != expected { | ||
t.Errorf("got %v(%T), expected %v(%T)", hex.EncodeToString(got), got, expected, expected) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package sha256 | ||
|
||
// XXX injected via stdlibs/stdlibs.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters