Source file
src/crypto/sha1/example_test.go
1
2
3
4
5 package sha1_test
6
7 import (
8 "crypto/sha1"
9 "fmt"
10 "io"
11 "log"
12 "os"
13 )
14
15 func ExampleNew() {
16 h := sha1.New()
17 io.WriteString(h, "His money is twice tainted:")
18 io.WriteString(h, " 'taint yours and 'taint mine.")
19 fmt.Printf("% x", h.Sum(nil))
20
21 }
22
23 func ExampleSum() {
24 data := []byte("This page intentionally left blank.")
25 fmt.Printf("% x", sha1.Sum(data))
26
27 }
28
29 func ExampleNew_file() {
30 f, err := os.Open("file.txt")
31 if err != nil {
32 log.Fatal(err)
33 }
34 defer f.Close()
35
36 h := sha1.New()
37 if _, err := io.Copy(h, f); err != nil {
38 log.Fatal(err)
39 }
40
41 fmt.Printf("% x", h.Sum(nil))
42 }
43
View as plain text