certificate.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package option
  2. import (
  3. C "github.com/sagernet/sing-box/constant"
  4. "github.com/sagernet/sing/common/json"
  5. "github.com/sagernet/sing/common/json/badoption"
  6. )
  7. type _CertificateOptions struct {
  8. Store string `json:"store,omitempty"`
  9. Certificate badoption.Listable[string] `json:"certificate,omitempty"`
  10. CertificatePath badoption.Listable[string] `json:"certificate_path,omitempty"`
  11. CertificateDirectoryPath badoption.Listable[string] `json:"certificate_directory_path,omitempty"`
  12. }
  13. type CertificateOptions _CertificateOptions
  14. func (o CertificateOptions) MarshalJSON() ([]byte, error) {
  15. switch o.Store {
  16. case C.CertificateStoreSystem:
  17. o.Store = ""
  18. }
  19. return json.Marshal((*_CertificateOptions)(&o))
  20. }
  21. func (o *CertificateOptions) UnmarshalJSON(data []byte) error {
  22. err := json.Unmarshal(data, (*_CertificateOptions)(o))
  23. if err != nil {
  24. return err
  25. }
  26. switch o.Store {
  27. case C.CertificateStoreSystem, "":
  28. o.Store = C.CertificateStoreSystem
  29. }
  30. return nil
  31. }