diff options
Diffstat (limited to 'src/send.go')
-rw-r--r-- | src/send.go | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/send.go b/src/send.go index 7d4014a..c598ad4 100644 --- a/src/send.go +++ b/src/send.go @@ -349,12 +349,19 @@ func (device *Device) RoutineEncryption() { // encrypt content (append to header) binary.LittleEndian.PutUint64(nonce[4:], elem.nonce) - elem.packet = elem.keyPair.send.Seal( - header, - nonce[:], - elem.packet, - nil, - ) + elem.keyPair.send.mutex.RLock() + if elem.keyPair.send.aead == nil { + // very unlikely (the key was deleted during queuing) + elem.Drop() + } else { + elem.packet = elem.keyPair.send.aead.Seal( + header, + nonce[:], + elem.packet, + nil, + ) + } + elem.keyPair.send.mutex.RUnlock() elem.mutex.Unlock() // refresh key if necessary |