aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/message.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-04-13 16:31:51 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-04-13 16:31:51 +0800
commit7b501906db5b4bed0cf9972a1b103cc343d7f2d2 (patch)
tree9336342ec2ee9e090323f6b8f01ea968e8e12b39 /whisper/message.go
parent5467e7b312a29f492ce3063686711ea0bea6dbc3 (diff)
downloaddexon-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.tar
dexon-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.tar.gz
dexon-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.tar.bz2
dexon-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.tar.lz
dexon-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.tar.xz
dexon-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.tar.zst
dexon-7b501906db5b4bed0cf9972a1b103cc343d7f2d2.zip
whisper: separate out magic number from the code
Diffstat (limited to 'whisper/message.go')
-rw-r--r--whisper/message.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/whisper/message.go b/whisper/message.go
index 2666ee6e0..457cf6def 100644
--- a/whisper/message.go
+++ b/whisper/message.go
@@ -35,8 +35,9 @@ type Options struct {
// NewMessage creates and initializes a non-signed, non-encrypted Whisper message.
func NewMessage(payload []byte) *Message {
- // Construct an initial flag set: bit #1 = 0 (no signature), rest random
- flags := byte(rand.Intn(128))
+ // Construct an initial flag set: no signature, rest random
+ flags := byte(rand.Intn(256))
+ flags &= ^signatureFlag
// Assemble and return the message
return &Message{
@@ -84,7 +85,7 @@ func (self *Message) Wrap(pow time.Duration, options Options) (*Envelope, error)
// sign calculates and sets the cryptographic signature for the message , also
// setting the sign flag.
func (self *Message) sign(key *ecdsa.PrivateKey) (err error) {
- self.Flags |= 1 << 7
+ self.Flags |= signatureFlag
self.Signature, err = crypto.Sign(self.hash(), key)
return
}
@@ -102,8 +103,14 @@ func (self *Message) Recover() *ecdsa.PublicKey {
}
// encrypt encrypts a message payload with a public key.
-func (self *Message) encrypt(to *ecdsa.PublicKey) (err error) {
- self.Payload, err = crypto.Encrypt(to, self.Payload)
+func (self *Message) encrypt(key *ecdsa.PublicKey) (err error) {
+ self.Payload, err = crypto.Encrypt(key, self.Payload)
+ return
+}
+
+// decrypt decrypts an encrypted payload with a private key.
+func (self *Message) decrypt(key *ecdsa.PrivateKey) (err error) {
+ self.Payload, err = crypto.Decrypt(key, self.Payload)
return
}