mirror of
https://salsa.debian.org/mdosch/go-sendxmpp
synced 2024-11-10 19:10:30 +00:00
[golangci-lint]: Use constant for error.
This commit is contained in:
parent
686041acc8
commit
d85cf8fee7
1
const.go
1
const.go
@ -21,5 +21,6 @@ const (
|
|||||||
oxAltBody = "This message is encrypted (XEP-0373: OpenPGP for XMPP)."
|
oxAltBody = "This message is encrypted (XEP-0373: OpenPGP for XMPP)."
|
||||||
pubsubPubOptions = "http://jabber.org/protocol/pubsub#publish-options"
|
pubsubPubOptions = "http://jabber.org/protocol/pubsub#publish-options"
|
||||||
strChat = "chat"
|
strChat = "chat"
|
||||||
|
strError = "error"
|
||||||
strGroupchat = "groupchat"
|
strGroupchat = "groupchat"
|
||||||
)
|
)
|
||||||
|
46
ox.go
46
ox.go
@ -81,7 +81,7 @@ func oxDecrypt(m xmpp.Chat, client *xmpp.Client, iqc chan xmpp.IQ,
|
|||||||
cryptMsgByte, err =
|
cryptMsgByte, err =
|
||||||
base64.StdEncoding.DecodeString(r.InnerXML)
|
base64.StdEncoding.DecodeString(r.InnerXML)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", time.Now(), err
|
return strError, time.Now(), err
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -89,53 +89,53 @@ func oxDecrypt(m xmpp.Chat, client *xmpp.Client, iqc chan xmpp.IQ,
|
|||||||
oxMsg := crypto.NewPGPMessage(cryptMsgByte)
|
oxMsg := crypto.NewPGPMessage(cryptMsgByte)
|
||||||
keyRing, err := crypto.NewKeyRing(oxPrivKey)
|
keyRing, err := crypto.NewKeyRing(oxPrivKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", time.Now(), err
|
return strError, time.Now(), err
|
||||||
}
|
}
|
||||||
senderKeyRing, err := oxGetPublicKeyRing(client, iqc, sender)
|
senderKeyRing, err := oxGetPublicKeyRing(client, iqc, sender)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", time.Now(), err
|
return strError, time.Now(), err
|
||||||
}
|
}
|
||||||
decryptMsg, err := keyRing.Decrypt(oxMsg, senderKeyRing, crypto.GetUnixTime())
|
decryptMsg, err := keyRing.Decrypt(oxMsg, senderKeyRing, crypto.GetUnixTime())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", time.Now(), err
|
return strError, time.Now(), err
|
||||||
}
|
}
|
||||||
// Remove invalid code points.
|
// Remove invalid code points.
|
||||||
message := validUTF8(string(decryptMsg.Data))
|
message := validUTF8(string(decryptMsg.Data))
|
||||||
doc := etree.NewDocument()
|
doc := etree.NewDocument()
|
||||||
err = doc.ReadFromString(message)
|
err = doc.ReadFromString(message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", time.Now(), err
|
return strError, time.Now(), err
|
||||||
}
|
}
|
||||||
signcrypt := doc.SelectElement("signcrypt")
|
signcrypt := doc.SelectElement("signcrypt")
|
||||||
if signcrypt == nil {
|
if signcrypt == nil {
|
||||||
return "error", time.Now(), errors.New("ox: no signcrypt element")
|
return strError, time.Now(), errors.New("ox: no signcrypt element")
|
||||||
}
|
}
|
||||||
to := signcrypt.SelectElement("to")
|
to := signcrypt.SelectElement("to")
|
||||||
if to == nil {
|
if to == nil {
|
||||||
return "error", time.Now(), errors.New("ox: no to element")
|
return strError, time.Now(), errors.New("ox: no to element")
|
||||||
}
|
}
|
||||||
jid := to.SelectAttr("jid")
|
jid := to.SelectAttr("jid")
|
||||||
if jid == nil {
|
if jid == nil {
|
||||||
return "error", time.Now(), errors.New("ox: no jid attribute")
|
return strError, time.Now(), errors.New("ox: no jid attribute")
|
||||||
}
|
}
|
||||||
if strings.Split(jid.Value, "/")[0] != user {
|
if strings.Split(jid.Value, "/")[0] != user {
|
||||||
return "error", time.Now(), errors.New("ox: encrypted for wrong user")
|
return strError, time.Now(), errors.New("ox: encrypted for wrong user")
|
||||||
}
|
}
|
||||||
timestamp := signcrypt.SelectElement("time")
|
timestamp := signcrypt.SelectElement("time")
|
||||||
if timestamp == nil {
|
if timestamp == nil {
|
||||||
return "error", time.Now(), errors.New("ox: no time element")
|
return strError, time.Now(), errors.New("ox: no time element")
|
||||||
}
|
}
|
||||||
stamp := timestamp.SelectAttr("stamp")
|
stamp := timestamp.SelectAttr("stamp")
|
||||||
if stamp == nil {
|
if stamp == nil {
|
||||||
return "error", time.Now(), errors.New("ox: no stamp attribute")
|
return strError, time.Now(), errors.New("ox: no stamp attribute")
|
||||||
}
|
}
|
||||||
msgStamp, err := time.Parse("2006-01-02T15:04:05Z0700", stamp.Value)
|
msgStamp, err := time.Parse("2006-01-02T15:04:05Z0700", stamp.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", time.Now(), err
|
return strError, time.Now(), err
|
||||||
}
|
}
|
||||||
payload := signcrypt.SelectElement("payload")
|
payload := signcrypt.SelectElement("payload")
|
||||||
if payload == nil {
|
if payload == nil {
|
||||||
return "error", time.Now(), errors.New("ox: no payload element")
|
return strError, time.Now(), errors.New("ox: no payload element")
|
||||||
}
|
}
|
||||||
body := payload.SelectElement("body")
|
body := payload.SelectElement("body")
|
||||||
if body == nil {
|
if body == nil {
|
||||||
@ -334,10 +334,10 @@ func oxGetPrivKeyLoc(jid string) (string, error) {
|
|||||||
default:
|
default:
|
||||||
homeDir, err = os.UserHomeDir()
|
homeDir, err = os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", err
|
return strError, err
|
||||||
}
|
}
|
||||||
if homeDir == "" {
|
if homeDir == "" {
|
||||||
return "error", err
|
return strError, err
|
||||||
}
|
}
|
||||||
dataDir = homeDir + "/.local/share"
|
dataDir = homeDir + "/.local/share"
|
||||||
}
|
}
|
||||||
@ -345,7 +345,7 @@ func oxGetPrivKeyLoc(jid string) (string, error) {
|
|||||||
if _, err = os.Stat(dataDir); os.IsNotExist(err) {
|
if _, err = os.Stat(dataDir); os.IsNotExist(err) {
|
||||||
err = os.MkdirAll(dataDir, 0700)
|
err = os.MkdirAll(dataDir, 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", err
|
return strError, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataFile := dataDir + base64.StdEncoding.EncodeToString([]byte(jid))
|
dataFile := dataDir + base64.StdEncoding.EncodeToString([]byte(jid))
|
||||||
@ -367,10 +367,10 @@ func oxGetPubKeyLoc(fingerprint string) (string, error) {
|
|||||||
default:
|
default:
|
||||||
homeDir, err = os.UserHomeDir()
|
homeDir, err = os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", err
|
return strError, err
|
||||||
}
|
}
|
||||||
if homeDir == "" {
|
if homeDir == "" {
|
||||||
return "error", err
|
return strError, err
|
||||||
}
|
}
|
||||||
dataDir = homeDir + "/.local/share"
|
dataDir = homeDir + "/.local/share"
|
||||||
}
|
}
|
||||||
@ -378,7 +378,7 @@ func oxGetPubKeyLoc(fingerprint string) (string, error) {
|
|||||||
if _, err = os.Stat(dataDir); os.IsNotExist(err) {
|
if _, err = os.Stat(dataDir); os.IsNotExist(err) {
|
||||||
err = os.MkdirAll(dataDir, 0700)
|
err = os.MkdirAll(dataDir, 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", err
|
return strError, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataFile := dataDir + fingerprint
|
dataFile := dataDir + fingerprint
|
||||||
@ -703,7 +703,7 @@ func oxEncrypt(client *xmpp.Client, iqc chan xmpp.IQ, oxPrivKey *crypto.Key,
|
|||||||
}
|
}
|
||||||
privKeyRing, err := crypto.NewKeyRing(oxPrivKey)
|
privKeyRing, err := crypto.NewKeyRing(oxPrivKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", err
|
return strError, err
|
||||||
}
|
}
|
||||||
ownJid := strings.Split(client.JID(), "/")[0]
|
ownJid := strings.Split(client.JID(), "/")[0]
|
||||||
if recipient != ownJid {
|
if recipient != ownJid {
|
||||||
@ -729,12 +729,12 @@ func oxEncrypt(client *xmpp.Client, iqc chan xmpp.IQ, oxPrivKey *crypto.Key,
|
|||||||
oxCryptMessageScPayloadBody.CreateText(message)
|
oxCryptMessageScPayloadBody.CreateText(message)
|
||||||
ocm, err := oxCryptMessage.WriteToString()
|
ocm, err := oxCryptMessage.WriteToString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", err
|
return strError, err
|
||||||
}
|
}
|
||||||
plainMessage := crypto.NewPlainMessage([]byte(ocm))
|
plainMessage := crypto.NewPlainMessage([]byte(ocm))
|
||||||
pgpMessage, err := keyRing.Encrypt(plainMessage, privKeyRing)
|
pgpMessage, err := keyRing.Encrypt(plainMessage, privKeyRing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", err
|
return strError, err
|
||||||
}
|
}
|
||||||
om := etree.NewDocument()
|
om := etree.NewDocument()
|
||||||
om.WriteSettings.AttrSingleQuote = true
|
om.WriteSettings.AttrSingleQuote = true
|
||||||
@ -753,7 +753,7 @@ func oxEncrypt(client *xmpp.Client, iqc chan xmpp.IQ, oxPrivKey *crypto.Key,
|
|||||||
omMessageBody.CreateText(oxAltBody)
|
omMessageBody.CreateText(oxAltBody)
|
||||||
oms, err := om.WriteToString()
|
oms, err := om.WriteToString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "error", err
|
return strError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return oms, nil
|
return oms, nil
|
||||||
|
@ -88,11 +88,11 @@ func rcvStanzas(client *xmpp.Client, iqc chan xmpp.IQ, msgc chan xmpp.Chat) {
|
|||||||
root := etree.NewDocument()
|
root := etree.NewDocument()
|
||||||
root.WriteSettings.AttrSingleQuote = true
|
root.WriteSettings.AttrSingleQuote = true
|
||||||
reply := root.CreateElement("iq")
|
reply := root.CreateElement("iq")
|
||||||
reply.CreateAttr("type", "error")
|
reply.CreateAttr("type", strError)
|
||||||
reply.CreateAttr("from", client.JID())
|
reply.CreateAttr("from", client.JID())
|
||||||
reply.CreateAttr("to", v.From)
|
reply.CreateAttr("to", v.From)
|
||||||
reply.CreateAttr("id", v.ID)
|
reply.CreateAttr("id", v.ID)
|
||||||
errorReply := reply.CreateElement("error")
|
errorReply := reply.CreateElement(strError)
|
||||||
errorReply.CreateAttr("type", "cancel")
|
errorReply.CreateAttr("type", "cancel")
|
||||||
su := errorReply.CreateElement("service-unavailable")
|
su := errorReply.CreateElement("service-unavailable")
|
||||||
su.CreateAttr("xmlns", nsXMPPStanzas)
|
su.CreateAttr("xmlns", nsXMPPStanzas)
|
||||||
@ -108,11 +108,11 @@ func rcvStanzas(client *xmpp.Client, iqc chan xmpp.IQ, msgc chan xmpp.Chat) {
|
|||||||
root := etree.NewDocument()
|
root := etree.NewDocument()
|
||||||
root.WriteSettings.AttrSingleQuote = true
|
root.WriteSettings.AttrSingleQuote = true
|
||||||
reply := root.CreateElement("iq")
|
reply := root.CreateElement("iq")
|
||||||
reply.CreateAttr("type", "error")
|
reply.CreateAttr("type", strError)
|
||||||
reply.CreateAttr("from", client.JID())
|
reply.CreateAttr("from", client.JID())
|
||||||
reply.CreateAttr("to", v.From)
|
reply.CreateAttr("to", v.From)
|
||||||
reply.CreateAttr("id", v.ID)
|
reply.CreateAttr("id", v.ID)
|
||||||
errorReply := reply.CreateElement("error")
|
errorReply := reply.CreateElement(strError)
|
||||||
errorReply.CreateAttr("type", "cancel")
|
errorReply.CreateAttr("type", "cancel")
|
||||||
su := errorReply.CreateElement("service-unavailable")
|
su := errorReply.CreateElement("service-unavailable")
|
||||||
su.CreateAttr("xmlns", nsXMPPStanzas)
|
su.CreateAttr("xmlns", nsXMPPStanzas)
|
||||||
@ -123,7 +123,7 @@ func rcvStanzas(client *xmpp.Client, iqc chan xmpp.IQ, msgc chan xmpp.Chat) {
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "reply", "error":
|
case "reply", strError:
|
||||||
iqc <- v
|
iqc <- v
|
||||||
default:
|
default:
|
||||||
iqc <- v
|
iqc <- v
|
||||||
|
Loading…
Reference in New Issue
Block a user