-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.go
134 lines (103 loc) · 3.71 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
123
124
125
126
127
128
129
130
131
132
133
134
package ed25519
import (
"bytes"
"crypto/ed25519"
crypto "github.com/ThotaGopichandThota/gn-crypto1"
"github.com/ThotaGopichandThota/gn-core3/core/check"
)
var _ crypto.Point = (*ed25519Point)(nil)
// ed25519 - is a mapping over crypto/ed25519 public key
// Most of the implementations of the Point interface functions are mocked
//
// since the implementation details edwards25519 are internal to the crypto/ed25519 package
type ed25519Point struct {
ed25519.PublicKey
}
// Equal tests if receiver is equal with the Point p given as parameter.
func (ep *ed25519Point) Equal(p crypto.Point) (bool, error) {
if check.IfNil(p) {
return false, crypto.ErrNilParam
}
ed25519P, ok := p.(*ed25519Point)
if !ok {
return false, crypto.ErrInvalidPublicKey
}
return bytes.Equal(ep.PublicKey, ed25519P.PublicKey), nil
}
// GetUnderlyingObj returns the object the implementation wraps
func (ep *ed25519Point) GetUnderlyingObj() interface{} {
return ep.PublicKey
}
// MarshalBinary converts the point into its byte array representation
func (ep *ed25519Point) MarshalBinary() ([]byte, error) {
return ep.PublicKey, nil
}
// UnmarshalBinary reconstructs a point from its byte array representation
func (ep *ed25519Point) UnmarshalBinary(point []byte) error {
ep.PublicKey = point
return nil
}
// Set sets the receiver equal to another Point p.
func (ep *ed25519Point) Set(p crypto.Point) error {
if check.IfNil(p) {
return crypto.ErrNilParam
}
point, ok := p.(*ed25519Point)
if !ok {
return crypto.ErrInvalidPublicKey
}
ep.PublicKey = point.PublicKey
return nil
}
// Clone returns a clone of the receiver.
func (ep *ed25519Point) Clone() crypto.Point {
publicKeyBytes := make([]byte, len(ep.PublicKey))
copy(publicKeyBytes, ep.PublicKey)
return &ed25519Point{publicKeyBytes}
}
// Null is not needed for this use case, should be removed if possible
func (ep *ed25519Point) Null() crypto.Point {
log.Error("ed25519Point",
"message", "Null for ed25519Point is not implemented, should not be called")
return nil
}
// Base is not needed for this use case, should be removed if possible
func (ep *ed25519Point) Base() crypto.Point {
log.Error("ed25519Point",
"message", "Base for ed25519Point is not implemented, should not be called")
return nil
}
// Add is not needed for this use case, should be removed if possible
func (ep *ed25519Point) Add(_ crypto.Point) (crypto.Point, error) {
log.Error("ed25519Point",
"message", "Add for ed25519Point is not implemented, should not be called")
return nil, crypto.ErrNotImplemented
}
// Sub is not needed for this use case, should be removed if possible
func (ep *ed25519Point) Sub(_ crypto.Point) (crypto.Point, error) {
log.Error("ed25519Point",
"message", "Sub for ed25519Point is not implemented, should not be called")
return nil, crypto.ErrNotImplemented
}
// Neg is not needed for this use case, should be removed if possible
func (ep *ed25519Point) Neg() crypto.Point {
log.Error("ed25519Point",
"message", "Neg for ed25519Point is not implemented, should not be called")
return nil
}
// Mul is not needed for this use case, should be removed if possible
func (ep *ed25519Point) Mul(_ crypto.Scalar) (crypto.Point, error) {
log.Error("ed25519Point",
"message", "Mul for ed25519Point is not implemented, should not be called")
return nil, crypto.ErrNotImplemented
}
// Pick is not needed for this use case, should be removed if possible
func (ep *ed25519Point) Pick() (crypto.Point, error) {
log.Error("ed25519Point",
"message", "Pick for ed25519Point is not implemented, should not be called")
return nil, crypto.ErrNotImplemented
}
// IsInterfaceNil returns true if there is no value under the interface
func (ep *ed25519Point) IsInterfaceNil() bool {
return ep == nil
}