Update key upload structs

This commit is contained in:
Tulir Asokan 2020-04-20 01:25:59 +03:00
commit bb17582e1d
3 changed files with 26 additions and 11 deletions

View file

@ -6,6 +6,10 @@
package id
import (
"fmt"
)
// A RoomID is a string starting with ! that references a specific room.
// https://matrix.org/docs/spec/appendices#room-ids-and-event-ids
type RoomID string
@ -23,9 +27,20 @@ type EventID string
// A DeviceID is an arbitrary string that references a specific device.
type DeviceID string
// A KeyID is a string usually formatted as <algorithm>:<device_id> that is used as the key in deviceid-key mappings.
// A DeviceKeyID is a string formatted as <algorithm>:<device_id> that is used as the key in deviceid-key mappings.
type DeviceKeyID string
func NewDeviceKeyID(algorithm string, deviceID DeviceID) DeviceKeyID {
return DeviceKeyID(fmt.Sprintf("%s:%s", algorithm, deviceID))
}
// A KeyID a string formatted as <algorithm>:<key_id> that is used as the key in one-time-key mappings.
type KeyID string
func NewKeyID(algorithm, keyID string) KeyID {
return KeyID(fmt.Sprintf("%s:%s", algorithm, keyID))
}
func (roomID RoomID) String() string {
return string(roomID)
}
@ -42,6 +57,6 @@ func (deviceID DeviceID) String() string {
return string(deviceID)
}
func (keyID KeyID) String() string {
func (keyID DeviceKeyID) String() string {
return string(keyID)
}

View file

@ -108,17 +108,17 @@ type ReqAliasCreate struct {
}
type ReqUploadKeys struct {
DeviceKeys DeviceKeys `json:"device_keys,omitempty"`
DeviceKeys *DeviceKeys `json:"device_keys,omitempty"`
OneTimeKeys map[id.KeyID]string `json:"one_time_keys"`
}
type DeviceKeys struct {
UserID id.UserID `json:"user_id"`
DeviceID id.DeviceID `json:"device_id"`
Algorithms []string `json:"algorithms"`
Keys map[id.KeyID]string `json:"keys"`
Signatures map[id.UserID]map[string]string `json:"signatures"`
Unsigned *UnsignedDeviceInfo `json:"unsigned,omitempty"`
UserID id.UserID `json:"user_id"`
DeviceID id.DeviceID `json:"device_id"`
Algorithms []string `json:"algorithms"`
Keys map[id.DeviceKeyID]string `json:"keys"`
Signatures map[id.UserID]map[id.DeviceKeyID]string `json:"signatures"`
Unsigned *UnsignedDeviceInfo `json:"unsigned,omitempty"`
}
type UnsignedDeviceInfo struct {

View file

@ -239,8 +239,8 @@ type RespQueryKeys struct {
}
type RespClaimKeys struct {
Failures map[string]map[string]interface{} `json:"failures"`
OneTimeKeys map[id.UserID]map[id.KeyID]string `json:"one_time_keys"`
Failures map[string]map[string]interface{} `json:"failures"`
OneTimeKeys map[id.UserID]map[id.DeviceKeyID]string `json:"one_time_keys"`
}
type RespKeyChanges struct {