-
Notifications
You must be signed in to change notification settings - Fork 31
/
doc_test.go
64 lines (54 loc) · 2.05 KB
/
doc_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
58
59
60
61
62
63
64
// Copyright © 2018 Nik Unger
//
// This file is part of The PBC Go Wrapper.
//
// The PBC Go Wrapper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// The PBC Go Wrapper is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with The PBC Go Wrapper. If not, see <http://www.gnu.org/licenses/>.
//
// The PBC Go Wrapper makes use of The PBC library. The PBC Library and its use
// are covered under the terms of the GNU Lesser General Public License
// version 3, or (at your option) any later version.
package pbc_test
import (
"fmt"
"github.com/Nik-U/pbc"
)
// This example generates a pairing and some random group elements, then applies
// the pairing operation.
func Example() {
// In a real application, generate this once and publish it
params := pbc.GenerateA(160, 512)
pairing := params.NewPairing()
// Initialize group elements. pbc automatically handles garbage collection.
g := pairing.NewG1()
h := pairing.NewG2()
x := pairing.NewGT()
// Generate random group elements and pair them
g.Rand()
h.Rand()
fmt.Printf("g = %s\n", g)
fmt.Printf("h = %s\n", h)
x.Pair(g, h)
fmt.Printf("e(g,h) = %s\n", x)
}
// This example displays an element in a variety of formats.
func ExampleElement_Format() {
var element *pbc.Element
// ...populate element...
fmt.Printf("%v", element) // Print in PBC format
fmt.Printf("%s", element) // Same as above
fmt.Printf("%36v", element) // Print in PBC format, base 36
fmt.Printf("%#v", element) // Print metadata about element
fmt.Printf("%d", element) // Print with Go
fmt.Printf("%010o", element) // Print with Go, zero-padded width-10 octal
}