github.com/insolar/x-crypto@v0.0.0-20191031140942-75fab8a325f6/sha1/example_test.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package sha1_test 6 7 import ( 8 "fmt" 9 "github.com/insolar/x-crypto/sha1" 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 // Output: 59 7f 6a 54 00 10 f9 4c 15 d7 18 06 a9 9a 2c 87 10 e7 47 bd 21 } 22 23 func ExampleSum() { 24 data := []byte("This page intentionally left blank.") 25 fmt.Printf("% x", sha1.Sum(data)) 26 // Output: af 06 49 23 bb f2 30 15 96 aa c4 c2 73 ba 32 17 8e bc 4a 96 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 }