From bb17582e1dd5b35571278fb787e2a3fc7daaa09e Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 20 Apr 2020 01:25:59 +0300 Subject: [PATCH] Update key upload structs --- id/opaque.go | 19 +++++++++++++++++-- requests.go | 14 +++++++------- responses.go | 4 ++-- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/id/opaque.go b/id/opaque.go index 7cdadc35..e6a2740d 100644 --- a/id/opaque.go +++ b/id/opaque.go @@ -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 : that is used as the key in deviceid-key mappings. +// A DeviceKeyID is a string formatted as : 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 : 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) } diff --git a/requests.go b/requests.go index 4eb30748..45c7a5c2 100644 --- a/requests.go +++ b/requests.go @@ -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 { diff --git a/responses.go b/responses.go index 2ec95f26..28c7cca3 100644 --- a/responses.go +++ b/responses.go @@ -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 {