-
Notifications
You must be signed in to change notification settings - Fork 13
/
dummy.go
50 lines (38 loc) · 1.25 KB
/
dummy.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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package crypto
import (
"bytes"
"fmt"
t "github.com/filecoin-project/mir/pkg/types"
)
// TODO: Write comments.
// DummyCrypto represents a dummy MirModule module that
// always produces the same dummy byte slice specified at instantiation as signature.
// Verification of this dummy signature always succeeds.
// This is intended as a stub for testing purposes.
type DummyCrypto struct {
// The only accepted signature
DummySig []byte
}
// Sign always returns the dummy signature DummySig, regardless of the data.
func (dc *DummyCrypto) Sign(data [][]byte) ([]byte, error) {
return dc.DummySig, nil
}
// RegisterNodeKey does nothing, as no public keys are used.
func (dc *DummyCrypto) RegisterNodeKey(pubKey []byte, nodeID t.NodeID) error {
return nil
}
// DeleteNodeKey does nothing, as no public keys are used.
func (dc *DummyCrypto) DeleteNodeKey(nodeID t.NodeID) {
}
// Verify returns nil (i.e. success) only if signature equals DummySig.
// Both data and nodeID are ignored.
func (dc *DummyCrypto) Verify(data [][]byte, signature []byte, nodeID t.NodeID) error {
if !bytes.Equal(signature, dc.DummySig) {
return fmt.Errorf("dummy signature mismatch")
}
return nil
}