src/pqc_lint/patterns/go.py
1.2 KB · 35 lines · python Raw
1 """Go crypto patterns."""
2
3 from __future__ import annotations
4
5 from pqc_lint.patterns.base import PatternMatcher, compile_patterns
6
7
8 class GoMatcher(PatternMatcher):
9 language = "go"
10 file_extensions = (".go",)
11 patterns = compile_patterns([
12 # imports
13 ("PQC001", r"""["`]crypto/rsa["`]"""),
14 ("PQC002", r"""["`]crypto/ecdsa["`]"""),
15 ("PQC003", r"""["`]crypto/ed25519["`]"""),
16 ("PQC004", r"""["`]crypto/dsa["`]"""),
17 # function calls
18 ("PQC001", r"\brsa\.GenerateKey\s*\("),
19 ("PQC001", r"\brsa\.SignPKCS1v15\s*\("),
20 ("PQC001", r"\brsa\.SignPSS\s*\("),
21 ("PQC201", r"\brsa\.EncryptOAEP\s*\("),
22 ("PQC202", r"\brsa\.EncryptPKCS1v15\s*\("),
23 ("PQC002", r"\becdsa\.GenerateKey\s*\("),
24 ("PQC002", r"\becdsa\.Sign(?:ASN1)?\s*\("),
25 ("PQC003", r"\bed25519\.GenerateKey\s*\("),
26 ("PQC003", r"\bed25519\.Sign\s*\("),
27 # hashes
28 ("PQC301", r"""["`]crypto/md5["`]"""),
29 ("PQC301", r"\bmd5\.New\s*\("),
30 ("PQC301", r"\bmd5\.Sum\s*\("),
31 ("PQC302", r"""["`]crypto/sha1["`]"""),
32 ("PQC302", r"\bsha1\.New\s*\("),
33 ("PQC302", r"\bsha1\.Sum\s*\("),
34 ])
35