Skip to content

Commit

Permalink
return message when not encrypted
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavrax committed Nov 23, 2023
1 parent 0b6f537 commit ddf7b2c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions subscription_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,10 @@ func parseCipherInterface(data interface{}, pnConf *Config, module crypto.Crypto
pnConf.Log.Println("v[pn_other]", v["pn_other"], v, msg)
decrypted, errDecryption := decryptString(module, msg)
if errDecryption != nil {
if strings.Contains(errDecryption.Error(), "decrypt error on decode") {
pnConf.Log.Println("Couldn't decode message. Asumming no encrypted message. Returning raw message...")
return msg, nil
}
pnConf.Log.Println(errDecryption, msg)
return v, errDecryption
} else {
Expand All @@ -994,6 +998,11 @@ func parseCipherInterface(data interface{}, pnConf *Config, module crypto.Crypto
var intf interface{}
decrypted, errDecryption := decryptString(module, data.(string))
if errDecryption != nil {
if strings.Contains(errDecryption.Error(), "decrypt error on decode") {
pnConf.Log.Println("Couldn't decode message. Asumming no encrypted message. Returning raw message...")
return data, nil
}

pnConf.Log.Println(errDecryption, intf)
intf = data
return intf, errDecryption
Expand Down
10 changes: 10 additions & 0 deletions subscription_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,13 @@ func TestProcessSubscribePayloadCipherErr(t *testing.T) {
<-done
//pn.Destroy()
}

func TestDecryptionProcessOnNoEncryptedMessage(t *testing.T) {
assert := assert.New(t)
pn := NewPubNub(NewDemoConfig())

result, err := parseCipherInterface("test", pn.Config, pn.getCryptoModule())

assert.Nil(err)
assert.Equal("test", result)
}

0 comments on commit ddf7b2c

Please sign in to comment.