From a17a1f9208f858601f6660dbd7f1b77dd9a3f3d9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 12 Dec 2014 22:23:42 +0100 Subject: Implemented watching using filter package * Added filters / watches * Removed event dep --- whisper/envelope.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'whisper/envelope.go') 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) { -- cgit