grempe/tss-rb

View on GitHub

Showing 68 of 68 total issues

Method combine has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    def combine
      log('Starting combine')
      log("options : #{options.inspect}")
      shares = []

Severity: Minor
Found in lib/tss/cli_combine.rb - About 4 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method split has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    def split
      log('Starting split')
      log('options : ' + options.inspect)
      args = {}

Severity: Minor
Found in lib/tss/cli_split.rb - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method combine has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def combine
      log('Starting combine')
      log("options : #{options.inspect}")
      shares = []

Severity: Major
Found in lib/tss/cli_combine.rb - About 2 hrs to fix

    Method split has 55 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def split
          log('Starting split')
          log('options : ' + options.inspect)
          args = {}
    
    
    Severity: Major
    Found in lib/tss/cli_split.rb - About 2 hrs to fix

      Block has too many lines. [47/25]
      Open

      Gem::Specification.new do |spec|
        spec.name          = 'tss'
        spec.version       = TSS::VERSION
        spec.authors       = ['Glenn Rempe']
        spec.email         = ['glenn@rempe.us']
      Severity: Minor
      Found in tss.gemspec by rubocop

      This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

      Method combine has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def combine
            # unwrap 'human' shares into binary shares
            if all_shares_appear_human?(shares)
              @shares = convert_shares_human_to_binary(shares)
            end
      Severity: Minor
      Found in lib/tss/combiner.rb - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method combine has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def combine
            # unwrap 'human' shares into binary shares
            if all_shares_appear_human?(shares)
              @shares = convert_shares_human_to_binary(shares)
            end
      Severity: Minor
      Found in lib/tss/combiner.rb - About 1 hr to fix

        Method exit_if_binary! has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

              def exit_if_binary!(str)
                str.each_byte { |c|
                  # OK, 9 (TAB), 10 (CR), 13 (LF), >=32 for normal ASCII
                  # Usage of anything other than 10, 13, and 32-126 ASCII decimal codes
                  # looks as though contents are binary and not standard text.
        Severity: Minor
        Found in lib/tss/cli_common.rb - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method extract_secret_from_shares! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def extract_secret_from_shares!(hash_id, shares_bytes)
              secret = []
        
              # build up an Array of index values from each share
              # u[i] equal to the first octet of the ith share
        Severity: Minor
        Found in lib/tss/combiner.rb - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            Contract ({ :secret => C::SecretArg, :threshold => C::Maybe[C::ThresholdArg], :num_shares => C::Maybe[C::NumSharesArg], :identifier => C::Maybe[C::IdentifierArg], :hash_alg => C::Maybe[C::HashAlgArg], :format => C::Maybe[C::FormatArg], :padding => C::Maybe[C::Bool] }) => C::Any
            def initialize(opts = {})
        Severity: Minor
        Found in lib/tss/splitter.rb and 1 other location - About 55 mins to fix
        lib/tss/tss.rb on lines 76..77

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 44.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

          Contract ({ :secret => C::SecretArg, :threshold => C::Maybe[C::ThresholdArg], :num_shares => C::Maybe[C::NumSharesArg], :identifier => C::Maybe[C::IdentifierArg], :hash_alg => C::Maybe[C::HashAlgArg], :format => C::Maybe[C::FormatArg], :padding => C::Maybe[C::Bool] }) => C::ArrayOfShares
          def self.split(opts)
        Severity: Minor
        Found in lib/tss/tss.rb and 1 other location - About 55 mins to fix
        lib/tss/splitter.rb on lines 14..15

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 44.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Method unpad has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.unpad(str, k = TSS::PADDING_BLOCK_SIZE_BYTES)
              return str if k.zero?
              str_bytes = str.is_a?(Array) ? str : TSS::Util.utf8_to_bytes(str)
              val = str_bytes.last
              raise 'Input is not padded or padding is corrupt' if val > k
        Severity: Minor
        Found in lib/tss/util.rb - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Consider simplifying this complex logical expression.
        Open

                  if c < 9 || (c > 10 && c < 13) || (c > 13 && c < 32) || c == 127
                    err('STDIN secret appears to contain binary data.')
                    exit(1)
                  end
        Severity: Major
        Found in lib/tss/cli_common.rb - About 40 mins to fix

          Method convert_shares_human_to_binary has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def convert_shares_human_to_binary(shares)
                shares.map do |s|
                  s_b64 = s.match(Util::HUMAN_SHARE_RE)
                  if s_b64.present? && s_b64.to_a[1].present?
                    begin
          Severity: Minor
          Found in lib/tss/combiner.rb - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method split has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def split
                num_shares_not_less_than_threshold!(threshold, num_shares)
          
                # Append needed PKCS#7 padding to the string
                secret_padded = padding ? Util.pad(secret) : secret
          Severity: Minor
          Found in lib/tss/splitter.rb - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method shares_bytes_have_valid_indexes! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def shares_bytes_have_valid_indexes!(shares_bytes)
                u = shares_bytes.map do |s|
                  raise TSS::ArgumentError, 'invalid shares, no index' if s[0].blank?
                  raise TSS::ArgumentError, 'invalid shares, zero index' if s[0] == 0
                  s[0]
          Severity: Minor
          Found in lib/tss/combiner.rb - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Don't use parentheses around a literal.
          Open

            Contract ({ :secret => C::SecretArg, :threshold => C::Maybe[C::ThresholdArg], :num_shares => C::Maybe[C::NumSharesArg], :identifier => C::Maybe[C::IdentifierArg], :hash_alg => C::Maybe[C::HashAlgArg], :format => C::Maybe[C::FormatArg], :padding => C::Maybe[C::Bool] }) => C::ArrayOfShares
          Severity: Minor
          Found in lib/tss/tss.rb by rubocop

          This cop checks for redundant parentheses.

          Example:

          # bad
          (x) if ((y.z).nil?)
          
          # good
          x if y.z.nil?

          Use x.zero? instead of x == 0.
          Open

                raise TSS::Error, 'invalid share index value, cannot be 0' if x == 0
          Severity: Minor
          Found in lib/tss/util.rb by rubocop

          This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

          The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

          The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

          Example: EnforcedStyle: predicate (default)

          # bad
          
          foo == 0
          0 > foo
          bar.baz > 0
          
          # good
          
          foo.zero?
          foo.negative?
          bar.baz.positive?

          Example: EnforcedStyle: comparison

          # bad
          
          foo.zero?
          foo.negative?
          bar.baz.positive?
          
          # good
          
          foo == 0
          0 > foo
          bar.baz > 0

          Use r.zero? instead of r == 0.
          Open

                r == 0
          Severity: Minor
          Found in lib/tss/util.rb by rubocop

          This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

          The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

          The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

          Example: EnforcedStyle: predicate (default)

          # bad
          
          foo == 0
          0 > foo
          bar.baz > 0
          
          # good
          
          foo.zero?
          foo.negative?
          bar.baz.positive?

          Example: EnforcedStyle: comparison

          # bad
          
          foo.zero?
          foo.negative?
          bar.baz.positive?
          
          # good
          
          foo == 0
          0 > foo
          bar.baz > 0

          Missing magic comment # frozen_string_literal: true.
          Open

          module TSS
          Severity: Minor
          Found in lib/tss/hasher.rb by rubocop

          This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

          Example: EnforcedStyle: when_needed (default)

          # The `when_needed` style will add the frozen string literal comment
          # to files only when the `TargetRubyVersion` is set to 2.3+.
          # bad
          module Foo
            # ...
          end
          
          # good
          # frozen_string_literal: true
          
          module Foo
            # ...
          end

          Example: EnforcedStyle: always

          # The `always` style will always add the frozen string literal comment
          # to a file, regardless of the Ruby version or if `freeze` or `<<` are
          # called on a string literal.
          # bad
          module Bar
            # ...
          end
          
          # good
          # frozen_string_literal: true
          
          module Bar
            # ...
          end

          Example: EnforcedStyle: never

          # The `never` will enforce that the frozen string literal comment does
          # not exist in a file.
          # bad
          # frozen_string_literal: true
          
          module Baz
            # ...
          end
          
          # good
          module Baz
            # ...
          end
          Severity
          Category
          Status
          Source
          Language