mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 01:13:10 -06:00
Change the way some variables are declared or passed as argument
This commit is contained in:
parent
62210741ce
commit
f7298a83a2
|
|
@ -180,12 +180,12 @@ func queryIDServer(
|
||||||
// queryIDServerLookup sends a response to the identity server on /_matrix/identity/api/v1/lookup
|
// queryIDServerLookup sends a response to the identity server on /_matrix/identity/api/v1/lookup
|
||||||
// and returns the response as a structure.
|
// and returns the response as a structure.
|
||||||
// Returns an error if the request failed to send or if the response couldn't be parsed.
|
// Returns an error if the request failed to send or if the response couldn't be parsed.
|
||||||
func queryIDServerLookup(body *MembershipRequest) (res *idServerLookupResponse, err error) {
|
func queryIDServerLookup(body *MembershipRequest) (*idServerLookupResponse, error) {
|
||||||
address := url.QueryEscape(body.Address)
|
address := url.QueryEscape(body.Address)
|
||||||
url := fmt.Sprintf("https://%s/_matrix/identity/api/v1/lookup?medium=%s&address=%s", body.IDServer, body.Medium, address)
|
url := fmt.Sprintf("https://%s/_matrix/identity/api/v1/lookup?medium=%s&address=%s", body.IDServer, body.Medium, address)
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
|
@ -194,9 +194,9 @@ func queryIDServerLookup(body *MembershipRequest) (res *idServerLookupResponse,
|
||||||
return nil, errors.New(errMgs)
|
return nil, errors.New(errMgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
res = new(idServerLookupResponse)
|
var res idServerLookupResponse
|
||||||
err = json.NewDecoder(resp.Body).Decode(res)
|
err = json.NewDecoder(resp.Body).Decode(&res)
|
||||||
return
|
return &res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// queryIDServerStoreInvite sends a response to the identity server on /_matrix/identity/api/v1/store-invite
|
// queryIDServerStoreInvite sends a response to the identity server on /_matrix/identity/api/v1/store-invite
|
||||||
|
|
@ -255,17 +255,17 @@ func queryIDServerStoreInvite(
|
||||||
return nil, errors.New(errMsg)
|
return nil, errors.New(errMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
idResp := new(idServerStoreInviteResponse)
|
var idResp idServerStoreInviteResponse
|
||||||
err = json.NewDecoder(resp.Body).Decode(idResp)
|
err = json.NewDecoder(resp.Body).Decode(&idResp)
|
||||||
return idResp, err
|
return &idResp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// queryIDServerPubKey requests a public key identified with a given ID to the
|
// queryIDServerPubKey requests a public key identified with a given ID to the
|
||||||
// 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(body *MembershipRequest, keyID string) (publicKey []byte, err error) {
|
func queryIDServerPubKey(idServerName string, keyID string) (publicKey []byte, err error) {
|
||||||
url := fmt.Sprintf("https://%s/_matrix/identity/api/v1/pubkey/%s", body.IDServer, 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
|
||||||
|
|
@ -277,7 +277,7 @@ func queryIDServerPubKey(body *MembershipRequest, keyID string) (publicKey []byt
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
// TODO: Log the error supplied with the identity server?
|
// TODO: Log the error supplied with the identity server?
|
||||||
errMsg := fmt.Sprintf("Couldn't retrieve key %s from server %s", keyID, body.IDServer)
|
errMsg := fmt.Sprintf("Couldn't retrieve key %s from server %s", keyID, idServerName)
|
||||||
return nil, errors.New(errMsg)
|
return nil, errors.New(errMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -308,7 +308,7 @@ func checkIDServerSignatures(body *MembershipRequest, res *idServerLookupRespons
|
||||||
}
|
}
|
||||||
|
|
||||||
for keyID := range signatures {
|
for keyID := range signatures {
|
||||||
pubKey, err := queryIDServerPubKey(body, keyID)
|
pubKey, err := queryIDServerPubKey(body.IDServer, keyID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue