whisper: resolving merge conflicts

This commit is contained in:
Vlad 2017-03-23 13:03:39 +01:00
parent abc79b542f
commit 3b57070408
5 changed files with 25 additions and 10 deletions

View file

@ -493,6 +493,10 @@ func sendMsg(payload []byte) common.Hash {
} }
msg := whisper.NewSentMessage(&params) msg := whisper.NewSentMessage(&params)
if msg == nil {
fmt.Printf("failed to create new message (OS level error)")
os.Exit(0)
}
envelope, err := msg.Wrap(&params) envelope, err := msg.Wrap(&params)
if err != nil { if err != nil {
fmt.Printf("failed to seal message: %v \n", err) fmt.Printf("failed to seal message: %v \n", err)
@ -622,6 +626,10 @@ func requestExpiredMessagesLoop() {
params.WorkTime = 5 params.WorkTime = 5
msg := whisper.NewSentMessage(&params) msg := whisper.NewSentMessage(&params)
if msg == nil {
fmt.Printf("failed to create new message (OS level error)")
os.Exit(0)
}
env, err := msg.Wrap(&params) env, err := msg.Wrap(&params)
if err != nil { if err != nil {
utils.Fatalf("Wrap failed: %s", err) utils.Fatalf("Wrap failed: %s", err)

View file

@ -402,6 +402,11 @@ func (api *PublicWhisperAPI) Post(args PostArgs) error {
// encrypt and send // encrypt and send
message := NewSentMessage(&params) message := NewSentMessage(&params)
if message == nil {
info := "Post: failed create new message, probably due to failed rand function (OS level)"
log.Error(info)
return errors.New(info)
}
envelope, err := message.Wrap(&params) envelope, err := message.Wrap(&params)
if err != nil { if err != nil {
log.Error(err.Error()) log.Error(err.Error())

View file

@ -194,15 +194,9 @@ func TestMatchEnvelope(t *testing.T) {
} }
// encrypt symmetrically // encrypt symmetrically
<<<<<<< d4e2ecd2e1164b6a5106b20d135742a35656838f
i := mrand.Int() % 4 i := mrand.Int() % 4
fsym.Topics[i] = params.Topic
fasym.Topics[i] = params.Topic
=======
i := rand.Int() % 4
fsym.Topics[i] = params.Topic[:] fsym.Topics[i] = params.Topic[:]
fasym.Topics[i] = params.Topic[:] fasym.Topics[i] = params.Topic[:]
>>>>>>> whisper: variable topic size allowed for a filter
msg = NewSentMessage(params) msg = NewSentMessage(params)
env, err = msg.Wrap(params) env, err = msg.Wrap(params)
if err != nil { if err != nil {

View file

@ -102,14 +102,18 @@ func NewSentMessage(params *MessageParams) *SentMessage {
msg := SentMessage{} msg := SentMessage{}
msg.Raw = make([]byte, 1, len(params.Payload)+len(params.Payload)+signatureLength+padSizeLimitUpper) msg.Raw = make([]byte, 1, len(params.Payload)+len(params.Payload)+signatureLength+padSizeLimitUpper)
msg.Raw[0] = 0 // set all the flags to zero msg.Raw[0] = 0 // set all the flags to zero
msg.appendPadding(params) err := msg.appendPadding(params)
if err != nil {
log.Error(fmt.Sprintf("NewSentMessage: %s", err))
return nil
}
msg.Raw = append(msg.Raw, params.Payload...) msg.Raw = append(msg.Raw, params.Payload...)
return &msg return &msg
} }
// appendPadding appends the pseudorandom padding bytes and sets the padding flag. // appendPadding appends the pseudorandom padding bytes and sets the padding flag.
// The last byte contains the size of padding (thus, its size must not exceed 256). // The last byte contains the size of padding (thus, its size must not exceed 256).
func (msg *SentMessage) appendPadding(params *MessageParams) { func (msg *SentMessage) appendPadding(params *MessageParams) error {
total := len(params.Payload) + 1 total := len(params.Payload) + 1
if params.Src != nil { if params.Src != nil {
total += signatureLength total += signatureLength
@ -128,7 +132,10 @@ func (msg *SentMessage) appendPadding(params *MessageParams) {
panic("please fix the padding algorithm before releasing new version") panic("please fix the padding algorithm before releasing new version")
} }
buf := make([]byte, padSize) buf := make([]byte, padSize)
mrand.Read(buf[1:]) _, err := mrand.Read(buf[1:])
if err != nil {
return err
}
buf[0] = byte(padSize) buf[0] = byte(padSize)
if params.Padding != nil { if params.Padding != nil {
copy(buf[1:], params.Padding) copy(buf[1:], params.Padding)
@ -136,6 +143,7 @@ func (msg *SentMessage) appendPadding(params *MessageParams) {
msg.Raw = append(msg.Raw, buf...) msg.Raw = append(msg.Raw, buf...)
msg.Raw[0] |= byte(0x1) // number of bytes indicating the padding size msg.Raw[0] |= byte(0x1) // number of bytes indicating the padding size
} }
return nil
} }
// sign calculates and sets the cryptographic signature for the message, // sign calculates and sets the cryptographic signature for the message,

View file

@ -391,7 +391,7 @@ func TestWhisperSymKeyManagement(t *testing.T) {
} }
randomKey = make([]byte, aesKeyLength+1) randomKey = make([]byte, aesKeyLength+1)
randomize(randomKey) mrand.Read(randomKey)
id1, err = w.AddSymKeyDirect(randomKey) id1, err = w.AddSymKeyDirect(randomKey)
if err == nil { if err == nil {
t.Fatalf("added the key with wrong size, seed %d.", seed) t.Fatalf("added the key with wrong size, seed %d.", seed)