diff options
author | obscuren <geffobscura@gmail.com> | 2014-12-13 05:23:42 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-12-13 05:23:42 +0800 |
commit | a17a1f9208f858601f6660dbd7f1b77dd9a3f3d9 (patch) | |
tree | 6f6f61cfd2dd41cc20d1bcae9604c1f09e07e42d /whisper/envelope.go | |
parent | ed1538248f2e7a44680d22a052a234a31b736624 (diff) | |
download | dexon-a17a1f9208f858601f6660dbd7f1b77dd9a3f3d9.tar.gz dexon-a17a1f9208f858601f6660dbd7f1b77dd9a3f3d9.tar.zst dexon-a17a1f9208f858601f6660dbd7f1b77dd9a3f3d9.zip |
Implemented watching using filter package
* Added filters / watches
* Removed event dep
Diffstat (limited to 'whisper/envelope.go')
-rw-r--r-- | whisper/envelope.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/whisper/envelope.go b/whisper/envelope.go index 359fa1568..683e88128 100644 --- a/whisper/envelope.go +++ b/whisper/envelope.go @@ -61,22 +61,27 @@ func (self *Envelope) Seal(pow time.Duration) { self.proveWork(pow) } -func (self *Envelope) Open(prv *ecdsa.PrivateKey) (*Message, error) { +func (self *Envelope) Open(prv *ecdsa.PrivateKey) (msg *Message, err error) { data := self.Data - if data[0] > 0 && len(data) < 66 { - return nil, fmt.Errorf("unable to open envelope. First bit set but len(data) < 66") - } - + var message Message + dataStart := 1 if data[0] > 0 { - payload, err := crypto.Decrypt(prv, data[66:]) + if len(data) < 66 { + return nil, fmt.Errorf("unable to open envelope. First bit set but len(data) < 66") + } + dataStart = 66 + message.Flags = data[0] + message.Signature = data[1:66] + } + message.Payload = data[dataStart:] + if prv != nil { + message.Payload, err = crypto.Decrypt(prv, message.Payload) if err != nil { return nil, fmt.Errorf("unable to open envelope. Decrypt failed: %v", err) } - - return NewMessage(payload), nil } - return NewMessage(data[1:]), nil + return &message, nil } func (self *Envelope) proveWork(dura time.Duration) { |