-
Notifications
You must be signed in to change notification settings - Fork 199
/
point.go
122 lines (98 loc) · 3.04 KB
/
point.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package cryptoMocks
import (
"github.com/multiversx/mx-chain-crypto-go"
)
// PointMock represents a mock implementation for a Point
type PointMock struct {
X int
Y int
GetUnderlyingObjStub func() interface{}
MarshalBinaryStub func(x, y int) ([]byte, error)
UnmarshalBinaryStub func([]byte) (x, y int, err error)
}
// Equal tests if receiver is equal with the Point p given as parameter.
// Both Points need to be derived from the same Group
func (po *PointMock) Equal(p crypto.Point) (bool, error) {
pp, ok := p.(*PointMock)
if !ok {
return false, crypto.ErrInvalidParam
}
return pp.X == po.X && pp.Y == po.Y, nil
}
// Null returns the neutral identity element.
func (po *PointMock) Null() crypto.Point {
panic("implement me")
}
// Base returns the Group's base point.
func (po *PointMock) Base() crypto.Point {
pp := &PointMock{
X: 1,
Y: 1,
UnmarshalBinaryStub: po.UnmarshalBinaryStub,
MarshalBinaryStub: po.MarshalBinaryStub,
}
return pp
}
// Set sets the receiver equal to another Point p.
func (po *PointMock) Set(_ crypto.Point) error {
panic("implement me")
}
// Clone returns a clone of the receiver.
func (po *PointMock) Clone() crypto.Point {
panic("implement me")
}
// Add returns the result of adding receiver with Point p given as parameter,
// so that their scalars add homomorphically
func (po *PointMock) Add(_ crypto.Point) (crypto.Point, error) {
panic("implement me")
}
// Sub returns the result of subtracting from receiver the Point p given as parameter,
// so that their scalars subtract homomorphically
func (po *PointMock) Sub(_ crypto.Point) (crypto.Point, error) {
panic("implement me")
}
// Neg returns the negation of receiver
func (po *PointMock) Neg() crypto.Point {
panic("implement me")
}
// Mul returns the result of multiplying receiver by the scalar s.
// Mock multiplies the scalar to both X and Y fields
func (po *PointMock) Mul(s crypto.Scalar) (crypto.Point, error) {
if s == nil {
return nil, crypto.ErrInvalidParam
}
ss, _ := s.(*ScalarMock)
pp := &PointMock{
X: po.X * ss.X,
Y: po.Y * ss.X,
UnmarshalBinaryStub: po.UnmarshalBinaryStub,
MarshalBinaryStub: po.MarshalBinaryStub,
}
return pp, nil
}
// Pick returns a fresh random or pseudo-random Point.
func (po *PointMock) Pick() (crypto.Point, error) {
panic("implement me")
}
// GetUnderlyingObj returns the object the implementation wraps
func (po *PointMock) GetUnderlyingObj() interface{} {
if po.GetUnderlyingObjStub != nil {
return po.GetUnderlyingObjStub()
}
return 0
}
// MarshalBinary transforms the Point into a byte array
func (po *PointMock) MarshalBinary() ([]byte, error) {
return po.MarshalBinaryStub(po.X, po.Y)
}
// UnmarshalBinary recreates the Point from a byte array
func (po *PointMock) UnmarshalBinary(point []byte) error {
x, y, err := po.UnmarshalBinaryStub(point)
po.X = x
po.Y = y
return err
}
// IsInterfaceNil returns true if there is no value under the interface
func (po *PointMock) IsInterfaceNil() bool {
return po == nil
}