whisper5: minor update

This commit is contained in:
Vlad 2016-08-30 16:58:13 +02:00
parent c2eced014d
commit d14292e0ed
2 changed files with 8 additions and 3 deletions

View file

@ -58,4 +58,7 @@ const (
DefaultPoW = 50 * time.Millisecond DefaultPoW = 50 * time.Millisecond
) )
// Topic represents a cryptographically secure, probabilistic partial
// classifications of a message, determined as the first (left) 4 bytes of the
// SHA3 hash of some arbitrary data given by the original author of the message.
type TopicType [4]byte type TopicType [4]byte

View file

@ -23,7 +23,6 @@ package whisper5
import ( import (
crand "crypto/rand" crand "crypto/rand"
"errors" "errors"
mrand "math/rand"
"time" "time"
"crypto/aes" "crypto/aes"
@ -126,7 +125,10 @@ func (self *Message) Padding() []byte {
// NewMessage creates and initializes a non-signed, non-encrypted Whisper message. // NewMessage creates and initializes a non-signed, non-encrypted Whisper message.
func NewMessage(payload []byte) *Message { func NewMessage(payload []byte) *Message {
// Construct an initial flag set: no signature, no padding, other bits random // Construct an initial flag set: no signature, no padding, other bits random
flags := byte(mrand.Intn(256)) buf := make([]byte, 1)
crand.Read(buf)
flags := buf[0]
flags &= ^signatureFlag flags &= ^signatureFlag
flags &= ^paddingFlag flags &= ^paddingFlag
@ -158,7 +160,7 @@ func (self *Message) appendPadding(options Options) {
if odd > 0 { if odd > 0 {
padSize := maxPadLength - odd padSize := maxPadLength - odd
buf := make([]byte, padSize) buf := make([]byte, padSize)
mrand.Read(buf) crand.Read(buf)
if options.Pad != nil { if options.Pad != nil {
copy(buf, options.Pad) copy(buf, options.Pad)
} }