event/verification: remove Supports* functions

Use slices.Contains instead

Signed-off-by: Sumner Evans <sumner@beeper.com>
pull/185/head
Sumner Evans 2024-02-19 16:33:56 -07:00
parent 0f7c716964
commit 128fc8cd89
No known key found for this signature in database
GPG Key ID: 8904527AB50022FD
2 changed files with 6 additions and 29 deletions

View File

@ -171,18 +171,18 @@ func (vh *VerificationHelper) onVerificationStartSAS(ctx context.Context, txn *v
}
keyAggreementProtocol := event.KeyAgreementProtocolCurve25519HKDFSHA256
if !startEvt.SupportsKeyAgreementProtocol(keyAggreementProtocol) {
if !slices.Contains(startEvt.KeyAgreementProtocols, keyAggreementProtocol) {
return fmt.Errorf("the other device does not support any key agreement protocols that we support")
}
hashAlgorithm := event.VerificationHashMethodSHA256
if !startEvt.SupportsHashMethod(hashAlgorithm) {
if !slices.Contains(startEvt.Hashes, hashAlgorithm) {
return fmt.Errorf("the other device does not support any hash algorithms that we support")
}
macMethod := event.MACMethodHKDFHMACSHA256V2
if !startEvt.SupportsMACMethod(macMethod) {
if startEvt.SupportsMACMethod(event.MACMethodHKDFHMACSHA256) {
if !slices.Contains(startEvt.MessageAuthenticationCodes, macMethod) {
if slices.Contains(startEvt.MessageAuthenticationCodes, event.MACMethodHKDFHMACSHA256) {
macMethod = event.MACMethodHKDFHMACSHA256
} else {
return fmt.Errorf("the other device does not support any message authentication codes that we support")
@ -348,14 +348,14 @@ func (vh *VerificationHelper) onVerificationKey(ctx context.Context, txn *verifi
var decimals []int
var emojis []rune
if txn.StartEventContent.SupportsSASMethod(event.SASMethodDecimal) {
if slices.Contains(txn.StartEventContent.ShortAuthenticationString, event.SASMethodDecimal) {
decimals = []int{
(int(sasBytes[0])<<5 | int(sasBytes[1])>>3) + 1000,
((int(sasBytes[1])&0x07)<<10 | int(sasBytes[2])<<2 | int(sasBytes[3])>>6) + 1000,
((int(sasBytes[3])&0x3f)<<7 | int(sasBytes[4])>>1) + 1000,
}
}
if txn.StartEventContent.SupportsSASMethod(event.SASMethodEmoji) {
if slices.Contains(txn.StartEventContent.ShortAuthenticationString, event.SASMethodEmoji) {
sasNum := uint64(sasBytes[0])<<40 | uint64(sasBytes[1])<<32 | uint64(sasBytes[2])<<24 |
uint64(sasBytes[3])<<16 | uint64(sasBytes[4])<<8 | uint64(sasBytes[5])

View File

@ -9,7 +9,6 @@ package event
import (
"go.mau.fi/util/jsonbytes"
"go.mau.fi/util/jsontime"
"golang.org/x/exp/slices"
"maunium.net/go/mautrix/id"
)
@ -105,12 +104,6 @@ func VerificationRequestEventContentFromMessage(evt *Event) *VerificationRequest
}
}
// SupportsVerificationMethod returns whether the given verification method is
// supported by the sender.
func (vrec *VerificationRequestEventContent) SupportsVerificationMethod(method VerificationMethod) bool {
return slices.Contains(vrec.Methods, method)
}
// VerificationReadyEventContent represents the content of an
// [m.key.verification.ready] event (both the to-device and the in-room
// version) as described in [Section 11.12.2.1] of the Spec.
@ -199,22 +192,6 @@ type VerificationStartEventContent struct {
Secret jsonbytes.UnpaddedBytes `json:"secret,omitempty"`
}
func (vsec *VerificationStartEventContent) SupportsKeyAgreementProtocol(proto KeyAgreementProtocol) bool {
return slices.Contains(vsec.KeyAgreementProtocols, proto)
}
func (vsec *VerificationStartEventContent) SupportsHashMethod(alg VerificationHashMethod) bool {
return slices.Contains(vsec.Hashes, alg)
}
func (vsec *VerificationStartEventContent) SupportsMACMethod(meth MACMethod) bool {
return slices.Contains(vsec.MessageAuthenticationCodes, meth)
}
func (vsec *VerificationStartEventContent) SupportsSASMethod(meth SASMethod) bool {
return slices.Contains(vsec.ShortAuthenticationString, meth)
}
// VerificationDoneEventContent represents the content of an
// [m.key.verification.done] event (both the to-device and the in-room version)
// as described in [Section 11.12.2.1] of the Spec.