hiddens peers unlock

This commit is contained in:
ycc 2023-01-08 23:19:08 +01:00
parent 61958593a1
commit c4bb8c5693

View File

@ -26,6 +26,7 @@ type Identity struct {
OwnedDevices PeerList `json:"owned_devices,omitempty"`
StaticMtkServerPaths []InternalServerList `json:"static_mtk_server_paths,omitempty"`
DynamicMtkServeRules []string `json:"dynamic_mtk_serve_rules,omitempty"`
unlockedHiddenPeers PeerList
}
func CreateIdentity(nickname string) *Identity {
@ -138,3 +139,23 @@ func (id *Identity) Save() error {
err = os.WriteFile(GetConfig().IdentityFile, []byte(armor), 0600)
return err
}
func (id *Identity) TryUnlockHidden(password string) error {
found := false
for _, encPeer := range id.HiddenPeers {
p := Peer{}
jsonPeer, err := meowlib.SymDecrypt(password, encPeer)
if err == nil {
err = json.Unmarshal(jsonPeer, &p)
if err != nil {
return err
}
id.unlockedHiddenPeers = append(id.unlockedHiddenPeers, p)
found = true
}
}
if found {
return nil
}
return errors.New("no peer found")
}