GODT-1815: Combined/Split mode
This commit is contained in:
@ -1,5 +1,11 @@
|
||||
package vault
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/ProtonMail/gluon/imap"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
vault *Vault
|
||||
userID string
|
||||
@ -13,16 +19,41 @@ func (user *User) Username() string {
|
||||
return user.vault.getUser(user.userID).Username
|
||||
}
|
||||
|
||||
func (user *User) GluonID() string {
|
||||
return user.vault.getUser(user.userID).GluonID
|
||||
func (user *User) GetGluonIDs() map[string]string {
|
||||
return user.vault.getUser(user.userID).GluonIDs
|
||||
}
|
||||
|
||||
func (user *User) SetGluonID(addrID, gluonID string) error {
|
||||
return user.vault.modUser(user.userID, func(data *UserData) {
|
||||
data.GluonIDs[addrID] = gluonID
|
||||
})
|
||||
}
|
||||
|
||||
func (user *User) GetUIDValidity(addrID string) (imap.UID, bool) {
|
||||
validity, ok := user.vault.getUser(user.userID).UIDValidity[addrID]
|
||||
if !ok {
|
||||
return imap.UID(0), false
|
||||
}
|
||||
|
||||
return validity, true
|
||||
}
|
||||
|
||||
func (user *User) SetUIDValidity(addrID string, validity imap.UID) error {
|
||||
return user.vault.modUser(user.userID, func(data *UserData) {
|
||||
data.UIDValidity[addrID] = validity
|
||||
})
|
||||
}
|
||||
|
||||
func (user *User) GluonKey() []byte {
|
||||
return user.vault.getUser(user.userID).GluonKey
|
||||
}
|
||||
|
||||
func (user *User) AddressMode() AddressMode {
|
||||
return user.vault.getUser(user.userID).AddressMode
|
||||
}
|
||||
|
||||
func (user *User) BridgePass() string {
|
||||
return user.vault.getUser(user.userID).BridgePass
|
||||
return hex.EncodeToString(user.vault.getUser(user.userID).BridgePass)
|
||||
}
|
||||
|
||||
func (user *User) AuthUID() string {
|
||||
@ -51,7 +82,7 @@ func (user *User) SetKeyPass(keyPass []byte) error {
|
||||
})
|
||||
}
|
||||
|
||||
// SetAuth updates the auth secrets for the given user.
|
||||
// SetAuth sets the auth secrets for the given user.
|
||||
func (user *User) SetAuth(authUID, authRef string) error {
|
||||
return user.vault.modUser(user.userID, func(data *UserData) {
|
||||
data.AuthUID = authUID
|
||||
@ -59,33 +90,23 @@ func (user *User) SetAuth(authUID, authRef string) error {
|
||||
})
|
||||
}
|
||||
|
||||
// SetGluonAuth updates the gluon ID and key for the given user.
|
||||
func (user *User) SetGluonAuth(gluonID string, gluonKey []byte) error {
|
||||
// SetAddressMode sets the address mode for the given user.
|
||||
func (user *User) SetAddressMode(mode AddressMode) error {
|
||||
return user.vault.modUser(user.userID, func(data *UserData) {
|
||||
data.GluonID = gluonID
|
||||
data.GluonKey = gluonKey
|
||||
data.AddressMode = mode
|
||||
})
|
||||
}
|
||||
|
||||
// SetEventID updates the event ID for the given user.
|
||||
// SetEventID sets the event ID for the given user.
|
||||
func (user *User) SetEventID(eventID string) error {
|
||||
return user.vault.modUser(user.userID, func(data *UserData) {
|
||||
data.EventID = eventID
|
||||
})
|
||||
}
|
||||
|
||||
// SetSync updates the sync state for the given user.
|
||||
// SetSync sets the sync state for the given user.
|
||||
func (user *User) SetSync(hasSync bool) error {
|
||||
return user.vault.modUser(user.userID, func(data *UserData) {
|
||||
data.HasSync = hasSync
|
||||
})
|
||||
}
|
||||
|
||||
// Clear clears the secrets for the given user.
|
||||
func (user *User) Clear() error {
|
||||
return user.vault.modUser(user.userID, func(data *UserData) {
|
||||
data.AuthUID = ""
|
||||
data.AuthRef = ""
|
||||
data.KeyPass = nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user