diff --git a/src/github.com/matrix-org/dendrite/encryptoapi/encryptoapi.go b/src/github.com/matrix-org/dendrite/encryptoapi/encryptoapi.go index 249c9649d..b103dc827 100644 --- a/src/github.com/matrix-org/dendrite/encryptoapi/encryptoapi.go +++ b/src/github.com/matrix-org/dendrite/encryptoapi/encryptoapi.go @@ -1,4 +1,4 @@ -// Copyright 2017 Vector Creations Ltd +// Copyright 2018 Vector Creations Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/github.com/matrix-org/dendrite/encryptoapi/routing/keys.go b/src/github.com/matrix-org/dendrite/encryptoapi/routing/keys.go index 84ede1153..11ab6acdf 100644 --- a/src/github.com/matrix-org/dendrite/encryptoapi/routing/keys.go +++ b/src/github.com/matrix-org/dendrite/encryptoapi/routing/keys.go @@ -1,4 +1,4 @@ -// Copyright 2017 Vector Creations Ltd +// Copyright 2018 Vector Creations Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -49,13 +49,22 @@ type KeyNotifier struct { var keyProducer = &KeyNotifier{} -func UploadPKeys(req *http.Request, encryptionDB *storage.Database, userID, deviceID string) util.JSONResponse { +func UploadPKeys( + req *http.Request, + encryptionDB *storage.Database, + userID, deviceID string, +) util.JSONResponse { var keybody types.UploadEncrypt - if reqErr := httputil.UnmarshalJSONRequest(req, &keybody); reqErr != nil { + if reqErr := httputil.UnmarshalJSONRequest(req, &keybody); + reqErr != nil { return *reqErr } keySpecific := turnSpecific(keybody) - err := persistKeys(encryptionDB, req.Context(), &keySpecific, userID, deviceID) + err := persistKeys( + encryptionDB, + req.Context(), + &keySpecific, + userID, deviceID) numMap := (QueryOneTimeKeys( TYPESUM, userID, @@ -78,17 +87,24 @@ func UploadPKeys(req *http.Request, encryptionDB *storage.Database, userID, devi } } -func QueryPKeys(req *http.Request, encryptionDB *storage.Database, userID, deviceID string, deviceDB *devices.Database) util.JSONResponse { +func QueryPKeys( + req *http.Request, + encryptionDB *storage.Database, + userID, deviceID string, + deviceDB *devices.Database, +) util.JSONResponse { var queryRq types.QueryRequest queryRp := types.QueryResponse{} queryRp.Failure = make(map[string]interface{}) queryRp.DeviceKeys = make(map[string]map[string]types.DeviceKeysQuery) - if reqErr := httputil.UnmarshalJSONRequest(req, &queryRq); reqErr != nil { + if reqErr := httputil.UnmarshalJSONRequest(req, &queryRq); + reqErr != nil { return *reqErr } /* - federation consideration: when user id is in federation, a query is needed to ask fed for keys + federation consideration: when user id is in federation, a + query is needed to ask fed for keys. domain --------+ fed (keys) domain +--tout-- timer */ @@ -166,7 +182,12 @@ func QueryPKeys(req *http.Request, encryptionDB *storage.Database, userID, devic } } -func ClaimOneTimeKeys(req *http.Request, encryptionDB *storage.Database, userID, deviceID string, deviceDB *devices.Database) util.JSONResponse { +func ClaimOneTimeKeys( + req *http.Request, + encryptionDB *storage.Database, + userID, deviceID string, + deviceDB *devices.Database, +) util.JSONResponse { var claimRq types.ClaimRequest claimRp := types.ClaimResponse{} claimRp.Failures = make(map[string]interface{}) @@ -354,7 +375,9 @@ func persistKeys( return err } -func turnSpecific(cont types.UploadEncrypt) (spec types.UploadEncryptSpecific) { +func turnSpecific( + cont types.UploadEncrypt, +) (spec types.UploadEncryptSpecific) { // both device keys are coordinate spec.DeviceKeys = cont.DeviceKeys spec.OneTimeKey.KeyString = make(map[string]string) @@ -374,19 +397,32 @@ func turnSpecific(cont types.UploadEncrypt) (spec types.UploadEncryptSpecific) { return } -func persistAl(encryptDB storage.Database, ctx context.Context, uid, device string, al []string) (err error) { +func persistAl( + encryptDB storage.Database, + ctx context.Context, + uid, device string, + al []string, +) (err error) { err = encryptDB.InsertAl(ctx, uid, device, al) return } -func takeAL(encryptDB storage.Database, ctx context.Context, uid, device string) (al []string, err error) { +func takeAL( + encryptDB storage.Database, + ctx context.Context, + uid, device string, +) (al []string, err error) { al, err = encryptDB.SelectAl(ctx, uid, device) return } -func pickOne(encryptDB storage.Database, ctx context.Context, uid, device, al string) (key types.KeyHolder, err error) { - key, err = encryptDB.SelectOneTimeKeySingle(ctx, uid, device, al) - return +func pickOne( + encryptDB storage.Database, + ctx context.Context, + uid, device, al string, +) (key types.KeyHolder, err error) { +key, err = encryptDB.SelectOneTimeKeySingle(ctx, uid, device, al) +return } func upnotify(userID string) { diff --git a/src/github.com/matrix-org/dendrite/encryptoapi/routing/routing.go b/src/github.com/matrix-org/dendrite/encryptoapi/routing/routing.go index 38fc10922..a8a5eb592 100644 --- a/src/github.com/matrix-org/dendrite/encryptoapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/encryptoapi/routing/routing.go @@ -1,4 +1,4 @@ -// Copyright 2017 Vector Creations Ltd +// Copyright 2018 Vector Creations Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/github.com/matrix-org/dendrite/encryptoapi/storage/encrypt_algorithm.go b/src/github.com/matrix-org/dendrite/encryptoapi/storage/encrypt_algorithm.go index 9c03e0f26..18657e859 100644 --- a/src/github.com/matrix-org/dendrite/encryptoapi/storage/encrypt_algorithm.go +++ b/src/github.com/matrix-org/dendrite/encryptoapi/storage/encrypt_algorithm.go @@ -1,4 +1,4 @@ -// Copyright 2017 Vector Creations Ltd +// Copyright 2018 Vector Creations Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,13 +30,13 @@ CREATE TABLE IF NOT EXISTS encrypt_algorithm ( algorithms TEXT NOT NULL ); ` - const insertalSQL = ` -INSERT INTO encrypt_algorithm (device_id, user_id, algorithms) VALUES ($1, $2, $3) +INSERT INTO encrypt_algorithm (device_id, user_id, algorithms) +VALUES ($1, $2, $3) ` - const selectalSQL = ` -SELECT user_id, device_id, algorithms FROM encrypt_algorithm WHERE user_id = $1 AND device_id = $2 +SELECT user_id, device_id, algorithms FROM encrypt_algorithm +WHERE user_id = $1 AND device_id = $2 ` type alStatements struct { diff --git a/src/github.com/matrix-org/dendrite/encryptoapi/storage/encrypt_keys_table.go b/src/github.com/matrix-org/dendrite/encryptoapi/storage/encrypt_keys_table.go index 79bb9de84..fdce52d9e 100644 --- a/src/github.com/matrix-org/dendrite/encryptoapi/storage/encrypt_keys_table.go +++ b/src/github.com/matrix-org/dendrite/encryptoapi/storage/encrypt_keys_table.go @@ -1,4 +1,4 @@ -// Copyright 2017 Vector Creations Ltd +// Copyright 2018 Vector Creations Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,29 +35,29 @@ CREATE TABLE IF NOT EXISTS encrypt_keys ( signature TEXT NOT NULL ); ` - const insertkeySQL = ` INSERT INTO encrypt_keys (device_id, user_id, key_id, key_type, key_info, algorithm, signature) - VALUES ($1, $2, $3, $4, $5, $6, $7) +VALUES ($1, $2, $3, $4, $5, $6, $7) ` - const selectkeySQL = ` -SELECT user_id, device_id, key_id, key_type, key_info, algorithm, signature FROM encrypt_keys WHERE user_id = $1 AND device_id = $2 +SELECT user_id, device_id, key_id, key_type, key_info, algorithm, signature FROM encrypt_keys +WHERE user_id = $1 AND device_id = $2 ` - const deleteSinglekeySQL = ` -SELECT user_id, device_id, key_id, key_type, key_info, algorithm, signature FROM encrypt_keys WHERE user_id = $1 AND device_id = $2 AND algorithm = $3 +SELECT user_id, device_id, key_id, key_type, key_info, algorithm, signature FROM encrypt_keys +WHERE user_id = $1 AND device_id = $2 AND algorithm = $3 ` const selectSinglekeySQL = ` -DELETE FROM encrypt_keys WHERE user_id = $1 AND device_id = $2 AND algorithm = $3 AND key_id = $4 +DELETE FROM encrypt_keys +WHERE user_id = $1 AND device_id = $2 AND algorithm = $3 AND key_id = $4 ` - const selectInkeysSQL = ` -SELECT user_id, device_id, key_id, key_type, key_info, algorithm, signature FROM encrypt_keys WHERE user_id = $1 AND key_type = 'device_key' AND device_id = ANY($2) +SELECT user_id, device_id, key_id, key_type, key_info, algorithm, signature FROM encrypt_keys + WHERE user_id = $1 AND key_type = 'device_key' AND device_id = ANY($2) ` - const selectAllkeysSQL = ` -SELECT user_id, device_id, key_id, key_type, key_info, algorithm, signature FROM encrypt_keys WHERE user_id = $1 AND key_type = $2 +SELECT user_id, device_id, key_id, key_type, key_info, algorithm, signature FROM encrypt_keys +WHERE user_id = $1 AND key_type = $2 ` type keyStatements struct { diff --git a/src/github.com/matrix-org/dendrite/encryptoapi/storage/storage.go b/src/github.com/matrix-org/dendrite/encryptoapi/storage/storage.go index ea58b7e82..bb14bb2ab 100644 --- a/src/github.com/matrix-org/dendrite/encryptoapi/storage/storage.go +++ b/src/github.com/matrix-org/dendrite/encryptoapi/storage/storage.go @@ -1,4 +1,4 @@ -// Copyright 2017 Vector Creations Ltd +// Copyright 2018 Vector Creations Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -86,7 +86,9 @@ func (d *Database) QueryInRange( return } -func (d *Database) InsertAl(ctx context.Context, uid, device string, al []string) (err error) { +func (d *Database) InsertAl( + ctx context.Context, uid, device string, al []string, +) (err error) { err = common.WithTransaction(d.db, func(txn *sql.Tx) (err error) { d.alStatements.insertAl(ctx, txn, uid, device, strings.Join(al, ",")) return @@ -94,7 +96,9 @@ func (d *Database) InsertAl(ctx context.Context, uid, device string, al []string return } -func (d *Database) SelectAl(ctx context.Context, uid, device string) (res []string, err error) { +func (d *Database) SelectAl( + ctx context.Context, uid, device string, +) (res []string, err error) { err = common.WithTransaction(d.db, func(txn *sql.Tx) (err error) { holder, err := d.alStatements.selectAl(ctx, txn, uid, device) res = strings.Split(holder.Supported_algorithm, ",") diff --git a/src/github.com/matrix-org/dendrite/encryptoapi/types/claim.go b/src/github.com/matrix-org/dendrite/encryptoapi/types/claim.go index 36dba5f8f..80a786d20 100644 --- a/src/github.com/matrix-org/dendrite/encryptoapi/types/claim.go +++ b/src/github.com/matrix-org/dendrite/encryptoapi/types/claim.go @@ -1,4 +1,4 @@ -// Copyright 2017 Vector Creations Ltd +// Copyright 2018 Vector Creations Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/github.com/matrix-org/dendrite/encryptoapi/types/query.go b/src/github.com/matrix-org/dendrite/encryptoapi/types/query.go index fed20ec53..1c5dba3a2 100644 --- a/src/github.com/matrix-org/dendrite/encryptoapi/types/query.go +++ b/src/github.com/matrix-org/dendrite/encryptoapi/types/query.go @@ -1,4 +1,4 @@ -// Copyright 2017 Vector Creations Ltd +// Copyright 2018 Vector Creations Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/github.com/matrix-org/dendrite/encryptoapi/types/storage.go b/src/github.com/matrix-org/dendrite/encryptoapi/types/storage.go index 9dc44eb75..55815420a 100644 --- a/src/github.com/matrix-org/dendrite/encryptoapi/types/storage.go +++ b/src/github.com/matrix-org/dendrite/encryptoapi/types/storage.go @@ -1,4 +1,4 @@ -// Copyright 2017 Vector Creations Ltd +// Copyright 2018 Vector Creations Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/github.com/matrix-org/dendrite/encryptoapi/types/upload.go b/src/github.com/matrix-org/dendrite/encryptoapi/types/upload.go index 3b4267d1c..b2f542075 100644 --- a/src/github.com/matrix-org/dendrite/encryptoapi/types/upload.go +++ b/src/github.com/matrix-org/dendrite/encryptoapi/types/upload.go @@ -1,4 +1,4 @@ -// Copyright 2017 Vector Creations Ltd +// Copyright 2018 Vector Creations Ltd // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License.