cvss-suite 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6aacfd5bb6fb48310c6c6c5cb2821a247971ef6115cb7c4c86dddb4335d8dafd
4
- data.tar.gz: 5c881abb0186de84cb10596ff12333a9e8934ed290b8fe762471aaf82f008177
3
+ metadata.gz: 792fd7bf771ac83da4c5a4ee81cfce2e5ce42edf32d3a8d84ecdccdb8df1f555
4
+ data.tar.gz: 6bc9148983a577d0e26ed5b19407ba6a366070e46166aae1a0b440c2328a59e4
5
5
  SHA512:
6
- metadata.gz: 293c41865c1905f2ca44a34d7298813484312af93deb77f443411222df307df80f4a40781af2137b05f561e66fd8317196b5a8512ea82c21d565d4eb221492ff
7
- data.tar.gz: 3c33b092a180ca728add5bcb4380881789f98652cf5476eb841ee23ee8b38a72e56cd7be916cfb297aa644d470830280826086561850c4625228a06e43bb82f2
6
+ metadata.gz: ce3abc3c7f0c6eeaa02b3739da79e61445936bc8ee2e0c066252c06477022ec1aaf752ca18400727aac8f81f3627f96cb89fd932df261168d156f000da860db6
7
+ data.tar.gz: c0ef0261fec46ae6340bf52f04e1739ffd92915b76039027fb98cf06db9ecd5e99472d31b54068c49618607ebdef6fd98e1b8a70bd2a7a097799d2321c17fe21
@@ -0,0 +1,23 @@
1
+ name: RSpec
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ ruby: [ '2.4', '2.5', '2.6', '2.7' ]
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up ${{ matrix.ruby }}
15
+ uses: actions/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ - name: Build
19
+ run: |
20
+ gem install bundler -v ">= 1.10"
21
+ bundle install --jobs 4 --retry 3
22
+ - name: Run tests
23
+ run: bundle exec rspec spec
@@ -1,2 +1,7 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
1
3
  Metrics/LineLength:
