TritonDataCenter / node-http-signature

Reference implementation of Joyent's HTTP Signature Scheme
https://tritondatacenter.com
MIT License
405 stars 118 forks source link

Avoid using deprecated Buffer API on newer Node.js #67

Open ChALkeR opened 6 years ago

ChALkeR commented 6 years ago

This avoids using Buffer constructor API on newer Node.js versions.

To achieve that, Buffer.from presence is checked, with validation that it's not the same method as Uint8Array.from.

Also an additional type-guard is added in the fallback code path to ensure that typed numbers are never accidently fed into new Buffer input.

Given this module popularity and the fact that old Buffer constructor API was used in a single place, I decided to just feature-detect it in-place instead of pulling in polyfill deps. Another way would be to just use Buffer.from and do var Buffer = require('safe-buffer');

Refs: https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor Tracking: https://github.com/nodejs/node/issues/19079

ChALkeR commented 6 years ago

Ping?