pax_global_header00006660000000000000000000000064145130035130014505gustar00rootroot0000000000000052 comment=9047e45073bf93e495ed100361d270d4062867d8
bufferutil-4.0.8/000077500000000000000000000000001451300351300136655ustar00rootroot00000000000000bufferutil-4.0.8/.github/000077500000000000000000000000001451300351300152255ustar00rootroot00000000000000bufferutil-4.0.8/.github/workflows/000077500000000000000000000000001451300351300172625ustar00rootroot00000000000000bufferutil-4.0.8/.github/workflows/ci.yml000066400000000000000000000052271451300351300204060ustar00rootroot00000000000000name: CI
on:
- push
- pull_request
permissions: {}
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
arch:
- x64
- x86
node:
- 14
- 16
- 18
- 20
os:
- macos-latest
- ubuntu-latest
- windows-latest
exclude:
- arch: x86
os: macos-latest
- arch: x86
os: ubuntu-latest
- arch: x86
node: 18
os: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
architecture: ${{ matrix.arch }}
- run: npm install
- run: npm test
build:
if: startsWith(github.ref, 'refs/tags/')
needs: test
runs-on: ${{ matrix.os }}
strategy:
matrix:
arch:
- x64
- x86
os:
- macos-latest
- ubuntu-20.04
- windows-latest
exclude:
- arch: x86
os: macos-latest
- arch: x86
os: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 14
architecture: ${{ matrix.arch }}
- run: npm install
- run: npm run prebuild
if: matrix.os != 'macos-latest'
- run: npm run prebuild-darwin-x64+arm64
if: matrix.os == 'macos-latest'
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}
path: prebuilds
retention-days: 1
release:
needs: build
permissions:
contents: write # Needed for softprops/action-gh-release.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
path: prebuilds
- run: echo "version=$(git describe --tags)" >> $GITHUB_OUTPUT
id: get_version
- run:
tar -cvf "${{ steps.get_version.outputs.version
}}-darwin-x64+arm64.tar" -C "prebuilds/macos-latest" .
- run:
tar -cvf "${{ steps.get_version.outputs.version }}-linux-x64.tar" -C
"prebuilds/ubuntu-20.04" linux-x64
- run:
tar -cvf "${{ steps.get_version.outputs.version }}-win32-ia32.tar" -C
"prebuilds/windows-latest" win32-ia32
- run:
tar -cvf "${{ steps.get_version.outputs.version }}-win32-x64.tar" -C
"prebuilds/windows-latest" win32-x64
- uses: softprops/action-gh-release@v1
with:
files: ${{ steps.get_version.outputs.version }}-*.tar
token: ${{ secrets.GITHUB_TOKEN }}
bufferutil-4.0.8/.gitignore000066400000000000000000000000561451300351300156560ustar00rootroot00000000000000node_modules/
prebuilds/
build/
npm-debug.log
bufferutil-4.0.8/.npmignore000066400000000000000000000000201451300351300156540ustar00rootroot00000000000000build/
test/
.*
bufferutil-4.0.8/.npmrc000066400000000000000000000000231451300351300150000ustar00rootroot00000000000000package-lock=false
bufferutil-4.0.8/LICENSE000066400000000000000000000022371451300351300146760ustar00rootroot00000000000000Copyright (c) 2011 Einar Otto Stangvik
Copyright (c) 2013 Arnout Kazemier and contributors
Copyright (c) 2016 Luigi Pinca and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
bufferutil-4.0.8/README.md000066400000000000000000000036361451300351300151540ustar00rootroot00000000000000# bufferutil
[](https://www.npmjs.com/package/bufferutil)
[](https://github.com/websockets/bufferutil/actions?query=workflow%3ACI+branch%3Amaster)
`bufferutil` is what makes `ws` fast. It provides some utilities to efficiently
perform some operations such as masking and unmasking the data payload of
WebSocket frames.
## Installation
```
npm install bufferutil --save-optional
```
The `--save-optional` flag tells npm to save the package in your package.json
under the
[`optionalDependencies`](https://docs.npmjs.com/files/package.json#optionaldependencies)
key.
## API
The module exports two functions.
### `bufferUtil.mask(source, mask, output, offset, length)`
Masks a buffer using the given masking-key as specified by the WebSocket
protocol.
#### Arguments
- `source` - The buffer to mask.
- `mask` - A buffer representing the masking-key.
- `output` - The buffer where to store the result.
- `offset` - The offset at which to start writing.
- `length` - The number of bytes to mask.
#### Example
```js
'use strict';
const bufferUtil = require('bufferutil');
const crypto = require('crypto');
const source = crypto.randomBytes(10);
const mask = crypto.randomBytes(4);
bufferUtil.mask(source, mask, source, 0, source.length);
```
### `bufferUtil.unmask(buffer, mask)`
Unmasks a buffer using the given masking-key as specified by the WebSocket
protocol.
#### Arguments
- `buffer` - The buffer to unmask.
- `mask` - A buffer representing the masking-key.
#### Example
```js
'use strict';
const bufferUtil = require('bufferutil');
const crypto = require('crypto');
const buffer = crypto.randomBytes(10);
const mask = crypto.randomBytes(4);
bufferUtil.unmask(buffer, mask);
```
## License
[MIT](LICENSE)
bufferutil-4.0.8/binding.gyp000066400000000000000000000014421451300351300160210ustar00rootroot00000000000000{
'targets': [
{
'target_name': 'bufferutil',
'sources': ['src/bufferutil.c'],
'cflags': ['-std=c99'],
'conditions': [
["OS=='mac'", {
'variables': {
'clang_version':
'&1 | perl -ne \'print $1 if /clang version ([0-9]+(\.[0-9]+){2,})/\')'
},
'xcode_settings': {
'MACOSX_DEPLOYMENT_TARGET': '10.7'
},
'conditions': [
# Use Perl v-strings to compare versions.
['clang_version and {
for (var i = 0; i < length; i++) {
output[offset + i] = source[i] ^ mask[i & 3];
}
};
/**
* Unmasks a buffer using the given mask.
*
* @param {Buffer} buffer The buffer to unmask
* @param {Buffer} mask The mask to use
* @public
*/
const unmask = (buffer, mask) => {
// Required until https://github.com/nodejs/node/issues/9006 is resolved.
const length = buffer.length;
for (var i = 0; i < length; i++) {
buffer[i] ^= mask[i & 3];
}
};
module.exports = { mask, unmask };
bufferutil-4.0.8/index.js000066400000000000000000000002101451300351300153230ustar00rootroot00000000000000'use strict';
try {
module.exports = require('node-gyp-build')(__dirname);
} catch (e) {
module.exports = require('./fallback');
}
bufferutil-4.0.8/package.json000066400000000000000000000016161451300351300161570ustar00rootroot00000000000000{
"name": "bufferutil",
"version": "4.0.8",
"description": "WebSocket buffer utils",
"main": "index.js",
"engines": {
"node": ">=6.14.2"
},
"scripts": {
"install": "node-gyp-build",
"prebuild": "prebuildify --napi --strip --target=14.0.0",
"prebuild-darwin-x64+arm64": "prebuildify --arch x64+arm64 --napi --strip --target=14.0.0",
"test": "mocha"
},
"repository": {
"type": "git",
"url": "https://github.com/websockets/bufferutil"
},
"keywords": [
"bufferutil"
],
"author": "Einar Otto Stangvik (http://2x.io)",
"license": "MIT",
"bugs": {
"url": "https://github.com/websockets/bufferutil/issues"
},
"homepage": "https://github.com/websockets/bufferutil",
"dependencies": {
"node-gyp-build": "^4.3.0"
},
"devDependencies": {
"mocha": "^10.0.0",
"node-gyp": "^9.1.0",
"prebuildify": "^5.0.0"
}
}
bufferutil-4.0.8/src/000077500000000000000000000000001451300351300144545ustar00rootroot00000000000000bufferutil-4.0.8/src/bufferutil.c000066400000000000000000000071421451300351300167730ustar00rootroot00000000000000#define NAPI_VERSION 1
#include
#include
napi_value Mask(napi_env env, napi_callback_info info) {
napi_status status;
size_t argc = 5;
napi_value argv[5];
status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
assert(status == napi_ok);
uint8_t *source;
uint8_t *mask;
uint8_t *destination;
uint32_t offset;
uint32_t length;
status = napi_get_buffer_info(env, argv[0], (void **)&source, NULL);
assert(status == napi_ok);
status = napi_get_buffer_info(env, argv[1], (void **)&mask, NULL);
assert(status == napi_ok);
status = napi_get_buffer_info(env, argv[2], (void **)&destination, NULL);
assert(status == napi_ok);
status = napi_get_value_uint32(env, argv[3], &offset);
assert(status == napi_ok);
status = napi_get_value_uint32(env, argv[4], &length);
assert(status == napi_ok);
destination += offset;
uint32_t index = 0;
//
// Alignment preamble.
//
while (index < length && ((size_t)source % 8)) {
*destination++ = *source++ ^ mask[index % 4];
index++;
}
length -= index;
if (!length)
return NULL;
//
// Realign mask and convert to 64 bit.
//
uint8_t maskAlignedArray[8];
for (uint8_t i = 0; i < 8; i++, index++) {
maskAlignedArray[i] = mask[index % 4];
}
//
// Apply 64 bit mask in 8 byte chunks.
//
uint32_t loop = length / 8;
uint64_t *pMask8 = (uint64_t *)maskAlignedArray;
while (loop--) {
uint64_t *pFrom8 = (uint64_t *)source;
uint64_t *pTo8 = (uint64_t *)destination;
*pTo8 = *pFrom8 ^ *pMask8;
source += 8;
destination += 8;
}
//
// Apply mask to remaining data.
//
uint8_t *pmaskAlignedArray = maskAlignedArray;
length %= 8;
while (length--) {
*destination++ = *source++ ^ *pmaskAlignedArray++;
}
return NULL;
}
napi_value Unmask(napi_env env, napi_callback_info info) {
napi_status status;
size_t argc = 2;
napi_value argv[2];
status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
assert(status == napi_ok);
uint8_t *source;
size_t length;
uint8_t *mask;
status = napi_get_buffer_info(env, argv[0], (void **)&source, &length);
assert(status == napi_ok);
status = napi_get_buffer_info(env, argv[1], (void **)&mask, NULL);
assert(status == napi_ok);
uint32_t index = 0;
//
// Alignment preamble.
//
while (index < length && ((size_t)source % 8)) {
*source++ ^= mask[index % 4];
index++;
}
length -= index;
if (!length)
return NULL;
//
// Realign mask and convert to 64 bit.
//
uint8_t maskAlignedArray[8];
for (uint8_t i = 0; i < 8; i++, index++) {
maskAlignedArray[i] = mask[index % 4];
}
//
// Apply 64 bit mask in 8 byte chunks.
//
uint32_t loop = length / 8;
uint64_t *pMask8 = (uint64_t *)maskAlignedArray;
while (loop--) {
uint64_t *pSource8 = (uint64_t *)source;
*pSource8 ^= *pMask8;
source += 8;
}
//
// Apply mask to remaining data.
//
uint8_t *pmaskAlignedArray = maskAlignedArray;
length %= 8;
while (length--) {
*source++ ^= *pmaskAlignedArray++;
}
return NULL;
}
napi_value Init(napi_env env, napi_value exports) {
napi_status status;
napi_value mask;
napi_value unmask;
status = napi_create_function(env, NULL, 0, Mask, NULL, &mask);
assert(status == napi_ok);
status = napi_create_function(env, NULL, 0, Unmask, NULL, &unmask);
assert(status == napi_ok);
status = napi_set_named_property(env, exports, "mask", mask);
assert(status == napi_ok);
status = napi_set_named_property(env, exports, "unmask", unmask);
assert(status == napi_ok);
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
bufferutil-4.0.8/test/000077500000000000000000000000001451300351300146445ustar00rootroot00000000000000bufferutil-4.0.8/test/test.js000066400000000000000000000026071451300351300161660ustar00rootroot00000000000000'use strict';
const { deepStrictEqual } = require('assert');
const { join } = require('path');
function use(bufferUtil) {
return function () {
it('masks a buffer (1/2)', function () {
const buf = Buffer.from([0x6c, 0x3c, 0x58, 0xd9, 0x3e, 0x21, 0x09, 0x9f]);
const mask = Buffer.from([0x48, 0x2a, 0xce, 0x24]);
bufferUtil.mask(buf, mask, buf, 0, buf.length);
deepStrictEqual(
buf,
Buffer.from([0x24, 0x16, 0x96, 0xfd, 0x76, 0x0b, 0xc7, 0xbb])
);
});
it('masks a buffer (2/2)', function () {
const src = Buffer.from([0x6c, 0x3c, 0x58, 0xd9, 0x3e, 0x21, 0x09, 0x9f]);
const mask = Buffer.from([0x48, 0x2a, 0xce, 0x24]);
const dest = Buffer.alloc(src.length + 2);
bufferUtil.mask(src, mask, dest, 2, src.length);
deepStrictEqual(
dest,
Buffer.from([0x00, 0x00, 0x24, 0x16, 0x96, 0xfd, 0x76, 0x0b, 0xc7, 0xbb])
);
});
it('unmasks a buffer', function () {
const buf = Buffer.from([0x24, 0x16, 0x96, 0xfd, 0x76, 0x0b, 0xc7, 0xbb]);
const mask = Buffer.from([0x48, 0x2a, 0xce, 0x24]);
bufferUtil.unmask(buf, mask);
deepStrictEqual(
buf,
Buffer.from([0x6c, 0x3c, 0x58, 0xd9, 0x3e, 0x21, 0x09, 0x9f])
);
});
};
}
describe('bindings', use(require('node-gyp-build')(join(__dirname, '..'))));
describe('fallback', use(require('../fallback')));