diff options
Diffstat (limited to 'whisper/envelope.go')
-rw-r--r-- | whisper/envelope.go | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/whisper/envelope.go b/whisper/envelope.go index f35a40a42..c51c6e600 100644 --- a/whisper/envelope.go +++ b/whisper/envelope.go @@ -11,7 +11,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/rlp" ) @@ -85,27 +84,22 @@ func (self *Envelope) Open(key *ecdsa.PrivateKey) (msg *Message, err error) { } data = data[1:] - if message.Flags&128 == 128 { - if len(data) < 65 { - return nil, fmt.Errorf("unable to open envelope. First bit set but len(data) < 65") + if message.Flags&signatureFlag == signatureFlag { + if len(data) < signatureLength { + return nil, fmt.Errorf("unable to open envelope. First bit set but len(data) < len(signature)") } - message.Signature, data = data[:65], data[65:] + message.Signature, data = data[:signatureLength], data[signatureLength:] } message.Payload = data - // Short circuit if the encryption was requested + // Decrypt the message, if requested if key == nil { return message, nil } - // Otherwise try to decrypt the message - message.Payload, err = crypto.Decrypt(key, message.Payload) - switch err { + switch message.decrypt(key) { case nil: return message, nil - case ecies.ErrInvalidPublicKey: // Payload isn't encrypted - return message, err - default: return nil, fmt.Errorf("unable to open envelope, decrypt failed: %v", err) } |