junkurihara/jscu

View on GitHub
packages/js-crypto-key-utils/src/util.ts

Summary

Maintainability
C
7 hrs
Test Coverage

Showing 5 of 5 total issues

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

    Function getJwkType has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    export const getJwkType = (jwkey: JsonWebKey): PublicOrPrivate => {
    if(jwkey.kty === 'EC'){
    if (jwkey.x && jwkey.y && jwkey.d) return 'private';
    else if (jwkey.x && jwkey.y) return 'public';
    else throw new Error('InvalidECKey');
    Severity: Minor
    Found in packages/js-crypto-key-utils/src/util.ts - About 55 mins to fix

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

    export const getSec1KeyType = (sec1key: OctetEC, namedCurve: CurveTypes): PublicOrPrivate => {
    const len = params.namedCurves[namedCurve].payloadSize;
     
    const binKey = (sec1key instanceof Uint8Array) ? sec1key : jseu.encoder.hexStringToArrayBuffer(sec1key);
     
     
    Severity: Minor
    Found in packages/js-crypto-key-utils/src/util.ts - About 35 mins to fix

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

    export const isAsn1Encrypted = (key: DER|PEM, format: AsnFormat = 'pem') => {
    let keyType;
    try{ keyType = getAsn1KeyType(key, format);} catch(e) {return false;}
    return keyType === 'encryptedPrivate';
    };
    Severity: Major
    Found in packages/js-crypto-key-utils/src/util.ts and 1 other location - About 2 hrs to fix
    packages/js-crypto-key-utils/src/util.ts on lines 28..32

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

    export const isAsn1Public = (key: DER|PEM, format: AsnFormat = 'pem') => {
    let keyType;
    try{ keyType = getAsn1KeyType(key, format);} catch(e) {return false;}
    return (keyType === 'public');
    };
    Severity: Major
    Found in packages/js-crypto-key-utils/src/util.ts and 1 other location - About 2 hrs to fix
    packages/js-crypto-key-utils/src/util.ts on lines 16..20

    There are no issues that match your filters.

    Category
    Status