node-opcua/node-opcua-crypto

View on GitHub

Showing 31 of 107 total issues

File crypto_explore_certificate.ts has 472 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * @module node_opcua_crypto
 */
// ---------------------------------------------------------------------------------------------------------------------
// node-opcua-crypto
Severity: Minor
Found in packages/node-opcua-crypto/source/crypto_explore_certificate.ts - About 7 hrs to fix

    File test_crypto.ts has 391 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    // ---------------------------------------------------------------------------------------------------------------------
    // node-opcua-crypto
    // ---------------------------------------------------------------------------------------------------------------------
    // Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org
    // Copyright (c) 2022-2024 - Sterfive.com
    Severity: Minor
    Found in packages/node-opcua-crypto-test/test/test_crypto.ts - About 5 hrs to fix

      File test_peculiar_edge_case.ts has 336 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import path from "node:path";
      import fs from "node:fs";
      import { tmpdir } from "node:os";
      import { Crypto as PeculiarWebCrypto } from "@peculiar/webcrypto";
      import * as x509 from "@peculiar/x509";
      Severity: Minor
      Found in packages/node-opcua-crypto-test/test/test_peculiar_edge_case.ts - About 4 hrs to fix

        Function make_suite has 95 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function make_suite(algorithm: string, signatureLength: number) {
                it("should sign with a private key and verify with the public key - " + algorithm, function () {
                    const alice_private_key = readPrivateKey(alice_private_key_filename);
                    const options1 = {
                        algorithm,
        Severity: Major
        Found in packages/node-opcua-crypto-test/test/test_crypto.ts - About 3 hrs to fix

          File oid_map.ts has 297 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          // https://github.com/lapo-luchini/asn1js/blob/master/oids.js
          export const oid_map: { [key: string]: { d: string; c: string; w?: boolean } } = {
              "0.9.2342.19200300.100.1.1": { d: "userID", c: "Some oddball X.500 attribute collection" },
              "0.9.2342.19200300.100.1.3": { d: "rfc822Mailbox", c: "Some oddball X.500 attribute collection" },
              "0.9.2342.19200300.100.1.25": { d: "domainComponent", c: "Men are from Mars, this OID is from Pluto" },
          Severity: Minor
          Found in packages/node-opcua-crypto/source/oid_map.ts - About 3 hrs to fix

            Function explorePrivateKey has 69 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function explorePrivateKey(privateKey2: PrivateKey): PrivateKeyInternals {
                const privateKey1 = privateKey2.hidden;
                const privateKey =
                    typeof privateKey1 === "string" ? convertPEMtoDER(privateKey1) : privateKey1.export({ format: "der", type: "pkcs1" });
            
            
            Severity: Major
            Found in packages/node-opcua-crypto/source/explore_private_key.ts - About 2 hrs to fix

              File asn1.ts has 278 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import assert from "assert";
              import { oid_map } from "./oid_map.js";
              import { DirectoryName } from "./directory_name.js";
              // https://github.com/lapo-luchini/asn1js/blob/master/asn1.js
              export enum TagType {
              Severity: Minor
              Found in packages/node-opcua-crypto/source/asn1.ts - About 2 hrs to fix

                Function readTbsCertificate has 57 lines of code (exceeds 25 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: Major
                Found in packages/node-opcua-crypto/source/crypto_explore_certificate.ts - About 2 hrs to fix

                  Function parseOID has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function parseOID(buffer: Buffer, start: number, end: number): string {
                      // ASN.1 JavaScript decoder
                      // Copyright (c) 2008-2014 Lapo Luchini <lapo@lapo.it>
                      let s = "",
                          n = 0,
                  Severity: Minor
                  Found in packages/node-opcua-crypto/source/asn1.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 _readGeneralNames has 47 lines of code (exceeds 25 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

                    Function verifyCertificateChain has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export async function verifyCertificateChain(certificateChain: Certificate[]): Promise<{ status: _VerifyStatus; reason: string }> {
                        // verify that all the certificate
                        // second certificate must be used for CertificateSign
                    
                        for (let index = 1; index < certificateChain.length; index++) {
                    Severity: Minor
                    Found in packages/node-opcua-crypto/source/verify_certificate_signature.ts - About 1 hr to fix

                      Function _readTbsCertList has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function _readTbsCertList(buffer: Buffer, blockInfo: BlockInfo): TBSCertList {
                          const blocks = readStruct(buffer, blockInfo);
                      
                          const hasOptionalVersion = blocks[0].tag === TagType.INTEGER;
                      
                      

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

                        function _readTbsCertList(buffer: Buffer, blockInfo: BlockInfo): TBSCertList {
                            const blocks = readStruct(buffer, blockInfo);
                        
                            const hasOptionalVersion = blocks[0].tag === TagType.INTEGER;
                        
                        

                        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 _readAuthorityKeyIdentifier has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function _readAuthorityKeyIdentifier(buffer: Buffer): AuthorityKeyIdentifier {
                            /**
                             *  where a CA distributes its public key in the form of a "self-signed"
                             *  certificate, the authority key identifier MAY be omitted.  Th
                             *  signature on a self-signed certificate is generated with the private
                        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 _readAuthorityKeyIdentifier has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        function _readAuthorityKeyIdentifier(buffer: Buffer): AuthorityKeyIdentifier {
                            /**
                             *  where a CA distributes its public key in the form of a "self-signed"
                             *  certificate, the authority key identifier MAY be omitted.  Th
                             *  signature on a self-signed certificate is generated with the private
                        Severity: Minor
                        Found in packages/node-opcua-crypto/source/crypto_explore_certificate.ts - About 1 hr to fix

                          Function readExtension has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          export function readExtension(buffer: Buffer, block: BlockInfo): { identifier: { oid: string; name: string }; value: any } {
                              const inner_blocks = readStruct(buffer, block);
                          
                              if (inner_blocks.length === 3) {
                                  assert(inner_blocks[1].tag === TagType.BOOLEAN);
                          Severity: Minor
                          Found in packages/node-opcua-crypto/source/crypto_explore_certificate.ts - About 1 hr to fix

                            Function verifyCertificateChain has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                            Open

                            export async function verifyCertificateChain(certificateChain: Certificate[]): Promise<{ status: _VerifyStatus; reason: string }> {
                                // verify that all the certificate
                                // second certificate must be used for CertificateSign
                            
                                for (let index = 1; index < certificateChain.length; index++) {
                            Severity: Minor
                            Found in packages/node-opcua-crypto/source/verify_certificate_signature.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 generate has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            async function generate(event: any) {
                                event.preventDefault();
                                const keySize = document.getElementById("keySize").value;
                                const applicationUri = document.getElementById("applicationUri").value;
                                const subject = document.getElementById("subject").value;
                            Severity: Minor
                            Found in packages/node-opcua-crypto-web/web/main.ts - About 1 hr to fix

                              Function investigateCertificateSignature has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              export function investigateCertificateSignature(certificate: Certificate, caPrivateKey?: PrivateKey): void {
                                  const block_info = asn1.readTag(certificate, 0);
                                  const blocks = asn1.readStruct(certificate, block_info);
                              
                                  //  console.log(block_info, blocks[0], blocks[1], blocks[2]);

                                Function publicEncrypt_long has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                Open

                                export function publicEncrypt_long(
                                    buffer: Buffer,
                                    publicKey: KeyLike,
                                    blockSize: number,
                                    padding?: number,
                                Severity: Minor
                                Found in packages/node-opcua-crypto/source/crypto_utils.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

                                Severity
                                Category
                                Status
                                Source
                                Language