-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample_test.go
More file actions
34 lines (28 loc) · 758 Bytes
/
Copy pathexample_test.go
File metadata and controls
34 lines (28 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package alg_test
import (
"encoding/hex"
"fmt"
"io"
"log"
"github.com/mdlayher/alg"
)
func ExampleConn_hashSHA1() {
// Dial the kernel using AF_ALG sockets. The socket must be closed when it
// is no longer needed.
c, err := alg.Dial(alg.SHA1())
if err != nil {
log.Fatalf("failed to dial kernel: %v", err)
}
defer c.Close()
// Retrieve a hash handle from the kernel. This can be used the same as any
// other hash.Hash, but must also be closed when it is no longer needed.
h, err := c.Hash()
if err != nil {
log.Fatalf("failed to create hash: %v", err)
}
defer h.Close()
if _, err := io.WriteString(h, "hello, world"); err != nil {
log.Fatalf("failed to hash string: %v", err)
}
fmt.Println(hex.EncodeToString(h.Sum(nil)))
}