@@ -28,95 +28,28 @@ object Pattern {
2828
2929 case class Definition (patternId : Pattern .Id , parameters : Option [Set [Parameter .Definition ]])
3030
31- trait Specification {
32- val patternId : Pattern .Id
33- val level : Result .Level
34- val category : Category
35- val subcategory : Option [Subcategory ]
36- val parameters : Option [Set [Parameter .Specification ]]
37- val languages : Option [Set [Language ]]
31+ case class Specification (patternId : Pattern .Id ,
32+ level : Result .Level ,
33+ category : Specification .Category ,
34+ subcategory : Option [Specification .Subcategory ],
35+ parameters : Option [Set [Parameter .Specification ]],
36+ languages : Option [Set [Language ]] = None ) {
37+ require(subcategory.isEmpty || category == Specification .Category .Security ,
38+ " Security is the only category having subcategories" )
3839 }
39-
4040 object Specification {
41- private case class SpecificationImpl (patternId : Pattern .Id ,
42- level : Result .Level ,
43- category : Category ,
44- subcategory : Option [Subcategory ],
45- parameters : Option [Set [Parameter .Specification ]],
46- languages : Option [Set [Language ]] = None )
47- extends Specification
48-
49- def unapply (s : Pattern .Specification ): Option [(Pattern .Id ,
50- Result .Level ,
51- Category ,
52- Option [Subcategory ],
53- Option [Set [Parameter .Specification ]],
54- Option [Set [Language ]])] = s match {
55- case si : SpecificationImpl =>
56- SpecificationImpl .unapply(si)
41+ type Category = Category .Value
42+ object Category extends Enumeration {
43+ val Security, CodeStyle, ErrorProne, Performance, Compatibility, UnusedCode, Complexity, BestPractice ,
44+ Comprehensibility , Duplication , Documentation = Value
5745 }
5846
59- def apply (patternId : Pattern .Id ,
60- level : Result .Level ,
61- category : Category ,
62- subcategory : Option [Subcategory ],
63- parameters : Option [Set [Parameter .Specification ]],
64- languages : Option [Set [Language ]] = None ): Specification = {
65- val spec = SpecificationImpl (patternId, level, category, subcategory, parameters, languages)
66-
67- spec.subcategory match {
68- case Some (sc) =>
69- sc match {
70- case Subcategory .XSS | Subcategory .Input_validation | Subcategory .File_Access | Subcategory .HTTP |
71- Subcategory .Cookies | Subcategory .Unexpected_behaviour | Subcategory .Mass_assignment |
72- Subcategory .Insecure_Storage | Subcategory .Insecure_modules_libraries | Subcategory .Visibility |
73- Subcategory .CSRF | Subcategory .Android | Subcategory .Malicious_code | Subcategory .Cryptography |
74- Subcategory .Command_Injection | Subcategory .Firefox_OS | Subcategory .Auth | Subcategory .DoS |
75- Subcategory .SQL_Injection | Subcategory .Routes | Subcategory .Regex | Subcategory .SSL | Subcategory .Other
76- if category == Category .Security =>
77- spec
47+ type Subcategory = Subcategory .Value
7848
79- case _ => throw new Exception ( " invalid sub category " )
80- }
81- case None => spec
82- }
49+ object Subcategory extends Enumeration {
50+ val XSS, InputValidation, FileAccess, HTTP, Cookies, UnexpectedBehaviour, MassAssignment, InsecureStorage ,
51+ InsecureModulesLibraries , Visibility , CSRF , Android , MaliciousCode , Cryptography , CommandInjection , FirefoxOS ,
52+ Auth , DoS , SQLInjection , Routes , Regex , SSL , Other = Value
8353 }
8454 }
85-
86- type Category = Category .Value
87-
88- object Category extends Enumeration {
89-
90- val Security, CodeStyle, ErrorProne, Performance, Compatibility, UnusedCode, Complexity, BestPractice ,
91- Comprehensibility , Duplication , Documentation = Value
92- }
93-
94- type Subcategory = Subcategory .Value
95-
96- object Subcategory extends Enumeration {
97- val XSS = Value (" XSS" )
98- val Input_validation = Value (" Input validation" )
99- val File_Access = Value (" File Access" )
100- val HTTP = Value (" HTTP" )
101- val Cookies = Value (" Cookies" )
102- val Unexpected_behaviour = Value (" Unexpected behaviour" )
103- val Mass_assignment = Value (" Mass assignment" )
104- val Insecure_Storage = Value (" Insecure Storage" )
105- val Insecure_modules_libraries = Value (" Insecure modules/libraries" )
106- val Visibility = Value (" Visibility" )
107- val CSRF = Value (" CSRF" )
108- val Android = Value (" Android" )
109- val Malicious_code = Value (" Malicious code" )
110- val Cryptography = Value (" Cryptography" )
111- val Command_Injection = Value (" Command Injection" )
112- val Firefox_OS = Value (" Firefox OS" )
113- val Auth = Value (" Auth" )
114- val DoS = Value (" DoS" )
115- val SQL_Injection = Value (" SQL Injection" )
116- val Routes = Value (" Routes" )
117- val Regex = Value (" Regex" )
118- val SSL = Value (" SSL" )
119- val Other = Value (" Other" )
120- }
121-
12255}
0 commit comments