Documentation
¶
Overview ¶
Package mpctest provides insecure transport helpers for tests and local demos.
WARNING: This package is not a production transport. The in-memory helpers provide no authentication, no confidentiality, and no cross-process networking. Production applications should implement `mpc.Transport` with an authenticated and confidential transport such as mTLS.
Index ¶
- type MaliciousBehavior
- type MaliciousTransport
- func (m *MaliciousTransport) Close() error
- func (m *MaliciousTransport) MyIndex() int
- func (m *MaliciousTransport) PartyCount() int
- func (m *MaliciousTransport) Receive(ctx context.Context, fromParty int) ([]byte, error)
- func (m *MaliciousTransport) ReceiveAll(ctx context.Context, fromParties []int) ([][]byte, error)
- func (m *MaliciousTransport) Send(ctx context.Context, toParty int, msg []byte) error
- type MockTransport
- func (s *MockTransport) Close() error
- func (s *MockTransport) MyIndex() int
- func (s *MockTransport) PartyCount() int
- func (s *MockTransport) Receive(ctx context.Context, fromParty int) ([]byte, error)
- func (s *MockTransport) ReceiveAll(ctx context.Context, fromParties []int) ([][]byte, error)
- func (s *MockTransport) Send(_ context.Context, toParty int, msg []byte) error
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MaliciousBehavior ¶
type MaliciousBehavior struct {
// DropAllSends drops all outgoing messages (simulates a network partition).
DropAllSends bool
// DropAllReceives fails all receive operations.
DropAllReceives bool
// CorruptMessages modifies message contents before sending.
CorruptMessages bool
// SendWrongSize sends messages with incorrect size.
SendWrongSize bool
// FailAfterNSends fails after N send operations.
FailAfterNSends int
// FailAfterNReceives fails after N receive operations.
FailAfterNReceives int
// SendEmptyMessages sends empty messages instead of real data.
SendEmptyMessages bool
// SendGarbage sends all-0xFF garbage instead of protocol messages.
SendGarbage bool
// ReplayFirstMessage replays the first sent message repeatedly.
ReplayFirstMessage bool
// FlipRandomBits flips a bit in the middle of the message.
FlipRandomBits bool
// contains filtered or unexported fields
}
MaliciousBehavior defines what kind of malicious action to perform.
type MaliciousTransport ¶
type MaliciousTransport struct {
// contains filtered or unexported fields
}
MaliciousTransport wraps a normal transport with adversarial behavior for tests.
func NewMaliciousTransport ¶
func NewMaliciousTransport(inner Transport, behavior MaliciousBehavior) *MaliciousTransport
NewMaliciousTransport wraps a transport with malicious behavior.
func (*MaliciousTransport) Close ¶
func (m *MaliciousTransport) Close() error
Close implements Transport.Close.
func (*MaliciousTransport) MyIndex ¶
func (m *MaliciousTransport) MyIndex() int
MyIndex exposes the wrapped transport's local index when available.
func (*MaliciousTransport) PartyCount ¶
func (m *MaliciousTransport) PartyCount() int
PartyCount exposes the wrapped transport's party count when available.
func (*MaliciousTransport) ReceiveAll ¶
ReceiveAll implements Transport.ReceiveAll with malicious behavior.
type MockTransport ¶
type MockTransport struct {
// contains filtered or unexported fields
}
MockTransport provides an in-memory transport implementation for tests and local demos. It intentionally provides no authentication or confidentiality.
func NewMockNetwork ¶
func NewMockNetwork(nParties int) []*MockTransport
NewMockNetwork creates a complete mock network for tests and local demos. It returns a slice of MockTransport instances, one for each party.
func NewMockTransport ¶
func NewMockTransport(myIndex int) *MockTransport
NewMockTransport creates a new MockTransport for the specified party index.
func (*MockTransport) Close ¶
func (s *MockTransport) Close() error
Close closes the session and unblocks any waiting receives.
func (*MockTransport) MyIndex ¶
func (s *MockTransport) MyIndex() int
MyIndex returns this party's index.
func (*MockTransport) PartyCount ¶
func (s *MockTransport) PartyCount() int
PartyCount returns the total number of parties.
func (*MockTransport) ReceiveAll ¶
ReceiveAll receives messages from multiple parties concurrently.
type Transport ¶
type Transport interface {
io.Closer
Send(ctx context.Context, toParty int, msg []byte) error
Receive(ctx context.Context, fromParty int) ([]byte, error)
ReceiveAll(ctx context.Context, fromParties []int) ([][]byte, error)
}
Transport mirrors the network contract used by interactive MPC protocols. Concrete types in this package also satisfy `mpc.Transport`.
func NewMaliciousNetwork ¶
func NewMaliciousNetwork(nParties int, maliciousParty int, behavior MaliciousBehavior) []Transport
NewMaliciousNetwork creates a mock network where one party is malicious.