2
- Max: 120
4
+ Max: 120
5
+
6
+ Style/FrozenStringLiteralComment:
7
+ Enabled: false
@@ -0,0 +1,124 @@
1
+ # `rubocop --auto-gen-config`
2
+ # on 2020-05-05 17:47:10 +0200 using RuboCop version 0.82.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 1
9
+ Lint/IneffectiveAccessModifier:
10
+ Exclude:
11
+ - 'lib/cvss_suite.rb'
12
+
13
+ # Offense count: 1
14
+ # Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
15
+ Lint/UselessAccessModifier:
16
+ Exclude:
17
+ - 'lib/cvss_suite.rb'
18
+
19
+ # Offense count: 3
20
+ Lint/UselessAssignment:
21
+ Exclude:
22
+ - 'lib/cvss_suite/cvss.rb'
23
+ - 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
24
+ - 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
25
+
26
+ # Offense count: 8
27
+ # Configuration parameters: IgnoredMethods.
28
+ Metrics/AbcSize:
29
+ Max: 35
30
+
31
+ # Offense count: 5
32
+ # Configuration parameters: CountComments, ExcludedMethods.
33
+ # ExcludedMethods: refine
34
+ Metrics/BlockLength:
35
+ Max: 50
36
+
37
+ # Offense count: 2
38
+ # Configuration parameters: CountComments.
39
+ Metrics/ClassLength:
40
+ Max: 102
41
+
42
+ # Offense count: 2
43
+ # Configuration parameters: CountComments.
44
+ Metrics/ClassLength:
45
+ Max: 101
46
+
47
+ # Offense count: 1
48
+ # Configuration parameters: IgnoredMethods.
49
+ Metrics/CyclomaticComplexity:
50
+ Max: 9
51
+
52
+ # Offense count: 13
53
+ # Configuration parameters: CountComments, ExcludedMethods.
54
+ Metrics/MethodLength:
55
+ Max: 63
56
+
57
+ # Offense count: 1
58
+ # Configuration parameters: CountKeywordArgs.
59
+ Metrics/ParameterLists:
60
+ Max: 6
61
+
62
+ # Offense count: 1
63
+ # Configuration parameters: IgnoredMethods.
64
+ Metrics/PerceivedComplexity:
65
+ Max: 10
66
+
67
+ # Offense count: 1
68
+ Naming/AccessorMethodName:
69
+ Exclude:
70
+ - 'lib/cvss_suite/cvss_property.rb'
71
+
72
+ # Offense count: 31
73
+ # Configuration parameters: AllowedChars.
74
+ Style/AsciiComments:
75
+ Enabled: false
76
+
77
+ # Offense count: 20
78
+ Style/Documentation:
79
+ Enabled: false
80
+
81
+ # Offense count: 2
82
+ # Configuration parameters: MinBodyLength.
83
+ Style/GuardClause:
84
+ Exclude:
85
+ - 'lib/cvss_suite/helpers/extensions.rb'
86
+
87
+ # Offense count: 1
88
+ # Cop supports --auto-correct.
89
+ Style/IfUnlessModifier:
90
+ Exclude:
91
+ - 'lib/cvss_suite.rb'
92
+
93
+ # Offense count: 2
94
+ # Cop supports --auto-correct.
95
+ # Configuration parameters: EnforcedStyle.
96
+ # SupportedStyles: literals, strict
97
+ Style/MutableConstant:
98
+ Exclude:
99
+ - 'lib/cvss_suite.rb'
100
+ - 'lib/cvss_suite/version.rb'
101
+
102
+ # Offense count: 8
103
+ # Cop supports --auto-correct.
104
+ # Configuration parameters: Strict.
105
+ Style/NumericLiterals:
106
+ MinDigits: 7
107
+
108
+ # Offense count: 3
109
+ # Cop supports --auto-correct.
110
+ # Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
111
+ # SupportedStyles: predicate, comparison
112
+ Style/NumericPredicate:
113
+ Exclude:
114
+ - 'spec/**/*'
115
+ - 'lib/cvss_suite/cvss2/cvss2_base.rb'
116
+ - 'lib/cvss_suite/helpers/extensions.rb'
117
+
118
+ # Offense count: 1
119
+ # Cop supports --auto-correct.
120
+ # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods.
121
+ # AllowedMethods: present?, blank?, presence, try, try!
122
+ Style/SafeNavigation:
123
+ Exclude:
124
+ - 'lib/cvss_suite/cvss_metric.rb'
data/CHANGES.md CHANGED
@@ -2,6 +2,30 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [1.2.1] - 2020-05-10
6
+
7
+ ### Improvements
8
+ * Added CvssSuite module to every class (thanks to @fwininger)
9
+ * Removed override for integer and float (thanks to @fwininger)
10
+ * Added rubocop to development environment (thanks to @fwininger)
11
+
12
+ ### Notes
13
+ Adding CvssSuite module everywhere means it’s no longer possible to access a class without it. Since this only affects the undocumented and ‚internal‘ classes this should not affect you. If you’re using them, stop it.
14
+
15
+ Still works:
16
+
17
+ ```ruby
18
+ cvss = CvssSuite.new('string')
19
+ ```
20
+
21
+ Won’t work anymore (without any code change):
22
+
23
+ ```ruby
24
+ cvss = Cvss31.new('string')
25
+ ```
26
+
27
+ This would need to be CvssSuite::Cvss31.new('string') to work. Or you could include the whole namespace.
28
+
5
29
  ## [1.2.0] - 2019-07-02
6
30
 
7
31
  ### Notes
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
- # CvssSuite
1
+ # CvssSuite for Ruby
2
2
 
