MCPcopy Index your code
hub / github.com/nodejs/node / check

Function check

lib/internal/crypto/webcrypto.js:1770–1870  ·  view source on GitHub ↗
(op, alg, length)

Source from the content-addressed store, hash-verified

1768}
1769
1770function check(op, alg, length) {
1771 if (op === 'encapsulateBits' || op === 'encapsulateKey') {
1772 op = 'encapsulate';
1773 }
1774
1775 if (op === 'decapsulateBits' || op === 'decapsulateKey') {
1776 op = 'decapsulate';
1777 }
1778
1779 let normalizedAlgorithm;
1780 try {
1781 normalizedAlgorithm = normalizeAlgorithm(alg, op);
1782 } catch {
1783 if (op === 'wrapKey') {
1784 return check('encrypt', alg);
1785 }
1786
1787 if (op === 'unwrapKey') {
1788 return check('decrypt', alg);
1789 }
1790
1791 return false;
1792 }
1793
1794 switch (op) {
1795 case 'decapsulate':
1796 case 'decrypt':
1797 case 'digest': {
1798 if ((normalizedAlgorithm.name === 'cSHAKE128' ||
1799 normalizedAlgorithm.name === 'cSHAKE256') &&
1800 (normalizedAlgorithm.functionName?.byteLength ||
1801 normalizedAlgorithm.customization?.byteLength)) {
1802 return CShakeJob !== undefined;
1803 }
1804 return true;
1805 }
1806 case 'encapsulate':
1807 case 'encrypt':
1808 case 'exportKey':
1809 case 'importKey':
1810 case 'sign':
1811 case 'unwrapKey':
1812 case 'verify':
1813 case 'wrapKey':
1814 return true;
1815 case 'deriveBits': {
1816 if (normalizedAlgorithm.name === 'HKDF') {
1817 require('internal/crypto/hkdf').validateHkdfDeriveBitsLength(length);
1818 }
1819
1820 if (normalizedAlgorithm.name === 'PBKDF2') {
1821 require('internal/crypto/pbkdf2').validatePbkdf2DeriveBitsLength(length);
1822 }
1823
1824 if (StringPrototypeStartsWith(normalizedAlgorithm.name, 'Argon2')) {
1825 require('internal/crypto/argon2').validateArgon2DeriveBitsLength(length);
1826 }
1827

Callers 1

supportsMethod · 0.70

Calls 4

getCryptoKeyAlgorithmFunction · 0.85
normalizeAlgorithmFunction · 0.70
requireFunction · 0.50
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…