Skip to content

Commit

Permalink
wire-mix: instead of checking op string, check if writer implements h…
Browse files Browse the repository at this point in the history
…ash.Hash
  • Loading branch information
jrick committed Nov 24, 2023
1 parent 1b102c3 commit 43d8ef0
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 28 deletions.
3 changes: 2 additions & 1 deletion wire/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,8 @@ func isStrictAscii(s string) bool {
return true
}

// hashEncoder specifies a message encoder that will never error on its own
// hashEncoder specifies a writer for message and signature hashes which never
// errors.
type hashEncoder interface {
hashEncode(h hash.Hash, pver uint32)
}
Expand Down
7 changes: 3 additions & 4 deletions wire/msgmixciphertexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@ func (msg *MsgMixCiphertexts) hashEncode(h hash.Hash, pver uint32) {
// the signature. This allows code reuse between message serialization, and
// signing and verifying these message contents.
//
// If op is the empty string (when the message is being hashed), w is a
// hash.Hash (writes never error) and no errors will be returned for invalid
// message construction.
// If w implements hash.Hash, no errors will be returned for invalid message
// construction.
func (msg *MsgMixCiphertexts) writeMessageNoSignature(op string, w io.Writer, pver uint32) error {
hashing := op == ""
_, hashing := w.(hash.Hash)

err := writeElements(w, &msg.Identity, &msg.SessionID, msg.Expiry,
msg.Run)
Expand Down
7 changes: 3 additions & 4 deletions wire/msgmixconfirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,10 @@ func (msg *MsgMixConfirm) hashEncode(h hash.Hash, pver uint32) {
// the signature. This allows code reuse between message serialization, and
// signing and verifying these message contents.
//
// If op is the empty string (when the message is being hashed), w is a
// hash.Hash (writes never error) and no errors will be returned for invalid
// message construction.
// If w implements hash.Hash, no errors will be returned for invalid message
// construction.
func (msg *MsgMixConfirm) writeMessageNoSignature(op string, w io.Writer, pver uint32) error {
hashing := op == ""
_, hashing := w.(hash.Hash)

err := writeElements(w, &msg.Identity, &msg.SessionID, msg.Expiry,
msg.Run)
Expand Down
7 changes: 3 additions & 4 deletions wire/msgmixdcnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ func (msg *MsgMixDCNet) hashEncode(h hash.Hash, pver uint32) {
// the signature. This allows code reuse between message serialization, and
// signing and verifying these message contents.
//
// If op is the empty string (when the message is being hashed), w is a
// hash.Hash (writes never error) and no errors will be returned for invalid
// message construction.
// If w implements hash.Hash, no errors will be returned for invalid message
// construction.
func (msg *MsgMixDCNet) writeMessageNoSignature(op string, w io.Writer, pver uint32) error {
hashing := op == ""
_, hashing := w.(hash.Hash)

err := writeElements(w, &msg.Identity, &msg.SessionID, msg.Expiry,
msg.Run)
Expand Down
7 changes: 3 additions & 4 deletions wire/msgmixkeyexchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ func (msg *MsgMixKeyExchange) hashEncode(h hash.Hash, pver uint32) {
// the signature. This allows code reuse between message serialization, and
// signing and verifying these message contents.
//
// If op is the empty string (when the message is being hashed), w is a
// hash.Hash (writes never error) and no errors will be returned for invalid
// message construction.
// If w implements hash.Hash, no errors will be returned for invalid message
// construction.
func (msg *MsgMixKeyExchange) writeMessageNoSignature(op string, w io.Writer, pver uint32) error {
hashing := op == ""
_, hashing := w.(hash.Hash)

err := writeElements(w, &msg.Identity, &msg.SessionID, msg.Expiry,
msg.Run, &msg.ECDH, &msg.PQPK, &msg.Commitment)
Expand Down
7 changes: 3 additions & 4 deletions wire/msgmixpairreq.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,10 @@ func (msg *MsgMixPairReq) hashEncode(h hash.Hash, pver uint32) {
// the signature. This allows code reuse between message serialization, and
// signing and verifying these message contents.
//
// If op is the empty string (when the message is being hashed), w is a
// hash.Hash (writes never error) and no errors will be returned for invalid
// message construction.
// If w implements hash.Hash, no errors will be returned for invalid message
// construction.
func (msg *MsgMixPairReq) writeMessageNoSignature(op string, w io.Writer, pver uint32) error {
hashing := op == ""
_, hashing := w.(hash.Hash)

err := writeElements(w, &msg.Identity, msg.Expiry, msg.MixAmount)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions wire/msgmixsecrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ func (msg *MsgMixSecrets) hashEncode(h hash.Hash, pver uint32) {
// the signature. This allows code reuse between message serialization, and
// signing and verifying these message contents.
//
// If op is the empty string (when the message is being hashed), w is a
// hash.Hash (writes never error) and no errors will be returned for invalid
// message construction.
// This method never errors for invalid message construction.
func (msg *MsgMixSecrets) writeMessageNoSignature(op string, w io.Writer, pver uint32) error {
err := writeElements(w, &msg.Identity, &msg.SessionID, msg.Expiry,
msg.Run, &msg.Seed)
Expand Down
7 changes: 3 additions & 4 deletions wire/msgmixslotreserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,10 @@ func (msg *MsgMixSlotReserve) hashEncode(h hash.Hash, pver uint32) {
// the signature. This allows code reuse between message serialization, and
// signing and verifying these message contents.
//
// If op is the empty string (when the message is being hashed), w is a
// hash.Hash (writes never error) and no errors will be returned for invalid
// message construction.
// If w implements hash.Hash, no errors will be returned for invalid message
// construction.
func (msg *MsgMixSlotReserve) writeMessageNoSignature(op string, w io.Writer, pver uint32) error {
hashing := op == ""
_, hashing := w.(hash.Hash)

err := writeElements(w, &msg.Identity, &msg.SessionID, msg.Expiry,
msg.Run)
Expand Down

0 comments on commit 43d8ef0

Please sign in to comment.