junkurihara/cascade

View on GitHub

Showing 38 of 38 total issues

Function from has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

  async from(format, {keys, suite, mode}){
    // assertion
    if((mode.indexOf('encrypt') >= 0 && mode.indexOf('verify') >= 0)
      || (mode.indexOf('encrypt') >= 0 && mode.indexOf('decrypt') >= 0)
      || (mode.indexOf('decrypt') >= 0 && mode.indexOf('sign') >= 0)
Severity: Minor
Found in src/keys.js - About 5 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 decrypt has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

  static async decrypt({encrypted, keys, options}) {
    if (typeof encrypted.message === 'undefined') throw new Error('InvalidEncryptedMessage'); // TODO, change according to the class
    if (!(encrypted.message.message instanceof Array)) throw new Error('NonArrayMessage');
    const jscu = getJscu();

Severity: Minor
Found in src/suite_jscu.js - 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

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

  async decrypt(){
    if(this._cascadeMode !== 'decrypt') throw new Error('NotDecryptionCascade');

    // export verificationKey for precedence
    const verificationKeys = this._orgKeys.keys.publicKeys;
Severity: Minor
Found in src/cascade.js - 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

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

    signed = await cryptoSuite(keys.suite.sign_verify).sign({
      message: msgObj, keys: keys.keys, options: config.sign.options
    }).catch((e) => {
      throw new Error(`SigningFailed: ${e.message}`);
    });
Severity: Major
Found in src/core.js and 2 other locations - About 2 hrs to fix
src/core.js on lines 70..72
src/core.js on lines 127..131

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

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

    if (mode === 'decrypt') {
      if (!(encrypted instanceof CascadedData)) throw new Error('NotCascadedEncryptedData');
      const initial = encrypted.map( (encryptedObject) => {
        if(typeof encryptedObject.message === 'undefined') throw new Error('InvalidEncryptedMessage');
        return {data: encryptedObject};
Severity: Major
Found in src/cascade.js and 1 other location - About 2 hrs to fix
src/cascade.js on lines 46..53

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

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 3 locations. Consider refactoring.
Open

  const encrypted = await cryptoSuite(keys.suite.encrypt_decrypt).encrypt({
    message: msgObj, keys: keys.keys, options: config.encrypt.options
  }).catch( (e) => { throw new Error(`EncryptionFailed: ${e.message}`); });
Severity: Major
Found in src/core.js and 2 other locations - About 2 hrs to fix
src/core.js on lines 61..65
src/core.js on lines 127..131

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

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 3 locations. Consider refactoring.
Open

    return await cryptoSuite(keys.suite.sign_verify).sign({
      message: msgObj, keys: keys.keys, options: config.sign.options
    }).catch((e) => {
      throw new Error(`SigningFailed: ${e.message}`);
    });
Severity: Major
Found in src/core.js and 2 other locations - About 2 hrs to fix
src/core.js on lines 61..65
src/core.js on lines 70..72

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

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

    if (mode === 'encrypt') {
      if (!(procedure instanceof Array)) throw new Error('NotArrayProcedure');
      const initial = procedure.map( (config) => {
        if(typeof config.encrypt === 'undefined') throw new Error('InvalidProcedure');
        return {config};
Severity: Major
Found in src/cascade.js and 1 other location - About 2 hrs to fix
src/cascade.js on lines 55..62

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

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

  _init(keyIds){
    if (!(keyIds instanceof Array)) throw new Error('InvalidKeyIdList');
    const binaryKeyIds = keyIds.map( (k) => {
      if(!(k instanceof KeyId)) throw new Error('NotKeyId');
      return k;
Severity: Major
Found in src/keyid.js and 1 other location - About 2 hrs to fix
src/encrypted_message.js on lines 139..146

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

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

  _set(message) {
    if (!(message instanceof Array)) throw new Error('InvalidEncryptedMessageList');
    const binaryMessage = message.map((m) => {
      if (!(m instanceof RawEncryptedMessage)) throw new Error('NotEncryptedMessage');
      return m;
Severity: Major
Found in src/encrypted_message.js and 1 other location - About 2 hrs to fix
src/keyid.js on lines 64..71

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

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

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

  static async decrypt({encrypted, keys, options}) {
    if (typeof encrypted.message === 'undefined') throw new Error('InvalidEncryptedMessage'); // TODO, change according to the class
    if (!(encrypted.message.message instanceof Array)) throw new Error('NonArrayMessage');
    const jscu = getJscu();

Severity: Minor
Found in src/suite_jscu.js - About 1 hr to fix

    Function _init has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

      _init({mode, keys, procedure, encrypted}){
        // assertions
        if (modes.indexOf(mode) < 0) throw new Error('InvalidMode');
        if (!(keys instanceof Keys)) throw new Error('NotKeyObject');
        if (keys.mode.indexOf(mode) < 0) throw new Error('UnmatchedKeyMode');
    Severity: Minor
    Found in src/cascade.js - 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 encrypt has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      static async encrypt({message, keys, options}) {
        const jscu = getJscu();
    
        // check options
        if(typeof options === 'undefined') options = {};
    Severity: Minor
    Found in src/suite_jscu.js - 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 encrypt has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      static async encrypt({message, keys, options}) {
        const jscu = getJscu();
    
        // check options
        if(typeof options === 'undefined') options = {};
    Severity: Minor
    Found in src/suite_jscu.js - About 1 hr to fix

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

          if(elem.keyId instanceof Array) keyId = createKeyIdList(elem.keyId.map( (k) => createKeyId(new Uint8Array(k))));
          else keyId = createKeyId(new Uint8Array(elem.keyId));
      Severity: Major
      Found in src/encrypted_message.js and 1 other location - About 1 hr to fix
      src/encrypted_message.js on lines 43..44

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

      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

            if(decoded.keyId instanceof Array) keyId = createKeyIdList(decoded.keyId.map( (k) => createKeyId(new Uint8Array(k))));
            else keyId = createKeyId(new Uint8Array(decoded.keyId));
      Severity: Major
      Found in src/encrypted_message.js and 1 other location - About 1 hr to fix
      src/encrypted_message.js on lines 25..26

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

      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

        serialize () {
          return msgpack.encode({
            suite: this._suite,
            keyType: this._keyType,
            signatures: this._signatures.toJsObject(),
      Severity: Major
      Found in src/signature.js and 1 other location - About 1 hr to fix
      src/encrypted_message.js on lines 98..105

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

      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

        serialize() {
          return msgpack.encode({
            suite: this._suite,
            keyType: this._keyType,
            message: this._message.toJsObject(),
      Severity: Major
      Found in src/encrypted_message.js and 1 other location - About 1 hr to fix
      src/signature.js on lines 49..56

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

      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

      Consider simplifying this complex logical expression.
      Open

          if((mode.indexOf('encrypt') >= 0 && mode.indexOf('verify') >= 0)
            || (mode.indexOf('encrypt') >= 0 && mode.indexOf('decrypt') >= 0)
            || (mode.indexOf('decrypt') >= 0 && mode.indexOf('sign') >= 0)
            || (mode.indexOf('sign') >= 0 && mode.indexOf('verify') >= 0)
          ) throw new Error('InvalidMode');
      Severity: Critical
      Found in src/keys.js - About 1 hr to fix

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

          async _initEncryptionProcedure(){
            // export signingKey for precedence
            const signingKeys = this._orgKeys.keys.privateKeys;
        
            const precedence = this.slice(0, this.length -1);
        Severity: Minor
        Found in src/cascade.js - About 1 hr to fix
          Severity
          Category
          Status
          Source
          Language