leifj/pyXMLSecurity

View on GitHub
src/xmlsec/__init__.py

Summary

Maintainability
F
3 days
Test Coverage

Function _process_references has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
Open

def _process_references(t, sig, verify_mode=True, sig_path=".//{%s}Signature" % NS['ds'], drop_signature=False):
    """
    :returns: hash algorithm as string
    """

Severity: Minor
Found in src/xmlsec/__init__.py - About 1 day 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

File __init__.py has 394 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# This code was inspired by https://github.com/andrewdyates/xmldsig
# and includes https://github.com/andrewdyates/rsa_x509_pem with
# permission from the author.

__author__ = 'leifj'
Severity: Minor
Found in src/xmlsec/__init__.py - About 5 hrs to fix

    Cyclomatic complexity is too high in function _process_references. (27)
    Open

    def _process_references(t, sig, verify_mode=True, sig_path=".//{%s}Signature" % NS['ds'], drop_signature=False):
        """
        :returns: hash algorithm as string
        """
    
    
    Severity: Minor
    Found in src/xmlsec/__init__.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in function sign. (18)
    Open

    def sign(t, key_spec, cert_spec=None, reference_uri='', insert_index=0, sig_path=".//{%s}Signature" % NS['ds']):
        """
        Sign an XML document. This means to 'complete' all Signature elements in the XML.
    
        :param t: XML as lxml.etree
    Severity: Minor
    Found in src/xmlsec/__init__.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Function sign has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def sign(t, key_spec, cert_spec=None, reference_uri='', insert_index=0, sig_path=".//{%s}Signature" % NS['ds']):
        """
        Sign an XML document. This means to 'complete' all Signature elements in the XML.
    
        :param t: XML as lxml.etree
    Severity: Minor
    Found in src/xmlsec/__init__.py - 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

    Cyclomatic complexity is too high in function _verify. (11)
    Open

    def _verify(t, keyspec, sig_path=".//{%s}Signature" % NS['ds'], drop_signature=False):
        """
        Verify the signature(s) in an XML document.
    
        Throws an XMLSigException on any non-matching signatures.
    Severity: Minor
    Found in src/xmlsec/__init__.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Function _verify has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    def _verify(t, keyspec, sig_path=".//{%s}Signature" % NS['ds'], drop_signature=False):
        """
        Verify the signature(s) in an XML document.
    
        Throws an XMLSigException on any non-matching signatures.
    Severity: Minor
    Found in src/xmlsec/__init__.py - About 2 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

    Cyclomatic complexity is too high in function _is_template. (8)
    Open

    def _is_template(sig):
        si = sig.find(".//{%s}SignedInfo" % NS['ds'])
        if si is None:
            return False
        dv = si.find(".//{%s}DigestValue" % NS['ds'])
    Severity: Minor
    Found in src/xmlsec/__init__.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Function add_enveloped_signature has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def add_enveloped_signature(t,
    Severity: Major
    Found in src/xmlsec/__init__.py - About 50 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if nsprefix in r.nsmap:
                              obj_copy.nsmap[nsprefix] = r.nsmap[nsprefix]
      
      
      Severity: Major
      Found in src/xmlsec/__init__.py - About 45 mins to fix

        Function sign has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def sign(t, key_spec, cert_spec=None, reference_uri='', insert_index=0, sig_path=".//{%s}Signature" % NS['ds']):
        Severity: Minor
        Found in src/xmlsec/__init__.py - About 45 mins to fix

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

          def _transform(uri, t, tr=None, schema=None, sig_path=".//{%s}Signature" % NS['ds']):
          Severity: Minor
          Found in src/xmlsec/__init__.py - About 35 mins to fix

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

            def _c14n(t, exclusive, with_comments, inclusive_prefix_list=None, schema=None):
            Severity: Minor
            Found in src/xmlsec/__init__.py - About 35 mins to fix

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

              def _enveloped_signature_template(c14n_method,
              Severity: Minor
              Found in src/xmlsec/__init__.py - About 35 mins to fix

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

                def _process_references(t, sig, verify_mode=True, sig_path=".//{%s}Signature" % NS['ds'], drop_signature=False):
                Severity: Minor
                Found in src/xmlsec/__init__.py - About 35 mins to fix

                  XXX found
                  Open

                          # XXX create signature reference duplicates/overlaps process references unless a c14 is part of transforms
                  Severity: Minor
                  Found in src/xmlsec/__init__.py by fixme

                  TODO found
                  Open

                  ## TODO - support transforms with arguments
                  Severity: Minor
                  Found in src/xmlsec/__init__.py by fixme

                  TODO found
                  Open

                  def _signed_value(data, key_size, do_pad, hash_alg):  # TODO Do proper asn1 CMS
                  Severity: Minor
                  Found in src/xmlsec/__init__.py by fixme

                  XXX found
                  Open

                          if public.keysize and private.keysize:  # XXX maybe one set and one not set should also raise exception?
                  Severity: Minor
                  Found in src/xmlsec/__init__.py by fixme

                  There are no issues that match your filters.

                  Category
                  Status