3
3
  [![Gem Version](http://img.shields.io/gem/v/cvss-suite.svg)](https://rubygems.org/gems/cvss-suite)
4
4
  [![Ruby Version](https://img.shields.io/badge/Ruby-2.x-brightgreen.svg)](https://rubygems.org/gems/cvss-suite)
5
5
  [![Cvss Support](https://img.shields.io/badge/CVSS-v2-brightgreen.svg)](https://www.first.org/cvss/v2/guide)
6
6
  [![Cvss Support](https://img.shields.io/badge/CVSS-v3.0-brightgreen.svg)](https://www.first.org/cvss/v3.0/user-guide)
7
7
  [![Cvss Support](https://img.shields.io/badge/CVSS-v3.1-brightgreen.svg)](https://www.first.org/cvss/v3.1/user-guide)
8
+ ![RSpec](https://github.com/siemens/cvss-suite/workflows/RSpec/badge.svg)
8
9
 
9
10
  This Ruby gem helps you to process the vector of the [**Common Vulnerability Scoring System**](https://www.first.org/cvss/specification-document).
10
11
  Besides calculating the Base, Temporal and Environmental Score, you are able to extract the selected option.
@@ -105,9 +106,11 @@ There is a possibility of implementations generating different scores (+/- 0,1)
105
106
 
106
107
  ## Changelog
107
108
 
108
- [Click here to see all changes.](https://raw.githubusercontent.com/siemens/cvss-suite/master/CHANGES.md)
109
+ [Click here to see all changes.](https://github.com/siemens/cvss-suite/blob/1.x/CHANGES.md)
109
110
 
110
111
  ## Contributing
111
112
 
112
113
  Bug reports and pull requests are welcome on GitHub at https://github.com/siemens/cvss-suite. This project is intended to be a safe, welcoming space for collaboration.
113
114
 
115
+ ## References
116
+ [CvssSuite for .NET](https://github.com/oliverhamboerger/CvssSuite)
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-cayman
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "cvss_suite"
3
+ require 'bundler/setup'
4
+ require 'cvss_suite'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "cvss_suite"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -9,7 +9,8 @@
9
9
  # See the LICENSE.md file in the top-level directory.
10
10
 
11
11
  # coding: utf-8
12
- lib = File.expand_path('../lib', __FILE__)
12
+
13
+ lib = File.expand_path('lib', __dir__)
13
14
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
14
15
  require 'cvss_suite/version'
15
16
 
@@ -17,24 +18,23 @@ Gem::Specification.new do |spec|
17
18
  spec.name = 'cvss-suite'
18
19
  spec.version = CvssSuite::VERSION
19
20
  spec.license = 'MIT'
20
- spec.authors = ["Oliver Hamboerger"]
21
- spec.email = ["oliver.hamboerger@siemens.com"]
21
+ spec.authors = ['Oliver Hamboerger']
22
+ spec.email = ['oliver.hamboerger@siemens.com']
22
23
 
23
- spec.summary = %q{Ruby gem for processing cvss vectors.}
24
- spec.description = %q{This Ruby gem helps you to process the vector of the Common Vulnerability Scoring System (https://www.first.org/cvss/specification-document).
25
- Besides calculating the Base, Temporal and Environmental Score, you are able to extract the selected option.}
26
- spec.homepage = "https://siemens.github.io/cvss-suite/"
24
+ spec.summary = 'Ruby gem for processing cvss vectors.'
25
+ spec.description = 'This Ruby gem helps you to process the vector of the Common Vulnerability Scoring System (https://www.first.org/cvss/specification-document).
26
+ Besides calculating the Base, Temporal and Environmental Score, you are able to extract the selected option.'
27
+ spec.homepage = 'https://siemens.github.io/cvss-suite/'
27
28
 
28
29
  spec.required_ruby_version = '>= 2.0.0'
29
30
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
31
  spec.bindir = 'exe'
31
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
33
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
33
- spec.require_paths = ["lib"]
34
+ spec.require_paths = ['lib']
34
35
 
35
- spec.add_development_dependency "bundler", "~> 1.10"
36
- spec.add_development_dependency "rspec", "~> 3.4"
37
- spec.add_development_dependency "rspec-its", "~> 1.2"
38
- spec.add_development_dependency "rdoc", "~> 4.2"
39
- spec.add_development_dependency "simplecov", "~> 0.11.2"
36
+ spec.add_development_dependency 'bundler', '>= 1.10'
37
+ spec.add_development_dependency 'rspec', '~> 3.4'
38
+ spec.add_development_dependency 'rspec-its', '~> 1.2'
39
+ spec.add_development_dependency 'simplecov', '~> 0.11'
40
40
  end
@@ -12,7 +12,6 @@ require 'cvss_suite/cvss2/cvss2'
12
12
  require 'cvss_suite/cvss3/cvss3'
13
13
  require 'cvss_suite/cvss31/cvss31'
14
14
  require 'cvss_suite/version'
15
- require 'cvss_suite/helpers/extensions'
16
15
  require 'cvss_suite/errors'
17
16
  require 'cvss_suite/invalid_cvss'
18
17
 
@@ -21,9 +20,9 @@ require 'cvss_suite/invalid_cvss'
21
20
 
22
21
  module CvssSuite
23
22
  CVSS_VECTOR_BEGINNINGS = [
24
- {:string => 'AV:', :version => 2},
25
- {:string => 'CVSS:3.0/', :version => 3.0},
26
- {:string => 'CVSS:3.1/', :version => 3.1}
23
+ { string: 'AV:', version: 2 },
24
+ { string: 'CVSS:3.0/', version: 3.0 },
25
+ { string: 'CVSS:3.1/', version: 3.1 }
27
26
  ]
28
27
 
29
28
  ##
@@ -31,14 +30,15 @@ module CvssSuite
31
30
 
32
31
  def self.new(vector)
33
32
  return InvalidCvss.new unless vector.is_a? String
33
+
34
34
  @vector_string = vector
35
35
  case version
36
36
  when 2
37
- Cvss2.new(@vector_string, version)
37
+ Cvss2.new(@vector_string)
38
38
  when 3.0
39
- Cvss3.new(@vector_string, version)
39
+ Cvss3.new(@vector_string)
40
40
  when 3.1
41
- Cvss31.new(@vector_string, version)
41
+ Cvss31.new(@vector_string)
42
42
  else
43
43
  InvalidCvss.new
44
44
  end
@@ -53,5 +53,4 @@ module CvssSuite
53
53
  end
54
54
  end
55
55
  end
56
-
57
56
  end
@@ -11,115 +11,111 @@
11
11
  ##
12
12
  # This class represents any CVSS vector. Do not instantiate this class!
13
13
 
14
- class Cvss
14
+ module CvssSuite
15
+ class Cvss
16
+ ##
17
+ # Metric of a CVSS vector.
15
18
 
16
- ##
17
- # Metric of a CVSS vector.
19
+ attr_reader :base, :temporal, :environmental
18
20
 
19
- attr_reader :base, :temporal, :environmental
21
+ ##
22
+ # Returns the vector itself.
20
23
 
21
- ##
22
- # Returns version of current CVSS vector.
24
+ attr_reader :vector
23
25
 
24
- attr_reader :version
26
+ ##
27
+ # Creates a new CVSS vector by a +vector+.
28
+ #
29
+ # Raises an exception if it is called on Cvss class.
25
30
 
26
- ##
27
- # Returns the vector itself.
31
+ def initialize(vector)
32
+ raise CvssSuite::Errors::InvalidParentClass, 'Do not instantiate this class!' if self.class == Cvss
28
33
 
29
- attr_reader :vector
30
-
31
- ##
32
- # Creates a new CVSS vector by a +vector+ and a +version+.
33
- #
34
- # Raises an exception if it is called on Cvss class.
35
-
36
- def initialize(vector, version)
37
- raise CvssSuite::Errors::InvalidParentClass, 'Do not instantiate this class!' if self.class == Cvss
38
- @version = version
39
- @vector = vector
40
- @properties = []
41
- extract_metrics
42
- init_metrics
43
- end
34
+ @vector = vector
35
+ @properties = []
36
+ extract_metrics
37
+ init_metrics
38
+ end
44
39
 
45
- ##
46
- # Returns if CVSS vector is valid.
40
+ ##
41
+ # Returns if CVSS vector is valid.
47
42
 
48
- def valid?
49
- if @amount_of_properties == required_amount_of_properties
43
+ def valid?
44
+ if @amount_of_properties == required_amount_of_properties
50
45
  base = @base.valid?
51
46
  temporal = @base.valid? && @temporal.valid?
52
47
  environmental = @base.valid? && @environmental.valid?
53
48
  full = @base.valid? && @temporal.valid? && @environmental.valid?
54
49
  base || temporal || environmental || full
55
- else
56
- false
50
+ else
51
+ false
52
+ end
57
53
  end
58
- end
59
54
 
60
- ##
61
- # Returns the severity of the CVSS vector.
62
-
63
- def severity
64
- check_validity
65
-
66
- score = overall_score
67
-
68
- if 0.0 == score
69
- "None"
70
- elsif (0.1..3.9).include? score
71
- "Low"
72
- elsif (4.0..6.9).include? score
73
- "Medium"
74
- elsif (7.0..8.9).include? score
75
- "High"
76
- elsif (9.0..10.0).include? score
77
- "Critical"
78
- else
79
- "None"
55
+ ##
56
+ # Returns the severity of the CVSS vector.
57
+
58
+ def severity
59
+ check_validity
60
+
61
+ score = overall_score
62
+
63
+ if score == 0.0
64
+ 'None'
65
+ elsif (0.1..3.9).include? score
66
+ 'Low'
67
+ elsif (4.0..6.9).include? score
68
+ 'Medium'
69
+ elsif (7.0..8.9).include? score
70
+ 'High'
71
+ elsif (9.0..10.0).include? score
72
+ 'Critical'
73
+ else
74
+ 'None'
75
+ end
80
76
  end
81
- end
82
77
 
83
- ##
84
- # Returns the Overall Score of the CVSS vector.
78
+ ##
79
+ # Returns the Overall Score of the CVSS vector.
85
80
 
86
- def overall_score
87
- check_validity
88
- return temporal_score if @temporal.valid? && !@environmental.valid?
89
- return environmental_score if @environmental.valid?
90
- base_score
91
- end
81
+ def overall_score
82
+ check_validity
83
+ return temporal_score if @temporal.valid? && !@environmental.valid?
84
+ return environmental_score if @environmental.valid?
92
85
 
93
- private
86
+ base_score
87
+ end
94
88
 
95
- def extract_metrics
96
- properties = prepared_vector.split('/')
97
- @amount_of_properties = properties.size
98
- properties.each_with_index do |property, index|
99
- property = property.split(':')
100
- @properties.push({ name: property[0], selected: property[1], position: index })
89
+ private
90
+
91
+ def extract_metrics
92
+ properties = prepared_vector.split('/')
93
+ @amount_of_properties = properties.size
94
+ properties.each_with_index do |property, index|
95
+ property = property.split(':')
96
+ @properties.push({ name: property[0], selected: property[1], position: index })
97
+ end
101
98
  end
102
- end
103
99
 
104
- def check_validity
105
- raise CvssSuite::Errors::InvalidVector, 'Vector is not valid!' unless valid?
106
- end
100
+ def check_validity
101
+ raise CvssSuite::Errors::InvalidVector, 'Vector is not valid!' unless valid?
102
+ end
107
103
 
108
- def prepared_vector
109
- start_of_vector = @vector.index('AV')
104
+ def prepared_vector
105
+ start_of_vector = @vector.index('AV')
110
106
 
111
- if start_of_vector.nil?
112
- String.new
113
- else
114
- @vector[start_of_vector..-1]
107
+ if start_of_vector.nil?
108
+ ''
109
+ else
110
+ @vector[start_of_vector..-1]
111
+ end
115
112
  end
116
- end
117
113
 
118
- def required_amount_of_properties
119
- total = @base.count if @base.valid?
120
- total += @temporal.count if @temporal.valid?
121
- total += @environmental.count if @environmental.valid?
122
- total ||= 0
114
+ def required_amount_of_properties
115
+ total = @base.count if @base.valid?
116
+ total += @temporal.count if @temporal.valid?
117
+ total += @environmental.count if @environmental.valid?
118
+ total ||= 0
119
+ end
123
120
  end
124
-
125
- end
121
+ end