polkadot-js/common

View on GitHub
packages/util-crypto/src/nacl/tweetnacl.ts

Summary

Maintainability
D
2 days
Test Coverage

Function crypto_onetimeauth has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

function crypto_onetimeauth (out: Uint8Array, outpos: number, m: Uint8Array, mpos: number, n: number, k: Uint8Array): number {
  let i, j, u;
  const x = new Uint32Array(17), r = new Uint32Array(17), h = new Uint32Array(17), c = new Uint32Array(17), g = new Uint32Array(17);
  for (j = 0; j < 17; j++) r[j]=h[j]=0;
  for (j = 0; j < 16; j++) r[j]=k[j];
Severity: Minor
Found in packages/util-crypto/src/nacl/tweetnacl.ts - 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

Function core has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

function core (out: Uint8Array, inp: Uint8Array, k: Uint8Array, c: Uint8Array, h: boolean): void {
  const w = new Uint32Array(16), x = new Uint32Array(16), y = new Uint32Array(16), t = new Uint32Array(4);
  let i, j, m;

  for (i = 0; i < 4; i++) {
Severity: Minor
Found in packages/util-crypto/src/nacl/tweetnacl.ts - 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

Function crypto_stream_salsa20_xor has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

function crypto_stream_salsa20_xor (c: Uint8Array, cpos: number, m: Uint8Array | null, mpos: number, b: number, n: Uint8Array, k: Uint8Array): number {
  const z = new Uint8Array(16), x = new Uint8Array(64);
  let u, i;
  if (!b) return 0;
  for (i = 0; i < 16; i++) z[i] = 0;
Severity: Minor
Found in packages/util-crypto/src/nacl/tweetnacl.ts - 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

Function crypto_onetimeauth has 46 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function crypto_onetimeauth (out: Uint8Array, outpos: number, m: Uint8Array, mpos: number, n: number, k: Uint8Array): number {
  let i, j, u;
  const x = new Uint32Array(17), r = new Uint32Array(17), h = new Uint32Array(17), c = new Uint32Array(17), g = new Uint32Array(17);
  for (j = 0; j < 17; j++) r[j]=h[j]=0;
  for (j = 0; j < 16; j++) r[j]=k[j];
Severity: Minor
Found in packages/util-crypto/src/nacl/tweetnacl.ts - About 1 hr to fix

    Function core has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function core (out: Uint8Array, inp: Uint8Array, k: Uint8Array, c: Uint8Array, h: boolean): void {
      const w = new Uint32Array(16), x = new Uint32Array(16), y = new Uint32Array(16), t = new Uint32Array(4);
      let i, j, m;
    
      for (i = 0; i < 4; i++) {
    Severity: Minor
    Found in packages/util-crypto/src/nacl/tweetnacl.ts - About 1 hr to fix

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

      function crypto_stream_salsa20_xor (c: Uint8Array, cpos: number, m: Uint8Array | null, mpos: number, b: number, n: Uint8Array, k: Uint8Array): number {
      Severity: Major
      Found in packages/util-crypto/src/nacl/tweetnacl.ts - About 50 mins to fix

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

        function crypto_stream_xor (c: Uint8Array, cpos: number, m: Uint8Array | null, mpos: number, d: number, n: Uint8Array, k: Uint8Array): number {
        Severity: Major
        Found in packages/util-crypto/src/nacl/tweetnacl.ts - About 50 mins to fix

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

          function crypto_onetimeauth (out: Uint8Array, outpos: number, m: Uint8Array, mpos: number, n: number, k: Uint8Array): number {
          Severity: Minor
          Found in packages/util-crypto/src/nacl/tweetnacl.ts - About 45 mins to fix

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

            function crypto_onetimeauth_verify (h: Uint8Array, hpos: number, m: Uint8Array, mpos: number, n: number, k: Uint8Array) {
            Severity: Minor
            Found in packages/util-crypto/src/nacl/tweetnacl.ts - About 45 mins to fix

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

              function core (out: Uint8Array, inp: Uint8Array, k: Uint8Array, c: Uint8Array, h: boolean): void {
              Severity: Minor
              Found in packages/util-crypto/src/nacl/tweetnacl.ts - About 35 mins to fix

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

                function vn (x: Uint8Array, xi: number, y: Uint8Array, yi: number, n: number): number {
                Severity: Minor
                Found in packages/util-crypto/src/nacl/tweetnacl.ts - About 35 mins to fix

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

                  function crypto_secretbox (c: Uint8Array, m: Uint8Array, d: number, n: Uint8Array, k: Uint8Array) {
                  Severity: Minor
                  Found in packages/util-crypto/src/nacl/tweetnacl.ts - About 35 mins to fix

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

                    function crypto_secretbox_open (m: Uint8Array, c: Uint8Array, d: number, n: Uint8Array, k: Uint8Array): number {
                    Severity: Minor
                    Found in packages/util-crypto/src/nacl/tweetnacl.ts - About 35 mins to fix

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

                          for (j = 0; j < 16; j++) {
                            u = (u + h[j]) | 0;
                            h[j] = u & 255;
                            u >>>= 8;
                          }
                      Severity: Major
                      Found in packages/util-crypto/src/nacl/tweetnacl.ts and 1 other location - About 1 hr to fix
                      packages/util-crypto/src/nacl/tweetnacl.ts on lines 224..228

                      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 62.

                      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

                          for (j = 0; j < 16; j++) {
                            u = (u + h[j]) | 0;
                            h[j] = u & 255;
                            u >>>= 8;
                          }
                      Severity: Major
                      Found in packages/util-crypto/src/nacl/tweetnacl.ts and 1 other location - About 1 hr to fix
                      packages/util-crypto/src/nacl/tweetnacl.ts on lines 231..235

                      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 62.

                      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

                      function crypto_stream_xor (c: Uint8Array, cpos: number, m: Uint8Array | null, mpos: number, d: number, n: Uint8Array, k: Uint8Array): number {
                        const s = new Uint8Array(32);
                        core(s, n, k, sigma, true);
                        return crypto_stream_salsa20_xor(c, cpos, m, mpos, d, n.subarray(16), s);
                      }
                      Severity: Minor
                      Found in packages/util-crypto/src/nacl/tweetnacl.ts and 1 other location - About 35 mins to fix
                      packages/util-crypto/src/nacl/tweetnacl.ts on lines 146..170

                      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 47.

                      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

                      function crypto_stream_salsa20_xor (c: Uint8Array, cpos: number, m: Uint8Array | null, mpos: number, b: number, n: Uint8Array, k: Uint8Array): number {
                        const z = new Uint8Array(16), x = new Uint8Array(64);
                        let u, i;
                        if (!b) return 0;
                        for (i = 0; i < 16; i++) z[i] = 0;
                      Severity: Minor
                      Found in packages/util-crypto/src/nacl/tweetnacl.ts and 1 other location - About 35 mins to fix
                      packages/util-crypto/src/nacl/tweetnacl.ts on lines 182..186

                      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 47.

                      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

                      There are no issues that match your filters.

                      Category
                      Status