diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-04-13 16:31:51 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-04-13 16:31:51 +0800 |
commit | 7b501906db5b4bed0cf9972a1b103cc343d7f2d2 (patch) | |
tree | 9336342ec2ee9e090323f6b8f01ea968e8e12b39 /whisper/envelope.go | |
parent | 5467e7b312a29f492ce3063686711ea0bea6dbc3 (diff) | |
download | go-tangerine-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.tar go-tangerine-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.tar.gz go-tangerine-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.tar.bz2 go-tangerine-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.tar.lz go-tangerine-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.tar.xz go-tangerine-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.tar.zst go-tangerine-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.zip |
whisper: separate out magic number from the code
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) } |