Files
stats/patches/buffer-equal-constant-time@1.0.1.patch

43 lines
1.3 KiB
Diff

diff --git a/.npmignore b/.npmignore
deleted file mode 100644
index 34e4f5c298de294fa5c1c1769b6489eb047bde9a..0000000000000000000000000000000000000000
diff --git a/index.js b/index.js
index 5462c1f830bdbe79bf2b1fcfd811cd9799b4dd11..689421d49e83d168981a0c7d1fef59a0b0e56963 100644
--- a/index.js
+++ b/index.js
@@ -3,6 +3,9 @@
var Buffer = require('buffer').Buffer; // browserify
var SlowBuffer = require('buffer').SlowBuffer;
+// Handle Node.js v25+ where SlowBuffer was removed
+var hasSlowBuffer = !!SlowBuffer;
+
module.exports = bufferEq;
function bufferEq(a, b) {
@@ -28,14 +31,18 @@ function bufferEq(a, b) {
}
bufferEq.install = function() {
- Buffer.prototype.equal = SlowBuffer.prototype.equal = function equal(that) {
- return bufferEq(this, that);
- };
+ Buffer.prototype.equal = function equal(that) {
+ return bufferEq(this, that);
+ };
+ if (hasSlowBuffer) {
+ SlowBuffer.prototype.equal = Buffer.prototype.equal;
+ }
};
var origBufEqual = Buffer.prototype.equal;
-var origSlowBufEqual = SlowBuffer.prototype.equal;
bufferEq.restore = function() {
- Buffer.prototype.equal = origBufEqual;
- SlowBuffer.prototype.equal = origSlowBufEqual;
+ Buffer.prototype.equal = origBufEqual;
+ if (hasSlowBuffer && SlowBuffer.prototype) {
+ delete SlowBuffer.prototype.equal;
+ }
};