mirror of
https://github.com/securego/gosec.git
synced 2025-11-23 22:15:04 +02:00
Extract the issue in its own package
This commit is contained in:
committed by
Cosmin Cojocar
parent
31e63276f1
commit
de2c6a36fa
13
rules/rsa.go
13
rules/rsa.go
@@ -19,10 +19,11 @@ import (
|
||||
"go/ast"
|
||||
|
||||
"github.com/securego/gosec/v2"
|
||||
"github.com/securego/gosec/v2/issue"
|
||||
)
|
||||
|
||||
type weakKeyStrength struct {
|
||||
gosec.MetaData
|
||||
issue.MetaData
|
||||
calls gosec.CallList
|
||||
bits int
|
||||
}
|
||||
@@ -31,10 +32,10 @@ func (w *weakKeyStrength) ID() string {
|
||||
return w.MetaData.ID
|
||||
}
|
||||
|
||||
func (w *weakKeyStrength) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) {
|
||||
func (w *weakKeyStrength) Match(n ast.Node, c *gosec.Context) (*issue.Issue, error) {
|
||||
if callExpr := w.calls.ContainsPkgCallExpr(n, c, false); callExpr != nil {
|
||||
if bits, err := gosec.GetInt(callExpr.Args[1]); err == nil && bits < (int64)(w.bits) {
|
||||
return gosec.NewIssue(c, n, w.ID(), w.What, w.Severity, w.Confidence), nil
|
||||
return c.NewIssue(n, w.ID(), w.What, w.Severity, w.Confidence), nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
@@ -48,10 +49,10 @@ func NewWeakKeyStrength(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
|
||||
return &weakKeyStrength{
|
||||
calls: calls,
|
||||
bits: bits,
|
||||
MetaData: gosec.MetaData{
|
||||
MetaData: issue.MetaData{
|
||||
ID: id,
|
||||
Severity: gosec.Medium,
|
||||
Confidence: gosec.High,
|
||||
Severity: issue.Medium,
|
||||
Confidence: issue.High,
|
||||
What: fmt.Sprintf("RSA keys should be at least %d bits", bits),
|
||||
},
|
||||
}, []ast.Node{(*ast.CallExpr)(nil)}
|
||||
|
||||
Reference in New Issue
Block a user