package store import ( "encoding/json" "errors" ) type calendarCredential struct{ Purpose, Domain, Calendar, Username, Password string } func (s *Store) SealCalendarCredential(domain, id, user, password string) (string, error) { b, e := json.Marshal(calendarCredential{"calendar-source-v1", domain, id, user, password}) if e != nil { return "", e } return s.encryptAuthSecret(b) } func (s *Store) OpenCalendarCredential(domain, id, cipher string) (string, string, error) { b, e := s.decryptAuthSecret(cipher) if e != nil { return "", "", e } var v calendarCredential if json.Unmarshal(b, &v) != nil || v.Purpose != "calendar-source-v1" || v.Domain != domain || v.Calendar != id { return "", "", errors.New("invalid calendar credential context") } return v.Username, v.Password, nil }