node-opcua/node-opcua-crypto

View on GitHub

Showing 31 of 107 total issues

Function readTbsCertificate has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

export function readTbsCertificate(buffer: Buffer, block: BlockInfo): TbsCertificate {
    const blocks = readStruct(buffer, block);

    let version, serialNumber, signature, issuer, validity, subject, subjectFingerPrint, extensions;
    let subjectPublicKeyInfo: SubjectPublicKeyInfo;
Severity: Minor
Found in packages/node-opcua-crypto/source/crypto_explore_certificate.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 _readGeneralNames has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

function _readGeneralNames(buffer: Buffer, block: BlockInfo) {
    const _data: { [key: number]: { name: string; type: string } } = {
        1: { name: "rfc822Name", type: "IA5String" },
        2: { name: "dNSName", type: "IA5String" },
        3: { name: "x400Address", type: "ORAddress" },
Severity: Minor
Found in packages/node-opcua-crypto/source/crypto_explore_certificate.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 exploreAsn1 has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

export function exploreAsn1(buffer: Buffer) {
    console.log(hexDump(buffer));

    function dump(offset: number, depth: number) {
        const blockInfo = readTag(buffer, offset);
Severity: Minor
Found in packages/node-opcua-crypto/source/explore_asn1.ts - About 45 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 publicEncrypt_long has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    buffer: Buffer,
    publicKey: KeyLike,
    blockSize: number,
    padding?: number,
    paddingAlgorithm?: PaddingAlgorithm
Severity: Minor
Found in packages/node-opcua-crypto/source/crypto_utils.ts - About 35 mins to fix

    Function toStringInternal has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public toStringInternal(sep: string): string {
            // https://reference.opcfoundation.org/v104/GDS/docs/7.6.4/
            // The format of the subject name is a sequence of name value pairs separated by a ‘/’.
            // The name shall be one of ‘CN’, ‘O’, ‘OU’, ‘DC’, ‘L’, ‘S’ or ‘C’ and
            // shall be followed by a ‘=’ and then followed by the value.
    Severity: Minor
    Found in packages/node-opcua-crypto/source/subject.ts - About 35 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 toPem2 has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    export function toPem2(raw_key: Buffer | string | KeyObject | PrivateKey, pem: string): string {
        if ((raw_key as PrivateKey).hidden) {
            return toPem2((raw_key as PrivateKey).hidden, pem);
        }
        assert(raw_key, "expecting a key");
    Severity: Minor
    Found in packages/node-opcua-crypto/source/crypto_utils2.ts - About 35 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

    Avoid too many return statements within this function.
    Open

        return {
            status: "Good",
            reason: `certificate chain is valid(length = ${certificateChain.length})`,
        };
    Severity: Major
    Found in packages/node-opcua-crypto/source/verify_certificate_signature.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return {
                      status: "BadCertificateInvalid",
                      reason: "subjectKeyIdentifier authorityKeyIdentifier in child certificate do not match subjectKeyIdentifier of parent certificate",
                  };
      Severity: Major
      Found in packages/node-opcua-crypto/source/verify_certificate_signature.ts - About 30 mins to fix

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

        export function toPem(raw_key: Buffer | string, pem: string): string {
            assert(raw_key, "expecting a key");
            assert(typeof pem === "string");
            let pemType = identifyPemType(raw_key);
            if (pemType) {
        Severity: Minor
        Found in packages/node-opcua-crypto/source/crypto_utils.ts - 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

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

        export function parseBitString(buffer: Buffer, start: number, end: number, maxLength: number): string {
            const unusedBit = buffer.readUInt8(start),
                lenBit = ((end - start - 1) << 3) - unusedBit,
                intro = "(" + lenBit + " bit)\n";
        
        
        Severity: Minor
        Found in packages/node-opcua-crypto/source/asn1.ts - 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

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

        export async function _coercePrivateKey(privateKey: any): Promise<KeyObject> {
            const KeyObject = (crypto as any).KeyObject;
            if (privateKey instanceof Buffer) {
                const privateKey1 = await derToPrivateKey(privateKey); //
                return KeyObject.from(privateKey1);
        Severity: Minor
        Found in packages/node-opcua-crypto/source/x509/coerce_private_key.ts - 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

        Severity
        Category
        Status
        Source
        Language