From f60f3728ce618d97abb59ead8d7059df984ea1a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sat, 25 Jul 2026 22:57:06 +0800 Subject: [PATCH] Fix string type --- common/tls/std_client.go | 2 +- common/tls/std_server.go | 2 +- common/tls/utls_client.go | 2 +- option/platform.go | 114 ----------------------------------- protocol/ssh/outbound.go | 2 +- service/acme/service.go | 8 +-- service/origin_ca/service.go | 2 +- 7 files changed, 9 insertions(+), 123 deletions(-) delete mode 100644 option/platform.go diff --git a/common/tls/std_client.go b/common/tls/std_client.go index 8091e1d69..80fa6cb28 100644 --- a/common/tls/std_client.go +++ b/common/tls/std_client.go @@ -188,7 +188,7 @@ func newSTDClient(ctx context.Context, logger logger.ContextLogger, serverAddres if len(certificate) > 0 { certPool := x509.NewCertPool() if !certPool.AppendCertsFromPEM(certificate) { - return nil, E.New("failed to parse certificate:\n\n", certificate) + return nil, E.New("failed to parse certificate:\n\n", string(certificate)) } tlsConfig.RootCAs = certPool } diff --git a/common/tls/std_server.go b/common/tls/std_server.go index 52e87b540..ff4ee1a4c 100644 --- a/common/tls/std_server.go +++ b/common/tls/std_server.go @@ -289,7 +289,7 @@ func (c *STDServerConfig) certificateUpdated(path string) error { for _, certPath := range c.clientCertificatePath { content, err := filemanager.ReadFile(c.ctx, certPath) if err != nil { - c.logger.Error(E.Cause(err, "reload certificate from ", c.clientCertificatePath)) + c.logger.Error(E.Cause(err, "reload certificate from ", certPath)) continue } if !clientCertificateCA.AppendCertsFromPEM(content) { diff --git a/common/tls/utls_client.go b/common/tls/utls_client.go index 748665295..16d0352d0 100644 --- a/common/tls/utls_client.go +++ b/common/tls/utls_client.go @@ -260,7 +260,7 @@ func newUTLSClient(ctx context.Context, logger logger.ContextLogger, serverAddre if len(certificate) > 0 { certPool := x509.NewCertPool() if !certPool.AppendCertsFromPEM(certificate) { - return nil, E.New("failed to parse certificate:\n\n", certificate) + return nil, E.New("failed to parse certificate:\n\n", string(certificate)) } tlsConfig.RootCAs = certPool } diff --git a/option/platform.go b/option/platform.go deleted file mode 100644 index 7044245ad..000000000 --- a/option/platform.go +++ /dev/null @@ -1,114 +0,0 @@ -package option - -import ( - "github.com/sagernet/sing-box/schema" - E "github.com/sagernet/sing/common/exceptions" - "github.com/sagernet/sing/common/json" - "github.com/sagernet/sing/common/json/badoption" -) - -type OnDemandOptions struct { - Enabled bool `json:"enabled,omitempty"` - Rules []OnDemandRule `json:"rules,omitempty"` -} - -type OnDemandRule struct { - Action *OnDemandRuleAction `json:"action,omitempty"` - DNSSearchDomainMatch badoption.Listable[string] `json:"dns_search_domain_match,omitempty"` - DNSServerAddressMatch badoption.Listable[string] `json:"dns_server_address_match,omitempty"` - InterfaceTypeMatch *OnDemandRuleInterfaceType `json:"interface_type_match,omitempty"` - SSIDMatch badoption.Listable[string] `json:"ssid_match,omitempty"` - ProbeURL string `json:"probe_url,omitempty"` -} - -type OnDemandRuleAction int - -func (r *OnDemandRuleAction) MarshalJSON() ([]byte, error) { - if r == nil { - return nil, nil - } - value := *r - var actionName string - switch value { - case 1: - actionName = "connect" - case 2: - actionName = "disconnect" - case 3: - actionName = "evaluate_connection" - default: - return nil, E.New("unknown action: ", value) - } - return json.Marshal(actionName) -} - -func (r *OnDemandRuleAction) UnmarshalJSON(bytes []byte) error { - var actionName string - if err := json.Unmarshal(bytes, &actionName); err != nil { - return err - } - var actionValue int - switch actionName { - case "connect": - actionValue = 1 - case "disconnect": - actionValue = 2 - case "evaluate_connection": - actionValue = 3 - case "ignore": - actionValue = 4 - default: - return E.New("unknown action name: ", actionName) - } - *r = OnDemandRuleAction(actionValue) - return nil -} - -func (r OnDemandRuleAction) DescribeSchema(builder schema.Builder) (*schema.Node, error) { - return schema.StringEnum("connect", "disconnect", "evaluate_connection", "ignore"), nil -} - -type OnDemandRuleInterfaceType int - -func (r *OnDemandRuleInterfaceType) MarshalJSON() ([]byte, error) { - if r == nil { - return nil, nil - } - value := *r - var interfaceTypeName string - switch value { - case 1: - interfaceTypeName = "any" - case 2: - interfaceTypeName = "wifi" - case 3: - interfaceTypeName = "cellular" - default: - return nil, E.New("unknown interface type: ", value) - } - return json.Marshal(interfaceTypeName) -} - -func (r *OnDemandRuleInterfaceType) UnmarshalJSON(bytes []byte) error { - var interfaceTypeName string - if err := json.Unmarshal(bytes, &interfaceTypeName); err != nil { - return err - } - var interfaceTypeValue int - switch interfaceTypeName { - case "any": - interfaceTypeValue = 1 - case "wifi": - interfaceTypeValue = 2 - case "cellular": - interfaceTypeValue = 3 - default: - return E.New("unknown interface type name: ", interfaceTypeName) - } - *r = OnDemandRuleInterfaceType(interfaceTypeValue) - return nil -} - -func (r OnDemandRuleInterfaceType) DescribeSchema(builder schema.Builder) (*schema.Node, error) { - return schema.StringEnum("any", "wifi", "cellular"), nil -} diff --git a/protocol/ssh/outbound.go b/protocol/ssh/outbound.go index 407b00a28..d045f1896 100644 --- a/protocol/ssh/outbound.go +++ b/protocol/ssh/outbound.go @@ -110,7 +110,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL for _, hostKey := range options.HostKey { key, _, _, _, err := ssh.ParseAuthorizedKey([]byte(hostKey)) if err != nil { - return nil, E.New("parse host key ", key) + return nil, E.Cause(err, "parse host key: ", hostKey) } outbound.hostKey = append(outbound.hostKey, key) } diff --git a/service/acme/service.go b/service/acme/service.go index 2553100f2..3e1abd0aa 100644 --- a/service/acme/service.go +++ b/service/acme/service.go @@ -116,7 +116,7 @@ func NewCertificateProvider(ctx context.Context, logger log.ContextLogger, tag s case option.ACMEKeyTypeRSA4096: keyType = certmagic.RSA4096 default: - return nil, E.New("unsupported ACME key type: ", options.KeyType) + return nil, E.New("unsupported ACME key type: ", string(options.KeyType)) } config.KeySource = certmagic.StandardKeyGenerator{KeyType: keyType} } @@ -231,13 +231,13 @@ func newDNSSolver(dnsOptions *option.ACMEProviderDNS01ChallengeOptions, logger * return nil, nil } if dnsOptions.TTL < 0 { - return nil, E.New("invalid ACME DNS01 ttl: ", dnsOptions.TTL) + return nil, E.New("invalid ACME DNS01 ttl: ", dnsOptions.TTL.Build()) } if dnsOptions.PropagationDelay < 0 { - return nil, E.New("invalid ACME DNS01 propagation_delay: ", dnsOptions.PropagationDelay) + return nil, E.New("invalid ACME DNS01 propagation_delay: ", dnsOptions.PropagationDelay.Build()) } if dnsOptions.PropagationTimeout < -1 { - return nil, E.New("invalid ACME DNS01 propagation_timeout: ", dnsOptions.PropagationTimeout) + return nil, E.New("invalid ACME DNS01 propagation_timeout: ", dnsOptions.PropagationTimeout.Build()) } solver := &certmagic.DNS01Solver{ DNSManager: certmagic.DNSManager{ diff --git a/service/origin_ca/service.go b/service/origin_ca/service.go index 9f303e402..46d7337ed 100644 --- a/service/origin_ca/service.go +++ b/service/origin_ca/service.go @@ -338,7 +338,7 @@ func (s *Service) requestCertificate(ctx context.Context) ([]byte, []byte, *tls. } privateKey = ecKey default: - return nil, nil, nil, nil, E.New("unsupported Cloudflare Origin CA request type: ", s.requestType) + return nil, nil, nil, nil, E.New("unsupported Cloudflare Origin CA request type: ", string(s.requestType)) } privateKeyDER, err := x509.MarshalPKCS8PrivateKey(privateKey) if err != nil {