package storage import ( "cwtch.im/cwtch/model" "encoding/json" ) type profileStore struct { fs FileStore } // ProfileStore is an interface to managing the storage of Cwtch Profiles type ProfileStore interface { Save(profile *model.Profile) error Load() (*model.Profile, error) } func NewProfileStore(filename string, password string) ProfileStore { return &profileStore{NewFileStore(filename, password)} } func (ps *profileStore) Save(profile *model.Profile) error { bytes, _ := json.Marshal(profile) return ps.fs.Save(bytes) } // Load instantiates a cwtchPeer from the file store func (ps *profileStore) Load() (*model.Profile, error) { decrypted, err := ps.fs.Load() if err != nil { return nil, err } cp := new(model.Profile) err = json.Unmarshal(decrypted, &cp) if err == nil { return cp, nil } return nil, err }