github.com/emmansun/gmsm@v0.29.1/sm3/example_test.go (about) 1 package sm3_test 2 3 import ( 4 "fmt" 5 "io" 6 "log" 7 "os" 8 9 "github.com/emmansun/gmsm/sm3" 10 ) 11 12 func ExampleSum() { 13 sum := sm3.Sum([]byte("hello world\n")) 14 fmt.Printf("%x", sum) 15 // Output: 4cc2036b86431b5d2685a04d289dfe140a36baa854b01cb39fcd6009638e4e7a 16 } 17 18 func ExampleNew() { 19 h := sm3.New() 20 h.Write([]byte("hello world\n")) 21 fmt.Printf("%x", h.Sum(nil)) 22 // Output: 4cc2036b86431b5d2685a04d289dfe140a36baa854b01cb39fcd6009638e4e7a 23 } 24 25 func ExampleNew_file() { 26 f, err := os.Open("file.txt") 27 if err != nil { 28 log.Fatal(err) 29 } 30 defer f.Close() 31 32 h := sm3.New() 33 if _, err := io.Copy(h, f); err != nil { 34 log.Fatal(err) 35 } 36 37 fmt.Printf("%x", h.Sum(nil)) 38 }