Identity load and save params, invitation check

This commit is contained in:
ycc
2022-11-28 20:48:42 +01:00
parent f4ebb5cab1
commit b464a855ae
6 changed files with 46 additions and 14 deletions

View File

@ -55,6 +55,15 @@ func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerI
return &myContactCard
}
func (id *Identity) CheckInvitation(ReceivedContact *meowlib.ContactCard) (isAnswer bool, proposedNick string, receivedNick string) {
for _, p := range id.Peers {
if p.InvitationId == ReceivedContact.InvitationId {
return true, p.Name, ReceivedContact.Name
}
}
return false, "", ReceivedContact.Name
}
func (id *Identity) AnswerInvitation(MyName string, ContactName string, MessageServerIdxs []int, ReceivedContact *meowlib.ContactCard) *meowlib.ContactCard {
var peer Peer
var myContactCard meowlib.ContactCard
@ -93,13 +102,15 @@ func (id *Identity) FinalizeInvitation(ReceivedContact *meowlib.ContactCard) err
return errors.New("no matching contact found for invitationId " + ReceivedContact.InvitationId)
}
func LoadIdentity(file string) (*Identity, error) {
func LoadIdentity(filename string, password string) (*Identity, error) {
var id Identity
indata, err := ioutil.ReadFile(file)
GetConfig().memoryPassword = password
GetConfig().identityFile = filename
indata, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
pass, err := helper.DecryptMessageWithPassword([]byte(key), string(indata))
pass, err := helper.DecryptMessageWithPassword([]byte(password), string(indata))
if err != nil {
return nil, err
}
@ -107,12 +118,12 @@ func LoadIdentity(file string) (*Identity, error) {
return &id, err
}
func (id *Identity) Save(file string) error {
func (id *Identity) Save() error {
b, _ := json.Marshal(id)
armor, err := helper.EncryptMessageWithPassword([]byte(key), string(b))
armor, err := helper.EncryptMessageWithPassword([]byte(GetConfig().memoryPassword), string(b))
if err != nil {
return err
}
err = ioutil.WriteFile(file, []byte(armor), 0644)
err = ioutil.WriteFile(GetConfig().identityFile, []byte(armor), 0600)
return err
}