Fix Go 1.13 requirement and make compiling SAS optional

This commit is contained in:
Tulir Asokan 2020-08-02 13:52:13 +03:00
commit c3c4f6afe0
6 changed files with 15 additions and 9 deletions

View file

@ -1,15 +1,17 @@
package olm
// +build !nosas
import (
"crypto/rand"
"unsafe"
)
package olm
// #cgo LDFLAGS: -lolm -lstdc++
// #include <olm/olm.h>
// #include <olm/sas.h>
import "C"
import (
"crypto/rand"
"unsafe"
)
// SAS stores an Olm Short Authentication String (SAS) object.
type SAS struct {
int *C.OlmSAS

View file

@ -13,6 +13,7 @@ import (
"testing"
_ "github.com/mattn/go-sqlite3"
"maunium.net/go/mautrix/crypto/olm"
"maunium.net/go/mautrix/id"
)

View file

@ -4,6 +4,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// +build !nosas
package crypto
import (

View file

@ -187,7 +187,7 @@ func (VerificationMethodEmoji) GetVerificationSAS(initUserID id.UserID, initDevi
for i := 0; i < len(emojis); i++ {
// take nth group of 6 bits
emojiIdx := (sasNum >> (48 - (i+1)*6)) & 0x3F
emojiIdx := (sasNum >> uint(48-(i+1)*6)) & 0x3F
emoji := allEmojis[emojiIdx]
emojis[i] = emoji
}

View file

@ -9,7 +9,8 @@ package event
import (
"encoding/json"
"maunium.net/go/mautrix/crypto/olm"
"github.com/pkg/errors"
"maunium.net/go/mautrix/id"
)
@ -57,7 +58,7 @@ func (content *EncryptedEventContent) UnmarshalJSON(data []byte) error {
return json.Unmarshal(content.Ciphertext, &content.OlmCiphertext)
case id.AlgorithmMegolmV1:
if len(content.Ciphertext) == 0 || content.Ciphertext[0] != '"' || content.Ciphertext[len(content.Ciphertext)-1] != '"' {
return olm.InputNotJSONString
return errors.New("input doesn't look like a JSON string")
}
content.MegolmCiphertext = content.Ciphertext[1 : len(content.Ciphertext)-1]
}

View file

@ -1,3 +1,3 @@
package mautrix
const Version = "v0.7.0-rc.2"
const Version = "v0.7.0-rc.3"