whisper: filter with sym & asym keys must try both methods

There is an ongoing discussion whether this is the proper
way to go, as filters implementing both sym and asym keys
will see an unsuccessful attempt at an asymmetric
decryption be followed by an attempt at a symmetric
decription. This is inefficient in that case, which should
not happen too often. The alternative is to forbid using
filters with both options enabled, and will require
updating unit tests.
This commit is contained in:
Guillaume Ballet 2017-11-30 21:47:12 +01:00 committed by Felix Lange
parent 2640164304
commit a0abb7dcfc

View file

@ -211,14 +211,14 @@ func (e *Envelope) Open(watcher *Filter) (msg *ReceivedMessage) {
// if the filter has some asymmetric key provided, it will // if the filter has some asymmetric key provided, it will
// attempt to open it asymmetrically. If this fails, then // attempt to open it asymmetrically. If this fails, then
// attempt to open it symmetrically. // attempt to open it symmetrically.
if watcher.KeyAsym != nil { if watcher.expectsAsymmetricEncryption() {
msg, _ = e.OpenAsymmetric(watcher.KeyAsym) msg, _ = e.OpenAsymmetric(watcher.KeyAsym)
if msg != nil { if msg != nil {
msg.Dst = &watcher.KeyAsym.PublicKey msg.Dst = &watcher.KeyAsym.PublicKey
} }
} }
if msg == nil { if msg == nil && watcher.expectsSymmetricEncryption() {
msg, _ = e.OpenSymmetric(watcher.KeySym) msg, _ = e.OpenSymmetric(watcher.KeySym)
if msg != nil { if msg != nil {
msg.SymKeyHash = crypto.Keccak256Hash(watcher.KeySym) msg.SymKeyHash = crypto.Keccak256Hash(watcher.KeySym)