mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-13 21:02:25 +03:00
Create user room key if needed (#3108)
This commit is contained in:
parent
82b73a4906
commit
2c87972a3a
6 changed files with 67 additions and 2 deletions
|
@ -2,6 +2,7 @@ package internal
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ed25519"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
@ -270,3 +271,23 @@ func (r *RoomserverInternalAPI) PerformForget(
|
|||
) error {
|
||||
return r.Forgetter.PerformForget(ctx, req, resp)
|
||||
}
|
||||
|
||||
// GetOrCreateUserRoomPrivateKey gets the user room key for the specified user. If no key exists yet, a new one is created.
|
||||
func (r *RoomserverInternalAPI) GetOrCreateUserRoomPrivateKey(ctx context.Context, userID spec.UserID, roomID spec.RoomID) (ed25519.PrivateKey, error) {
|
||||
key, err := r.DB.SelectUserRoomPrivateKey(ctx, userID, roomID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// no key found, create one
|
||||
if len(key) == 0 {
|
||||
_, key, err = ed25519.GenerateKey(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
key, err = r.DB.InsertUserRoomPrivatePublicKey(ctx, userID, roomID, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return key, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue