| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,6 +44,8 @@ const { | |||
| 44 | 44 | isSymbolObject, | |
| 45 | 45 | isFloat32Array, | |
| 46 | 46 | isFloat64Array, | |
| 47 | + isKeyObject, | ||
| 48 | + isCryptoKey, | ||
| 47 | 49 | } = types; | |
| 48 | 50 | const { | |
| 49 | 51 | constants: { | |
@@ -61,6 +63,8 @@ const kIsArray = 1; | |||
| 61 | 63 | const kIsSet = 2; | |
| 62 | 64 | const kIsMap = 3; | |
| 63 | 65 | ||
| 66 | + let kKeyObject; | ||
| 67 | + | ||
| 64 | 68 | // Check if they have the same source and flags | |
| 65 | 69 | function areSimilarRegExps(a, b) { | |
| 66 | 70 | return a.source === b.source && | |
@@ -251,6 +255,20 @@ function innerDeepEqual(val1, val2, strict, memos) { | |||
| 251 | 255 | isNativeError(val2) || | |
| 252 | 256 | val2 instanceof Error) { | |
| 253 | 257 | return false; | |
| 258 | + } else if (isKeyObject(val1)) { | ||
| 259 | + if (!isKeyObject(val2) || !val1.equals(val2)) { | ||
| 260 | + return false; | ||
| 261 | + } | ||
| 262 | + } else if (isCryptoKey(val1)) { | ||
| 263 | + kKeyObject ??= require('internal/crypto/util').kKeyObject; | ||
| 264 | + if (!isCryptoKey(val2) || | ||
| 265 | + val1.extractable !== val2.extractable || | ||
| 266 | + !innerDeepEqual(val1.algorithm, val2.algorithm, strict, memos) || | ||
| 267 | + !innerDeepEqual(val1.usages, val2.usages, strict, memos) || | ||
| 268 | + !innerDeepEqual(val1[kKeyObject], val2[kKeyObject], strict, memos) | ||
| 269 | + ) { | ||
| 270 | + return false; | ||
| 271 | + } | ||
| 254 | 272 | } | |
| 255 | 273 | return keyCheck(val1, val2, strict, memos, kNoIterator); | |
| 256 | 274 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - require('../common'); | ||
| 3 | + const common = require('../common'); | ||
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | const util = require('util'); | |
| 6 | 6 | const { AssertionError } = assert; | |
@@ -1220,3 +1220,60 @@ assert.throws( | |||
| 1220 | 1220 | ||
| 1221 | 1221 | assertNotDeepOrStrict(a, b); | |
| 1222 | 1222 | } | |
| 1223 | + | ||
| 1224 | + // eslint-disable-next-line node-core/crypto-check | ||
| 1225 | + if (common.hasCrypto) { | ||
| 1226 | + const crypto = require('crypto'); | ||
| 1227 | + const { subtle } = globalThis.crypto; | ||
| 1228 | + | ||
| 1229 | + { | ||
| 1230 | + const a = crypto.createSecretKey(Buffer.alloc(1, 0)); | ||
| 1231 | + const b = crypto.createSecretKey(Buffer.alloc(1, 1)); | ||
| 1232 | + | ||
| 1233 | + assertNotDeepOrStrict(a, b); | ||
| 1234 | + } | ||
| 1235 | + | ||
| 1236 | + { | ||
| 1237 | + const a = crypto.createSecretKey(Buffer.alloc(0)); | ||
| 1238 | + const b = crypto.createSecretKey(Buffer.alloc(0)); | ||
| 1239 | + | ||
| 1240 | + assertDeepAndStrictEqual(a, b); | ||
| 1241 | + } | ||
| 1242 | + | ||
| 1243 | + (async () => { | ||
| 1244 | + { | ||
| 1245 | + const a = await subtle.importKey('raw', Buffer.alloc(1, 0), { name: 'HMAC', hash: 'SHA-256' }, true, ['sign']); | ||
| 1246 | + const b = await subtle.importKey('raw', Buffer.alloc(1, 1), { name: 'HMAC', hash: 'SHA-256' }, true, ['sign']); | ||
| 1247 | + | ||
| 1248 | + assertNotDeepOrStrict(a, b); | ||
| 1249 | + } | ||
| 1250 | + | ||
| 1251 | + { | ||
| 1252 | + const a = await subtle.importKey('raw', Buffer.alloc(1), { name: 'HMAC', hash: 'SHA-256' }, true, ['sign']); | ||
| 1253 | + const b = await subtle.importKey('raw', Buffer.alloc(1), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']); | ||
| 1254 | + | ||
| 1255 | + assertNotDeepOrStrict(a, b); | ||
| 1256 | + } | ||
| 1257 | + | ||
| 1258 | + { | ||
| 1259 | + const a = await subtle.importKey('raw', Buffer.alloc(1), { name: 'HMAC', hash: 'SHA-256' }, true, ['sign']); | ||
| 1260 | + const b = await subtle.importKey('raw', Buffer.alloc(1), { name: 'HMAC', hash: 'SHA-384' }, true, ['sign']); | ||
| 1261 | + | ||
| 1262 | + assertNotDeepOrStrict(a, b); | ||
| 1263 | + } | ||
| 1264 | + | ||
| 1265 | + { | ||
| 1266 | + const a = await subtle.importKey('raw', Buffer.alloc(1), { name: 'HMAC', hash: 'SHA-256' }, true, ['sign']); | ||
| 1267 | + const b = await subtle.importKey('raw', Buffer.alloc(1), { name: 'HMAC', hash: 'SHA-256' }, true, ['verify']); | ||
| 1268 | + | ||
| 1269 | + assertNotDeepOrStrict(a, b); | ||
| 1270 | + } | ||
| 1271 | + | ||
| 1272 | + { | ||
| 1273 | + const a = await subtle.importKey('raw', Buffer.alloc(1), { name: 'HMAC', hash: 'SHA-256' }, true, ['sign']); | ||
| 1274 | + const b = await subtle.importKey('raw', Buffer.alloc(1), { name: 'HMAC', hash: 'SHA-256' }, true, ['sign']); | ||
| 1275 | + | ||
| 1276 | + assertDeepAndStrictEqual(a, b); | ||
| 1277 | + } | ||
| 1278 | + })().then(common.mustCall()); | ||
| 1279 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments