File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ var commands = []Command{
2121 {name : "eval" , desc : "evaluates it" , fn : evaluate },
2222 {name : "type" , desc : "infers its type" , fn : inferType },
2323 {name : "push" , desc : "pushes it to the server" , fn : pushScrap },
24+ {name : "hash" , desc : "prints its sha256 hash" , fn : hashScrap },
2425}
2526
2627var (
@@ -102,3 +103,10 @@ func pushScrap(args []string) {
102103 key := must (env .Push (scrap ))
103104 fmt .Println (key )
104105}
106+
107+ func hashScrap (args []string ) {
108+ input := must (io .ReadAll (os .Stdin ))
109+ env := makeEnv ()
110+ scrap := must (env .Read (input ))
111+ fmt .Println (scrap .Sha256 ())
112+ }
Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ type Scrap struct {
1717 value Value
1818}
1919
20+ func (s Scrap ) Sha256 () string {
21+ return fmt .Sprintf ("%x" , sha256 .Sum256 (s .expr .Source .Bytes ()))
22+ }
23+
2024type Sha256Hash = [32 ]byte
2125
2226type Environment struct {
You can’t perform that action at this time.
0 commit comments