tlsfuzzer/tlslite-ng

View on GitHub
tlslite/utils/rsakey.py

Summary

Maintainability
D
2 days
Test Coverage
A
92%

File rsakey.py has 491 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Author: Trevor Perrin
# See the LICENSE file for legal information regarding use of this file.

"""Abstract class for RSA."""

Severity: Minor
Found in tlslite/utils/rsakey.py - About 7 hrs to fix

    RSAKey has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class RSAKey(object):
        """This is an abstract base class for RSA keys.
    
        Particular implementations of RSA keys, such as
        :py:class:`~.openssl_rsakey.OpenSSL_RSAKey`,
    Severity: Minor
    Found in tlslite/utils/rsakey.py - About 3 hrs to fix

      Function verify has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def verify(self, sigBytes, bytes, padding='pkcs1', hashAlg=None,
                     saltLen=None):
              """Verify the passed-in bytes with the signature.
      
              This verifies a PKCS1 signature on the passed-in data.
      Severity: Minor
      Found in tlslite/utils/rsakey.py - 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

      Function decrypt has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def decrypt(self, encBytes):
              """Decrypt the passed-in bytes.
      
              This requires the key to have a private component.  It performs
              PKCS#1 v1.5 decryption operation of the passed-in data.
      Severity: Minor
      Found in tlslite/utils/rsakey.py - About 1 hr to fix

        Function EMSA_PSS_verify has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def EMSA_PSS_verify(self, mHash, EM, emBits, hAlg, sLen=0):
                """Verify signature in passed in encoded message
        
                This verifies the signature in encoded message
        
        
        Severity: Minor
        Found in tlslite/utils/rsakey.py - 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

        Function EMSA_PSS_verify has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def EMSA_PSS_verify(self, mHash, EM, emBits, hAlg, sLen=0):
        Severity: Minor
        Found in tlslite/utils/rsakey.py - About 35 mins to fix

          Function verify has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def verify(self, sigBytes, bytes, padding='pkcs1', hashAlg=None,
          Severity: Minor
          Found in tlslite/utils/rsakey.py - About 35 mins to fix

            Function hashAndVerify has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def hashAndVerify(self, sigBytes, bytes, rsaScheme='PKCS1', hAlg='sha1',
            Severity: Minor
            Found in tlslite/utils/rsakey.py - About 35 mins to fix

              Function decrypt has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def decrypt(self, encBytes):
                      """Decrypt the passed-in bytes.
              
                      This requires the key to have a private component.  It performs
                      PKCS#1 v1.5 decryption operation of the passed-in data.
              Severity: Minor
              Found in tlslite/utils/rsakey.py - 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

              Whitespace before ':'
              Open

                  _pkcs1Prefixes = {'md5' : bytearray([0x30, 0x20, 0x30, 0x0c, 0x06, 0x08,
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Avoid extraneous whitespace.

              Avoid extraneous whitespace in these situations:
              - Immediately inside parentheses, brackets or braces.
              - Immediately before a comma, semicolon, or colon.
              
              Okay: spam(ham[1], {eggs: 2})
              E201: spam( ham[1], {eggs: 2})
              E201: spam(ham[ 1], {eggs: 2})
              E201: spam(ham[1], { eggs: 2})
              E202: spam(ham[1], {eggs: 2} )
              E202: spam(ham[1 ], {eggs: 2})
              E202: spam(ham[1], {eggs: 2 })
              
              E203: if x == 4: print x, y; x, y = y , x
              E203: if x == 4: print x, y ; x, y = y, x
              E203: if x == 4 : print x, y; x, y = y, x

              Too many blank lines (2)
              Open

                  # **************************************************************************
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Separate top-level function and class definitions with two blank lines.

              Method definitions inside a class are separated by a single blank
              line.
              
              Extra blank lines may be used (sparingly) to separate groups of
              related functions.  Blank lines may be omitted between a bunch of
              related one-liners (e.g. a set of dummy implementations).
              
              Use blank lines in functions, sparingly, to indicate logical
              sections.
              
              Okay: def a():\n    pass\n\n\ndef b():\n    pass
              Okay: def a():\n    pass\n\n\nasync def b():\n    pass
              Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
              Okay: default = 1\nfoo = 1
              Okay: classify = 1\nfoo = 1
              
              E301: class Foo:\n    b = 0\n    def bar():\n        pass
              E302: def a():\n    pass\n\ndef b(n):\n    pass
              E302: def a():\n    pass\n\nasync def b(n):\n    pass
              E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
              E303: def a():\n\n\n\n    pass
              E304: @decorator\n\ndef a():\n    pass
              E305: def a():\n    pass\na()
              E306: def a():\n    def b():\n        pass\n    def c():\n        pass

              Whitespace before ':'
              Open

                                    'sha512' : bytearray([0x30, 0x51, 0x30, 0x0d, 0x06, 0x09,
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Avoid extraneous whitespace.

              Avoid extraneous whitespace in these situations:
              - Immediately inside parentheses, brackets or braces.
              - Immediately before a comma, semicolon, or colon.
              
              Okay: spam(ham[1], {eggs: 2})
              E201: spam( ham[1], {eggs: 2})
              E201: spam(ham[ 1], {eggs: 2})
              E201: spam(ham[1], { eggs: 2})
              E202: spam(ham[1], {eggs: 2} )
              E202: spam(ham[1 ], {eggs: 2})
              E202: spam(ham[1], {eggs: 2 })
              
              E203: if x == 4: print x, y; x, y = y , x
              E203: if x == 4: print x, y ; x, y = y, x
              E203: if x == 4 : print x, y; x, y = y, x

              At least two spaces before inline comment
              Open

                      if blockType == 1: #Signature padding
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Separate inline comments by at least two spaces.

              An inline comment is a comment on the same line as a statement.
              Inline comments should be separated by at least two spaces from the
              statement. They should start with a # and a single space.
              
              Each line of a block comment starts with a # and a single space
              (unless it is indented text inside the comment).
              
              Okay: x = x + 1  # Increment x
              Okay: x = x + 1    # Increment x
              Okay: # Block comment
              E261: x = x + 1 # Increment x
              E262: x = x + 1  #Increment x
              E262: x = x + 1  #  Increment x
              E265: #Block comment
              E266: ### Block comment

              Inline comment should start with '# '
              Open

                      elif blockType == 2: #Encryption padding
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Separate inline comments by at least two spaces.

              An inline comment is a comment on the same line as a statement.
              Inline comments should be separated by at least two spaces from the
              statement. They should start with a # and a single space.
              
              Each line of a block comment starts with a # and a single space
              (unless it is indented text inside the comment).
              
              Okay: x = x + 1  # Increment x
              Okay: x = x + 1    # Increment x
              Okay: # Block comment
              E261: x = x + 1 # Increment x
              E262: x = x + 1  #Increment x
              E262: x = x + 1  #  Increment x
              E265: #Block comment
              E266: ### Block comment

              Whitespace before ':'
              Open

                                    'sha224' : bytearray([0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09,
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Avoid extraneous whitespace.

              Avoid extraneous whitespace in these situations:
              - Immediately inside parentheses, brackets or braces.
              - Immediately before a comma, semicolon, or colon.
              
              Okay: spam(ham[1], {eggs: 2})
              E201: spam( ham[1], {eggs: 2})
              E201: spam(ham[ 1], {eggs: 2})
              E201: spam(ham[1], { eggs: 2})
              E202: spam(ham[1], {eggs: 2} )
              E202: spam(ham[1 ], {eggs: 2})
              E202: spam(ham[1], {eggs: 2 })
              
              E203: if x == 4: print x, y; x, y = y , x
              E203: if x == 4: print x, y ; x, y = y, x
              E203: if x == 4 : print x, y; x, y = y, x

              At least two spaces before inline comment
              Open

                      elif blockType == 2: #Encryption padding
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Separate inline comments by at least two spaces.

              An inline comment is a comment on the same line as a statement.
              Inline comments should be separated by at least two spaces from the
              statement. They should start with a # and a single space.
              
              Each line of a block comment starts with a # and a single space
              (unless it is indented text inside the comment).
              
              Okay: x = x + 1  # Increment x
              Okay: x = x + 1    # Increment x
              Okay: # Block comment
              E261: x = x + 1 # Increment x
              E262: x = x + 1  #Increment x
              E262: x = x + 1  #  Increment x
              E265: #Block comment
              E266: ### Block comment

              Trailing whitespace
              Open

                      # with the parameter omitted.  While the original intention was 
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Trailing whitespace is superfluous.

              The warning returned varies on whether the line itself is blank,
              for easier filtering for those who want to indent their blank lines.
              
              Okay: spam(1)\n#
              W291: spam(1) \n#
              W293: class Foo(object):\n    \n    bang = 12

              Whitespace before ':'
              Open

                                    'sha384' : bytearray([0x30, 0x41, 0x30, 0x0d, 0x06, 0x09,
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Avoid extraneous whitespace.

              Avoid extraneous whitespace in these situations:
              - Immediately inside parentheses, brackets or braces.
              - Immediately before a comma, semicolon, or colon.
              
              Okay: spam(ham[1], {eggs: 2})
              E201: spam( ham[1], {eggs: 2})
              E201: spam(ham[ 1], {eggs: 2})
              E201: spam(ham[1], { eggs: 2})
              E202: spam(ham[1], {eggs: 2} )
              E202: spam(ham[1 ], {eggs: 2})
              E202: spam(ham[1], {eggs: 2 })
              
              E203: if x == 4: print x, y; x, y = y , x
              E203: if x == 4: print x, y ; x, y = y, x
              E203: if x == 4 : print x, y; x, y = y, x

              Expected 1 blank line, found 0
              Open

                  @classmethod
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Separate top-level function and class definitions with two blank lines.

              Method definitions inside a class are separated by a single blank
              line.
              
              Extra blank lines may be used (sparingly) to separate groups of
              related functions.  Blank lines may be omitted between a bunch of
              related one-liners (e.g. a set of dummy implementations).
              
              Use blank lines in functions, sparingly, to indicate logical
              sections.
              
              Okay: def a():\n    pass\n\n\ndef b():\n    pass
              Okay: def a():\n    pass\n\n\nasync def b():\n    pass
              Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
              Okay: default = 1\nfoo = 1
              Okay: classify = 1\nfoo = 1
              
              E301: class Foo:\n    b = 0\n    def bar():\n        pass
              E302: def a():\n    pass\n\ndef b(n):\n    pass
              E302: def a():\n    pass\n\nasync def b(n):\n    pass
              E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
              E303: def a():\n\n\n\n    pass
              E304: @decorator\n\ndef a():\n    pass
              E305: def a():\n    pass\na()
              E306: def a():\n    def b():\n        pass\n    def c():\n        pass

              Trailing whitespace
              Open

                      # algorithmIdentifier should be encoded with a NULL parameter or 
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Trailing whitespace is superfluous.

              The warning returned varies on whether the line itself is blank,
              for easier filtering for those who want to indent their blank lines.
              
              Okay: spam(1)\n#
              W291: spam(1) \n#
              W293: class Foo(object):\n    \n    bang = 12

              Trailing whitespace
              Open

                      # always implemented.  Anyways, verification code should probably 
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Trailing whitespace is superfluous.

              The warning returned varies on whether the line itself is blank,
              for easier filtering for those who want to indent their blank lines.
              
              Okay: spam(1)\n#
              W291: spam(1) \n#
              W293: class Foo(object):\n    \n    bang = 12

              Whitespace before ':'
              Open

                                    'sha256' : bytearray([0x30, 0x31, 0x30, 0x0d, 0x06, 0x09,
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Avoid extraneous whitespace.

              Avoid extraneous whitespace in these situations:
              - Immediately inside parentheses, brackets or braces.
              - Immediately before a comma, semicolon, or colon.
              
              Okay: spam(ham[1], {eggs: 2})
              E201: spam( ham[1], {eggs: 2})
              E201: spam(ham[ 1], {eggs: 2})
              E201: spam(ham[1], { eggs: 2})
              E202: spam(ham[1], {eggs: 2} )
              E202: spam(ham[1 ], {eggs: 2})
              E202: spam(ham[1], {eggs: 2 })
              
              E203: if x == 4: print x, y; x, y = y , x
              E203: if x == 4: print x, y ; x, y = y, x
              E203: if x == 4 : print x, y; x, y = y, x

              Missing whitespace after ','
              Open

                      padding = bytearray([0,blockType] + pad + [0])
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Each comma, semicolon or colon should be followed by whitespace.

              Okay: [a, b]
              Okay: (3,)
              Okay: a[1:4]
              Okay: a[:4]
              Okay: a[1:]
              Okay: a[1:4:2]
              E231: ['a','b']
              E231: foo(bar,baz)
              E231: [{'a':'b'}]

              Whitespace before ':'
              Open

                                    'sha1' : bytearray([0x30, 0x21, 0x30, 0x09, 0x06, 0x05,
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Avoid extraneous whitespace.

              Avoid extraneous whitespace in these situations:
              - Immediately inside parentheses, brackets or braces.
              - Immediately before a comma, semicolon, or colon.
              
              Okay: spam(ham[1], {eggs: 2})
              E201: spam( ham[1], {eggs: 2})
              E201: spam(ham[ 1], {eggs: 2})
              E201: spam(ham[1], { eggs: 2})
              E202: spam(ham[1], {eggs: 2} )
              E202: spam(ham[1 ], {eggs: 2})
              E202: spam(ham[1], {eggs: 2 })
              
              E203: if x == 4: print x, y; x, y = y , x
              E203: if x == 4: print x, y ; x, y = y, x
              E203: if x == 4 : print x, y; x, y = y, x

              Inline comment should start with '# '
              Open

                      if blockType == 1: #Signature padding
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Separate inline comments by at least two spaces.

              An inline comment is a comment on the same line as a statement.
              Inline comments should be separated by at least two spaces from the
              statement. They should start with a # and a single space.
              
              Each line of a block comment starts with a # and a single space
              (unless it is indented text inside the comment).
              
              Okay: x = x + 1  # Increment x
              Okay: x = x + 1    # Increment x
              Okay: # Block comment
              E261: x = x + 1 # Increment x
              E262: x = x + 1  #Increment x
              E262: x = x + 1  #  Increment x
              E265: #Block comment
              E266: ### Block comment

              Trailing whitespace
              Open

                      # There is a long history of confusion over whether the SHA1 
              Severity: Minor
              Found in tlslite/utils/rsakey.py by pep8

              Trailing whitespace is superfluous.

              The warning returned varies on whether the line itself is blank,
              for easier filtering for those who want to indent their blank lines.
              
              Okay: spam(1)\n#
              W291: spam(1) \n#
              W293: class Foo(object):\n    \n    bang = 12

              There are no issues that match your filters.

              Category
              Status