{"ast":null,"code":"const ASYMMETRIC_KEY_DETAILS_SUPPORTED = require('./asymmetricKeyDetailsSupported');\nconst RSA_PSS_KEY_DETAILS_SUPPORTED = require('./rsaPssKeyDetailsSupported');\nconst allowedAlgorithmsForKeys = {\n  'ec': ['ES256', 'ES384', 'ES512'],\n  'rsa': ['RS256', 'PS256', 'RS384', 'PS384', 'RS512', 'PS512'],\n  'rsa-pss': ['PS256', 'PS384', 'PS512']\n};\nconst allowedCurves = {\n  ES256: 'prime256v1',\n  ES384: 'secp384r1',\n  ES512: 'secp521r1'\n};\nmodule.exports = function (algorithm, key) {\n  if (!algorithm || !key) return;\n  const keyType = key.asymmetricKeyType;\n  if (!keyType) return;\n  const allowedAlgorithms = allowedAlgorithmsForKeys[keyType];\n  if (!allowedAlgorithms) {\n    throw new Error(`Unknown key type \"${keyType}\".`);\n  }\n  if (!allowedAlgorithms.includes(algorithm)) {\n    throw new Error(`\"alg\" parameter for \"${keyType}\" key type must be one of: ${allowedAlgorithms.join(', ')}.`);\n  }\n\n  /*\n   * Ignore the next block from test coverage because it gets executed\n   * conditionally depending on the Node version. Not ignoring it would\n   * prevent us from reaching the target % of coverage for versions of\n   * Node under 15.7.0.\n   */\n  /* istanbul ignore next */\n  if (ASYMMETRIC_KEY_DETAILS_SUPPORTED) {\n    switch (keyType) {\n      case 'ec':\n        const keyCurve = key.asymmetricKeyDetails.namedCurve;\n        const allowedCurve = allowedCurves[algorithm];\n        if (keyCurve !== allowedCurve) {\n          throw new Error(`\"alg\" parameter \"${algorithm}\" requires curve \"${allowedCurve}\".`);\n        }\n        break;\n      case 'rsa-pss':\n        if (RSA_PSS_KEY_DETAILS_SUPPORTED) {\n          const length = parseInt(algorithm.slice(-3), 10);\n          const {\n            hashAlgorithm,\n            mgf1HashAlgorithm,\n            saltLength\n          } = key.asymmetricKeyDetails;\n          if (hashAlgorithm !== `sha${length}` || mgf1HashAlgorithm !== hashAlgorithm) {\n            throw new Error(`Invalid key for this operation, its RSA-PSS parameters do not meet the requirements of \"alg\" ${algorithm}.`);\n          }\n          if (saltLength !== undefined && saltLength > length >> 3) {\n            throw new Error(`Invalid key for this operation, its RSA-PSS parameter saltLength does not meet the requirements of \"alg\" ${algorithm}.`);\n          }\n        }\n        break;\n    }\n  }\n};","map":{"version":3,"names":["ASYMMETRIC_KEY_DETAILS_SUPPORTED","require","RSA_PSS_KEY_DETAILS_SUPPORTED","allowedAlgorithmsForKeys","allowedCurves","ES256","ES384","ES512","module","exports","algorithm","key","keyType","asymmetricKeyType","allowedAlgorithms","Error","includes","join","keyCurve","asymmetricKeyDetails","namedCurve","allowedCurve","length","parseInt","slice","hashAlgorithm","mgf1HashAlgorithm","saltLength","undefined"],"sources":["C:/Users/user/Desktop/05mediaSocial/node_modules/jsonwebtoken/lib/validateAsymmetricKey.js"],"sourcesContent":["const ASYMMETRIC_KEY_DETAILS_SUPPORTED = require('./asymmetricKeyDetailsSupported');\nconst RSA_PSS_KEY_DETAILS_SUPPORTED = require('./rsaPssKeyDetailsSupported');\n\nconst allowedAlgorithmsForKeys = {\n  'ec': ['ES256', 'ES384', 'ES512'],\n  'rsa': ['RS256', 'PS256', 'RS384', 'PS384', 'RS512', 'PS512'],\n  'rsa-pss': ['PS256', 'PS384', 'PS512']\n};\n\nconst allowedCurves = {\n  ES256: 'prime256v1',\n  ES384: 'secp384r1',\n  ES512: 'secp521r1',\n};\n\nmodule.exports = function(algorithm, key) {\n  if (!algorithm || !key) return;\n\n  const keyType = key.asymmetricKeyType;\n  if (!keyType) return;\n\n  const allowedAlgorithms = allowedAlgorithmsForKeys[keyType];\n\n  if (!allowedAlgorithms) {\n    throw new Error(`Unknown key type \"${keyType}\".`);\n  }\n\n  if (!allowedAlgorithms.includes(algorithm)) {\n    throw new Error(`\"alg\" parameter for \"${keyType}\" key type must be one of: ${allowedAlgorithms.join(', ')}.`)\n  }\n\n  /*\n   * Ignore the next block from test coverage because it gets executed\n   * conditionally depending on the Node version. Not ignoring it would\n   * prevent us from reaching the target % of coverage for versions of\n   * Node under 15.7.0.\n   */\n  /* istanbul ignore next */\n  if (ASYMMETRIC_KEY_DETAILS_SUPPORTED) {\n    switch (keyType) {\n    case 'ec':\n      const keyCurve = key.asymmetricKeyDetails.namedCurve;\n      const allowedCurve = allowedCurves[algorithm];\n\n      if (keyCurve !== allowedCurve) {\n        throw new Error(`\"alg\" parameter \"${algorithm}\" requires curve \"${allowedCurve}\".`);\n      }\n      break;\n\n    case 'rsa-pss':\n      if (RSA_PSS_KEY_DETAILS_SUPPORTED) {\n        const length = parseInt(algorithm.slice(-3), 10);\n        const { hashAlgorithm, mgf1HashAlgorithm, saltLength } = key.asymmetricKeyDetails;\n\n        if (hashAlgorithm !== `sha${length}` || mgf1HashAlgorithm !== hashAlgorithm) {\n          throw new Error(`Invalid key for this operation, its RSA-PSS parameters do not meet the requirements of \"alg\" ${algorithm}.`);\n        }\n\n        if (saltLength !== undefined && saltLength > length >> 3) {\n          throw new Error(`Invalid key for this operation, its RSA-PSS parameter saltLength does not meet the requirements of \"alg\" ${algorithm}.`)\n        }\n      }\n      break;\n    }\n  }\n}\n"],"mappings":"AAAA,MAAMA,gCAAgC,GAAGC,OAAO,CAAC,iCAAiC,CAAC;AACnF,MAAMC,6BAA6B,GAAGD,OAAO,CAAC,6BAA6B,CAAC;AAE5E,MAAME,wBAAwB,GAAG;EAC/B,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;EACjC,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;EAC7D,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO;AACvC,CAAC;AAED,MAAMC,aAAa,GAAG;EACpBC,KAAK,EAAE,YAAY;EACnBC,KAAK,EAAE,WAAW;EAClBC,KAAK,EAAE;AACT,CAAC;AAEDC,MAAM,CAACC,OAAO,GAAG,UAASC,SAAS,EAAEC,GAAG,EAAE;EACxC,IAA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