How to use the webcrypto-core.AlgorithmError function in webcrypto-core

To help you get started, we’ve selected a few webcrypto-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PeculiarVentures / webcrypto-liner / src / rsa / crypto.ts View on Github external
public static alg2jwk(alg: Algorithm) {
        const hash = (alg as any).hash as Algorithm;
        const hashSize = /(\d+)/.exec(hash.name)![1];
        switch (alg.name!.toUpperCase()) {
            case AlgorithmNames.RsaOAEP.toUpperCase():
                return `RSA-OAEP${hashSize === "1" ? "" : `-${hashSize}`}`;
            case AlgorithmNames.RsaPSS.toUpperCase():
                return `PS${hashSize}`;
            case AlgorithmNames.RsaSSA.toUpperCase():
                return `RS${hashSize}`;
            default:
                throw new AlgorithmError(AlgorithmError.UNSUPPORTED_ALGORITHM, alg.name);
        }
    }
github PeculiarVentures / webcrypto-liner / src / mechs / sha / crypto.ts View on Github external
public static getDigest(name: string) {
    switch (name) {
      case "SHA-1":
        return new asmCrypto.Sha1();
      case "SHA-256":
        return new asmCrypto.Sha256();
      case "SHA-512":
        return new asmCrypto.Sha512();
      default:
        throw new core.AlgorithmError("keyAlgorithm.hash: Is not recognized");
    }
  }
github PeculiarVentures / node-webcrypto-ossl / lib / crypto / pbkdf2.ts View on Github external
.then((raw) => {
                let CryptoClass: typeof Core.BaseCrypto;
                switch (derivedKeyType.name.toUpperCase()) {
                    case Core.AlgorithmNames.AesCBC:
                    case Core.AlgorithmNames.AesGCM:
                    case Core.AlgorithmNames.AesKW:
                        CryptoClass = AesCrypto;
                        break;
                    case Core.AlgorithmNames.Hmac:
                        CryptoClass = HmacCrypto;
                        break;
                    default:
                        throw new Core.AlgorithmError(Core.AlgorithmError.UNSUPPORTED_ALGORITHM, algorithm.name);
                }
                return CryptoClass.importKey("raw", Buffer.from(raw), derivedKeyType as any, extractable, keyUsages);
            });
    }
github PeculiarVentures / webcrypto / src / mechs / aes / key.ts View on Github external
public get alg() {
    switch (this.algorithm.name.toUpperCase()) {
      case "AES-CBC":
        return `A${this.algorithm.length}CBC`;
      case "AES-CTR":
        return `A${this.algorithm.length}CTR`;
      case "AES-GCM":
        return `A${this.algorithm.length}GCM`;
      case "AES-KW":
        return `A${this.algorithm.length}KW`;
      case "AES-CMAC":
        return `A${this.algorithm.length}CMAC`;
      case "AES-ECB":
        return `A${this.algorithm.length}ECB`;
      default:
        throw new core.AlgorithmError("Unsupported algorithm name");
    }
  }