-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
57 lines (44 loc) · 1.23 KB
/
example_test.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package srp
import (
"crypto"
"fmt"
)
func ExampleSRP_default() {
c, _ := NewDefaultClient("jane_doe_123", "my-password")
s, _ := NewDefaultServer()
// Client salt and verifier and returns public key.
_, salt, verifier, _ := c.Enroll()
username, pubKeyA := c.Auth()
// Server processes auth credentials
pubKeyB, saltB, _ := s.ProcessAuth(username, salt, pubKeyA, verifier)
clientProof, err := c.ProveIdentity(pubKeyB, saltB)
fmt.Println(err)
serverProof, err := s.ProcessProof(clientProof)
fmt.Println(err)
ok := c.IsProofValid(serverProof)
fmt.Println(ok)
// Output:
// <nil>
// <nil>
// true
}
func ExampleSRP_specifyGroupAndHash() {
g, _ := NewGroup(Group8192)
c, _ := NewClient(crypto.SHA512, g, "jane_doe_123", "my-password")
s, _ := NewServer(crypto.SHA512, g)
// Client salt and verifier and returns public key.
_, salt, verifier, _ := c.Enroll()
username, pubKeyA := c.Auth()
// Server processes auth credentials
pubKeyB, saltB, _ := s.ProcessAuth(username, salt, pubKeyA, verifier)
clientProof, err := c.ProveIdentity(pubKeyB, saltB)
fmt.Println(err)
serverProof, err := s.ProcessProof(clientProof)
fmt.Println(err)
ok := c.IsProofValid(serverProof)
fmt.Println(ok)
// Output:
// <nil>
// <nil>
// true
}