gopkg.in/alecthomas/gometalinter.v3@v3.0.0/_linters/src/github.com/securego/gosec/rules/big.go (about) 1 // (c) Copyright 2016 Hewlett Packard Enterprise Development LP 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package rules 16 17 import ( 18 "go/ast" 19 20 "github.com/securego/gosec" 21 ) 22 23 type usingBigExp struct { 24 gosec.MetaData 25 pkg string 26 calls []string 27 } 28 29 func (r *usingBigExp) ID() string { 30 return r.MetaData.ID 31 } 32 33 func (r *usingBigExp) Match(n ast.Node, c *gosec.Context) (gi *gosec.Issue, err error) { 34 if _, matched := gosec.MatchCallByType(n, c, r.pkg, r.calls...); matched { 35 return gosec.NewIssue(c, n, r.ID(), r.What, r.Severity, r.Confidence), nil 36 } 37 return nil, nil 38 } 39 40 // NewUsingBigExp detects issues with modulus == 0 for Bignum 41 func NewUsingBigExp(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { 42 return &usingBigExp{ 43 pkg: "*math/big.Int", 44 calls: []string{"Exp"}, 45 MetaData: gosec.MetaData{ 46 ID: id, 47 What: "Use of math/big.Int.Exp function should be audited for modulus == 0", 48 Severity: gosec.Low, 49 Confidence: gosec.High, 50 }, 51 }, []ast.Node{(*ast.CallExpr)(nil)} 52 }