Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kayrus committed Dec 12, 2024
1 parent 3874795 commit 686a73c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ linters:
- depguard
- dogsled
- errcheck
- exhaustive
- exportloopref
- copyloopvar
- gci
- godot
- gofmt
- goheader
- goimports
Expand All @@ -51,6 +49,8 @@ linters:
- unconvert
- unused
- whitespace
# - exhaustive
# - godot
# - cyclop
# - dupl
# - durationcheck
Expand Down
50 changes: 40 additions & 10 deletions putty.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,46 @@ func decryptCBC(cipherKey, cipherIV, macKey, ciphertext []byte) error {

// validateHMAC validates PuTTY key HMAC with a hash function
func (k Key) validateHMAC(hashFunc hash.Hash) error {
binary.Write(hashFunc, binary.BigEndian, uint32(len(k.Algo)))
hashFunc.Write([]byte(k.Algo))
binary.Write(hashFunc, binary.BigEndian, uint32(len(k.Encryption)))
hashFunc.Write([]byte(k.Encryption))
binary.Write(hashFunc, binary.BigEndian, uint32(len(k.Comment)))
hashFunc.Write([]byte(k.Comment))
binary.Write(hashFunc, binary.BigEndian, uint32(len(k.PublicKey)))
hashFunc.Write(k.PublicKey)
binary.Write(hashFunc, binary.BigEndian, uint32(len(k.PrivateKey)))
hashFunc.Write(k.PrivateKey)
err := binary.Write(hashFunc, binary.BigEndian, uint32(len(k.Algo)))
if err != nil {
return err
}
_, err = hashFunc.Write([]byte(k.Algo))
if err != nil {
return err
}
err = binary.Write(hashFunc, binary.BigEndian, uint32(len(k.Encryption)))
if err != nil {
return err
}
_, err = hashFunc.Write([]byte(k.Encryption))
if err != nil {
return err
}
err = binary.Write(hashFunc, binary.BigEndian, uint32(len(k.Comment)))
if err != nil {
return err
}
_, err = hashFunc.Write([]byte(k.Comment))
if err != nil {
return err
}
err = binary.Write(hashFunc, binary.BigEndian, uint32(len(k.PublicKey)))
if err != nil {
return err
}
_, err = hashFunc.Write(k.PublicKey)
if err != nil {
return err
}
err = binary.Write(hashFunc, binary.BigEndian, uint32(len(k.PrivateKey)))
if err != nil {
return err
}
_, err = hashFunc.Write(k.PrivateKey)
if err != nil {
return err
}

mac := hashFunc.Sum(nil)
if !bytes.Equal(mac, k.PrivateMac) {
Expand Down
1 change: 0 additions & 1 deletion putty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ Comment: a@b`
if err == nil {
t.Errorf("Invalid key algorithm")
}

}

func TestKey_Load(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func parseField(v reflect.Value, src *bytes.Reader) error {
}
}
return nil
default:
}

switch fieldType {
Expand Down

0 comments on commit 686a73c

Please sign in to comment.