Use gomatrixserverlib.Base64String instead of the builtin base64 package

This commit is contained in:
Brendan Abolivier 2017-08-29 14:45:33 +01:00
parent f7298a83a2
commit 4bc6f64e97
No known key found for this signature in database
GPG key ID: 8EF1500759F70623

View file

@ -15,7 +15,6 @@
package thirdpartyinvites package thirdpartyinvites
import ( import (
"encoding/base64"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -264,15 +263,15 @@ func queryIDServerStoreInvite(
// a given identity server and returns the matching base64-decoded public key. // a given identity server and returns the matching base64-decoded public key.
// Returns an error if the request couldn't be sent, if its body couldn't be parsed // Returns an error if the request couldn't be sent, if its body couldn't be parsed
// or if the key couldn't be decoded from base64. // or if the key couldn't be decoded from base64.
func queryIDServerPubKey(idServerName string, keyID string) (publicKey []byte, err error) { func queryIDServerPubKey(idServerName string, keyID string) ([]byte, error) {
url := fmt.Sprintf("https://%s/_matrix/identity/api/v1/pubkey/%s", idServerName, keyID) url := fmt.Sprintf("https://%s/_matrix/identity/api/v1/pubkey/%s", idServerName, keyID)
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
return return nil, err
} }
var pubKeyRes struct { var pubKeyRes struct {
PublicKey string `json:"public_key"` PublicKey gomatrixserverlib.Base64String `json:"public_key"`
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
@ -281,11 +280,8 @@ func queryIDServerPubKey(idServerName string, keyID string) (publicKey []byte, e
return nil, errors.New(errMsg) return nil, errors.New(errMsg)
} }
if err = json.NewDecoder(resp.Body).Decode(&pubKeyRes); err != nil { err = json.NewDecoder(resp.Body).Decode(&pubKeyRes)
return nil, err return pubKeyRes.PublicKey, err
}
return base64.RawStdEncoding.DecodeString(pubKeyRes.PublicKey)
} }
// checkIDServerSignatures iterates over the signatures of a requests. // checkIDServerSignatures iterates over the signatures of a requests.