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 16a7631 commit 2b51460
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ linters:
- exhaustive
- exportloopref
- gci
- godot
- gofmt
- goheader
- goimports
Expand All @@ -51,6 +50,7 @@ linters:
- unconvert
- unused
- whitespace
# - 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 2b51460

Please sign in to comment.