Skip to content

Commit

Permalink
events/verification: use golang.org/x/exp/slices for Supports* functions
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <sumner@beeper.com>
  • Loading branch information
sumnerevans committed Jan 10, 2024
1 parent e0c8125 commit 02221ed
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions event/verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package event

import (
"golang.org/x/exp/slices"

"maunium.net/go/mautrix/id"
)

Expand Down Expand Up @@ -36,13 +38,8 @@ type VerificationRequestEventContent struct {
RelatesTo *RelatesTo `json:"m.relates_to,omitempty"`
}

func (vrec *VerificationRequestEventContent) SupportsVerificationMethod(meth VerificationMethod) bool {
for _, supportedMeth := range vrec.Methods {
if supportedMeth == meth {
return true
}
}
return false
func (vrec *VerificationRequestEventContent) SupportsVerificationMethod(method VerificationMethod) bool {
return slices.Contains(vrec.Methods, method)
}

type KeyAgreementProtocol string
Expand Down Expand Up @@ -91,39 +88,19 @@ type VerificationStartEventContent struct {
}

func (vsec *VerificationStartEventContent) SupportsKeyAgreementProtocol(proto KeyAgreementProtocol) bool {
for _, supportedProto := range vsec.KeyAgreementProtocols {
if supportedProto == proto {
return true
}
}
return false
return slices.Contains(vsec.KeyAgreementProtocols, proto)
}

func (vsec *VerificationStartEventContent) SupportsHashMethod(alg VerificationHashMethod) bool {
for _, supportedAlg := range vsec.Hashes {
if supportedAlg == alg {
return true
}
}
return false
return slices.Contains(vsec.Hashes, alg)
}

func (vsec *VerificationStartEventContent) SupportsMACMethod(meth MACMethod) bool {
for _, supportedMeth := range vsec.MessageAuthenticationCodes {
if supportedMeth == meth {
return true
}
}
return false
return slices.Contains(vsec.MessageAuthenticationCodes, meth)
}

func (vsec *VerificationStartEventContent) SupportsSASMethod(meth SASMethod) bool {
for _, supportedMeth := range vsec.ShortAuthenticationString {
if supportedMeth == meth {
return true
}
}
return false
return slices.Contains(vsec.ShortAuthenticationString, meth)
}

func (vsec *VerificationStartEventContent) GetRelatesTo() *RelatesTo {
Expand Down

0 comments on commit 02221ed

Please sign in to comment.