junkurihara/jscu

View on GitHub

Showing 61 of 106 total issues

Function fromJwk has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

export const fromJwk = async (
  publicJwk: JsonWebKey,
  privateJwk: JsonWebKey,
  format: AsnFormat = 'pem',
  options: X509EncodingOptions = {}
Severity: Minor
Found in packages/js-x509-utils/src/x509.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 compute has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

export const compute = async (msg: Uint8Array, hash: HashTypes = 'SHA-256') : Promise<Uint8Array> => {
  const env = util.getCrypto();

  let msgHash;
  let errMsg;
Severity: Minor
Found in packages/js-crypto-hash/src/hash.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 assertAlgorithms has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

const assertAlgorithms = ({name, iv, tagLength}: aesAlgorithm) => {
  if(params.ciphers[name].ivLength){
    if(!(iv instanceof Uint8Array)) throw new Error('InvalidArguments');
    if(iv.byteLength < 2 || iv.byteLength > 16) throw new Error('InvalidIVLength');
    if(params.ciphers[name].staticIvLength && (params.ciphers[name].ivLength !== iv.byteLength)) throw new Error('InvalidIVLength');
Severity: Minor
Found in packages/js-crypto-aes/src/aes.ts - 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 fromJwk has 45 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const fromJwk = async (
  publicJwk: JsonWebKey,
  privateJwk: JsonWebKey,
  format: AsnFormat = 'pem',
  options: X509EncodingOptions = {}
Severity: Minor
Found in packages/js-x509-utils/src/x509.ts - About 1 hr to fix

    Function export has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      async export(format: KeyFormat = 'jwk', options: KeyExportOptions = {}): Promise<JsonWebKey|PEM|DER|OctetEC>{
        // return 'as is' without passphrase when nothing is given as 'options'
        // only for the case to export der key from der key (considering encrypted key). expect to be called from getter
        if(this._isEncrypted && this._type === 'private'){
          if((format === 'der' || format === 'pem') && Object.keys(options).length === 0 && this._current.der) {
    Severity: Minor
    Found in packages/js-crypto-key-utils/src/key.ts - 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 encryptPBES2 has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const encryptPBES2 = async (
      binKey: any,
      passphrase: string,
      kdfAlgorithm: string,
      prf: string,
    Severity: Minor
    Found in packages/js-crypto-key-utils/src/rfc8018.ts - About 1 hr to fix

      Function toJwk has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export const toJwk = (
        decoded: DecodedAsn1Key,
        type: PublicOrPrivate
      ): JsonWebKey => {
      
      
      Severity: Minor
      Found in packages/js-crypto-key-utils/src/asn1rsa.ts - About 1 hr to fix

        Function constructor has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          constructor(format: KeyFormat, key: JsonWebKey|PEM|DER|OctetEC, options: {namedCurve?: CurveTypes}={}){
            const localKey = cloneDeep(key);
            const localOpt = cloneDeep(options);
        
            this._type = null;
        Severity: Minor
        Found in packages/js-crypto-key-utils/src/key.ts - 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 toJwk has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

        export const toJwk = async (
          key: PEM|DER,
          format: 'pem'|'der',
          {outputPublic, passphrase}: {outputPublic?: boolean, passphrase: string}
        ): Promise<JsonWebKey> => {
        Severity: Minor
        Found in packages/js-crypto-key-utils/src/asn1enc.ts - 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 fromJwk has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

        export const fromJwk = (
          jwkey: JsonWebKey,
          {outputPublic, outputFormat='binary', compact=false}: {outputPublic?: boolean, outputFormat?: OctetFormat, compact?: boolean}
        ): Uint8Array|string => {
          // original key type
        Severity: Minor
        Found in packages/js-crypto-key-utils/src/octenc.ts - 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 compute has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

        export const compute = async (key: Uint8Array, data: Uint8Array, hash: HashTypes = 'SHA-256'): Promise<Uint8Array> => {
          const env = util.getCrypto();
        
          let msgKeyedHash;
          let errMsg;
        Severity: Minor
        Found in packages/js-crypto-hmac/src/hmac.ts - 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 sign has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

        export const sign = async (
          msg: Uint8Array,
          privateJwk: JsonWebKey,
          hash: HashTypes = 'SHA-256',
          algorithm: RSASignAlgorithm = {name: 'RSA-PSS', saltLength: params.hashes[hash].hashSize}
        Severity: Minor
        Found in packages/js-crypto-rsa/src/rsa.ts - 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 fromJwkTo has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        export const fromJwkTo = async (
          output = 'pem',
          jwkey: JsonWebKey,
          options: KeyExportOptions = {}
        ): Promise<PEM|DER|OctetEC> => {
        Severity: Minor
        Found in packages/js-crypto-key-utils/src/converter.ts - 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 deriveSecret has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        export const deriveSecret = async (publicJwk: JsonWebKey, privateJwk: JsonWebKey): Promise<Uint8Array> => {
          // assertion
          if(publicJwk.crv !== privateJwk.crv) throw new Error('UnmatchedCurveName');
          const env = util.getCrypto();
        
        
        Severity: Minor
        Found in packages/js-crypto-ec/src/ec.ts - 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 generateKey has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        export const generateKey = async (namedCurve: CurveTypes ='P-256'): Promise<JsonWebKeyPair> => {
          const env = util.getCrypto();
        
          let pure: boolean = false;
          let keyPair: JsonWebKeyPair;
        Severity: Minor
        Found in packages/js-crypto-ec/src/ec.ts - 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 sign has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        export const sign = async (
          msg: Uint8Array,
          privateJwk: JsonWebKey,
          hash: HashTypes = 'SHA-256',
          signatureFormat: SignatureFormat ='raw'
        Severity: Minor
        Found in packages/js-crypto-ec/src/ec.ts - 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 verify has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        export const verify = async (
          msg: Uint8Array,
          signature: Uint8Array,
          publicJwk: JsonWebKey,
          hash: HashTypes = 'SHA-256',
        Severity: Minor
        Found in packages/js-crypto-rsa/src/rsa.ts - 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 checkLength has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        export const checkLength = (mode: 'sign'|'verify', {k, hash, saltLength}: PssParams) => {
          if(mode === 'sign'){
            if (k > (1 << params.hashes[hash].maxInput) - 1) throw new Error('Inconsistent');
            if (k < params.hashes[hash].hashSize + saltLength + 2 || saltLength < 0) throw new Error('EncodingError');
          }
        Severity: Minor
        Found in packages/js-crypto-rsa/src/pss.ts - 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 compute has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export const compute = async (key: Uint8Array, data: Uint8Array, hash: HashTypes = 'SHA-256'): Promise<Uint8Array> => {
          const env = util.getCrypto();
        
          let msgKeyedHash;
          let errMsg;
        Severity: Minor
        Found in packages/js-crypto-hmac/src/hmac.ts - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

              if (jwkey.n && jwkey.e && jwkey.d && jwkey.p && jwkey.q && jwkey.dp && jwkey.dq && jwkey.qi) return 'private';
              else if (jwkey.n && jwkey.e) return 'public';
              else throw new Error('InvalidRSAKey');
          Severity: Critical
          Found in packages/js-crypto-key-utils/src/util.ts - About 1 hr to fix
            Severity
            Category
            Status
            Source
            Language