Skip to content

Commit

Permalink
zmq4: evolve Security interface to support PLAIN and CURVE
Browse files Browse the repository at this point in the history
Updates #25.
Updates #26.
  • Loading branch information
sbinet committed Jul 4, 2018
1 parent a234d3a commit 4faa4ae
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (conn *Conn) init(sec Security, md map[string]string) error {
return errors.Wrapf(err, "zmq4: could not exchange greetings")
}

err = conn.sec.Handshake()
err = conn.sec.Handshake(conn, conn.server)
if err != nil {
return errors.Wrapf(err, "zmq4: could not perform security handshake")
}
Expand Down
6 changes: 4 additions & 2 deletions security.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import (

// Security is an interface for ZMTP security mechanisms
type Security interface {
// Type returns the security mechanism type.
Type() SecurityType

// Handshake implements the ZMTP security handshake according to
// this security mechanism.
// see:
// https://rfc.zeromq.org/spec:23/ZMTP/
// https://rfc.zeromq.org/spec:24/ZMTP-PLAIN/
// https://rfc.zeromq.org/spec:25/ZMTP-CURVE/
Handshake() error
Handshake(conn *Conn, server bool) error

// Encrypt writes the encrypted form of data to w.
Encrypt(w io.Writer, data []byte) (int, error)
Expand Down Expand Up @@ -58,7 +60,7 @@ func (nullSecurity) Type() SecurityType {
// https://rfc.zeromq.org/spec:23/ZMTP/
// https://rfc.zeromq.org/spec:24/ZMTP-PLAIN/
// https://rfc.zeromq.org/spec:25/ZMTP-CURVE/
func (nullSecurity) Handshake() error {
func (nullSecurity) Handshake(conn *Conn, server bool) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion security/null/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (security) Type() zmq4.SecurityType {
// https://rfc.zeromq.org/spec:23/ZMTP/
// https://rfc.zeromq.org/spec:24/ZMTP-PLAIN/
// https://rfc.zeromq.org/spec:25/ZMTP-CURVE/
func (security) Handshake() error {
func (security) Handshake(conn *zmq4.Conn, server bool) error {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions security/null/null_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"github.com/go-zeromq/zmq4/security/null"
)

func TestNullSecurity(t *testing.T) {
func TestSecurity(t *testing.T) {
sec := null.Security()
if got, want := sec.Type(), zmq4.NullSecurity; got != want {
t.Fatalf("got=%v, want=%v", got, want)
}

err := sec.Handshake()
err := sec.Handshake(nil, false)
if err != nil {
t.Fatalf("error doing handshake: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestNullSecurity(t *testing.T) {
t.Fatalf("got=%v, want=%v", got, want)
}

err := sec.Handshake()
err := sec.Handshake(nil, false)
if err != nil {
t.Fatalf("error doing handshake: %v", err)
}
Expand Down

0 comments on commit 4faa4ae

Please sign in to comment.