Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static and non-exported return linters #363

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ issues:
- "Error return value of `fmt.Fprintln` is not checked"
- "Error return value of `file.Close` is not checked"
- "Error return value of `os.Setenv` is not checked"
# ECDH code needs to support a Go 1.21 toolchain
- "elliptic.([A-Za-z]+) has been deprecated since Go 1.21: for ECDH"

linters:
enable:
Expand All @@ -21,9 +23,6 @@ linters:
- misspell
- revive
- unused
disable:
# Remove from disable when all issues are fixed
- staticcheck

linters-settings:
revive:
Expand Down Expand Up @@ -53,8 +52,7 @@ linters-settings:
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
# Uncomment when all issues are fixed
# - name: unexported-return
- name: unexported-return
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
Expand Down
8 changes: 4 additions & 4 deletions internal/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (d *Dispatcher) StartSession(ctx context.Context, domain universal.Domain)
d.sessionLock.Lock()
s, ok := d.sessions[domain]
if !ok {
d.sessions[domain], err = NewSession(d.privateKey, d.conn.VIN())
d.sessions[domain], err = newSession(d.privateKey, d.conn.VIN())
s = d.sessions[domain]
} else if s != nil && s.ctx != nil {
log.Info("Session for %s loaded from cache", domain)
Expand Down Expand Up @@ -202,7 +202,7 @@ func (d *Dispatcher) checkForSessionUpdate(message *universal.RoutableMessage, h
return
}

if err = session.ProcessHello(message.GetRequestUuid(), sessionInfo, tag); err != nil {
if err = session.processHello(message.GetRequestUuid(), sessionInfo, tag); err != nil {
log.Warning("[%02x] Session info error: %s", message.GetRequestUuid(), err)
return
}
Expand Down Expand Up @@ -411,7 +411,7 @@ func (d *Dispatcher) Send(ctx context.Context, message *universal.RoutableMessag
log.Warning("No session available for %s", message.GetToDestination().GetDomain())
return nil, protocol.ErrNoSession
}
if err := session.Authorize(ctx, message, auth); err != nil {
if err := session.authorize(ctx, message, auth); err != nil {
return nil, err
}
}
Expand Down Expand Up @@ -502,7 +502,7 @@ func (d *Dispatcher) Cache() []CacheEntry {
func (d *Dispatcher) LoadCache(entries []CacheEntry) error {
sessions := make(map[universal.Domain]*session)
for _, entry := range entries {
s, err := NewSession(d.privateKey, d.conn.VIN())
s, err := newSession(d.privateKey, d.conn.VIN())
close(s.readySignal)
s.ready = true
if err != nil {
Expand Down
20 changes: 5 additions & 15 deletions internal/dispatcher/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ type session struct {
readySignal chan struct{}
}

// NewSession creates a new session object that can authorize commands going to
// newSession creates a new session object that can authorize commands going to
// the vehicle and authenticate session info arriving from the vehicle.
func NewSession(private authentication.ECDHPrivateKey, vin string) (*session, error) {
func newSession(private authentication.ECDHPrivateKey, vin string) (*session, error) {
return &session{
private: private,
readySignal: make(chan struct{}, 1),
Expand All @@ -58,7 +58,7 @@ func (s *session) decrypt(message *universal.RoutableMessage, handler *receiver)
return nil
}

func (s *session) Authorize(ctx context.Context, command *universal.RoutableMessage, method connector.AuthMethod) error {
func (s *session) authorize(ctx context.Context, command *universal.RoutableMessage, method connector.AuthMethod) error {
var err error
lifetime := defaultExpiration
if deadline, ok := ctx.Deadline(); ok {
Expand Down Expand Up @@ -97,16 +97,6 @@ func (s *session) Authorize(ctx context.Context, command *universal.RoutableMess
}
}

// VehiclePublicKeyBytes returns the encoded remote public key.
func (s *session) VehiclePublicKeyBytes() []byte {
s.lock.Lock()
defer s.lock.Unlock()
if s.ctx == nil {
return nil
}
return s.ctx.RemotePublicKeyBytes()
}

func (s *session) export() []byte {
s.lock.Lock()
defer s.lock.Unlock()
Expand All @@ -120,11 +110,11 @@ func (s *session) export() []byte {
return info
}

// ProcessHello verifies a session info message from the vehicle.
// processHello verifies a session info message from the vehicle.
//
// The caller must verify that the challenge matches the UUID of a
// recently-transmitted message.
func (s *session) ProcessHello(challenge, info, tag []byte) error {
func (s *session) processHello(challenge, info, tag []byte) error {
s.lock.Lock()
defer s.lock.Unlock()

Expand Down
5 changes: 4 additions & 1 deletion pkg/proxy/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,10 @@ func ExtractCommandAction(ctx context.Context, command string, params RequestPar
if err != nil {
return nil, err
}
return func(v *vehicle.Vehicle) error { return v.SetValetMode(ctx, on, password) }, nil
if on {
return func(v *vehicle.Vehicle) error { return v.EnableValetMode(ctx, password) }, nil
}
return func(v *vehicle.Vehicle) error { return v.DisableValetMode(ctx) }, nil
case "set_vehicle_name":
name, err := params.getString("vehicle_name", true)
if err != nil {
Expand Down
Loading