aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/envelope.go
diff options
context:
space:
mode:
Diffstat (limited to 'whisper/envelope.go')
-rw-r--r--whisper/envelope.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/whisper/envelope.go b/whisper/envelope.go
index eb80098ad..359fa1568 100644
--- a/whisper/envelope.go
+++ b/whisper/envelope.go
@@ -2,7 +2,9 @@ package whisper
import (
"bytes"
+ "crypto/ecdsa"
"encoding/binary"
+ "fmt"
"io"
"time"
@@ -59,6 +61,24 @@ func (self *Envelope) Seal(pow time.Duration) {
self.proveWork(pow)
}
+func (self *Envelope) Open(prv *ecdsa.PrivateKey) (*Message, 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")
+ }
+
+ if data[0] > 0 {
+ payload, err := crypto.Decrypt(prv, data[66:])
+ if err != nil {
+ return nil, fmt.Errorf("unable to open envelope. Decrypt failed: %v", err)
+ }
+
+ return NewMessage(payload), nil
+ }
+
+ return NewMessage(data[1:]), nil
+}
+
func (self *Envelope) proveWork(dura time.Duration) {
var bestBit int
d := make([]byte, 64)