-
Notifications
You must be signed in to change notification settings - Fork 0
/
none.go
36 lines (30 loc) · 800 Bytes
/
none.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
package algorithms
import ()
type noneAlg algorithm
// List of "none" algorithms.
var (
AlgorithmNone = &noneAlg{name: "none"}
)
// Sign returns an empty byte array if no key was given. Otherwise an error is
// returned.
func (n noneAlg) Sign(data string, key []byte) ([]byte, error) {
if key != nil && len(key) != 0 {
return nil, ErrNoneKey
}
return []byte(""), nil
}
// Valid returns nil if no key was given and the signature is nil or empty.
// Otherwise an error is returned.
func (n noneAlg) Valid(data string, signature, key []byte) error {
if key != nil && len(key) != 0 {
return ErrNoneKey
}
if signature != nil && len(signature) != 0 {
return ErrSignatureLength
}
return nil
}
// Name returns the name of the algorithm.
func (n noneAlg) Name() string {
return n.name
}