This commit is contained in:
20
node_modules/bufferutil/LICENSE
generated
vendored
Normal file
20
node_modules/bufferutil/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
Copyright (c) 2011 Einar Otto Stangvik <einaros@gmail.com>
|
||||
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.
|
78
node_modules/bufferutil/README.md
generated
vendored
Normal file
78
node_modules/bufferutil/README.md
generated
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
# 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)
|
29
node_modules/bufferutil/binding.gyp
generated
vendored
Normal file
29
node_modules/bufferutil/binding.gyp
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'bufferutil',
|
||||
'sources': ['src/bufferutil.c'],
|
||||
'cflags': ['-std=c99'],
|
||||
'conditions': [
|
||||
["OS=='mac'", {
|
||||
'variables': {
|
||||
'clang_version':
|
||||
'<!(cc -v 2>&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 <!(perl -e \'print <(clang_version) cmp 12.0.0\')==1', {
|
||||
'xcode_settings': {
|
||||
'OTHER_CFLAGS': ['-arch arm64'],
|
||||
'OTHER_LDFLAGS': ['-arch arm64']
|
||||
}
|
||||
}]
|
||||
]
|
||||
}]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
34
node_modules/bufferutil/fallback.js
generated
vendored
Normal file
34
node_modules/bufferutil/fallback.js
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Masks a buffer using the given mask.
|
||||
*
|
||||
* @param {Buffer} source The buffer to mask
|
||||
* @param {Buffer} mask The mask to use
|
||||
* @param {Buffer} output The buffer where to store the result
|
||||
* @param {Number} offset The offset at which to start writing
|
||||
* @param {Number} length The number of bytes to mask.
|
||||
* @public
|
||||
*/
|
||||
const mask = (source, mask, output, offset, length) => {
|
||||
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 };
|
7
node_modules/bufferutil/index.js
generated
vendored
Normal file
7
node_modules/bufferutil/index.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
try {
|
||||
module.exports = require('node-gyp-build')(__dirname);
|
||||
} catch (e) {
|
||||
module.exports = require('./fallback');
|
||||
}
|
36
node_modules/bufferutil/package.json
generated
vendored
Normal file
36
node_modules/bufferutil/package.json
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"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 <einaros@gmail.com> (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"
|
||||
}
|
||||
}
|
BIN
node_modules/bufferutil/prebuilds/darwin-x64+arm64/node.napi.node
generated
vendored
Normal file
BIN
node_modules/bufferutil/prebuilds/darwin-x64+arm64/node.napi.node
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/bufferutil/prebuilds/linux-x64/node.napi.node
generated
vendored
Normal file
BIN
node_modules/bufferutil/prebuilds/linux-x64/node.napi.node
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/bufferutil/prebuilds/win32-ia32/node.napi.node
generated
vendored
Normal file
BIN
node_modules/bufferutil/prebuilds/win32-ia32/node.napi.node
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/bufferutil/prebuilds/win32-x64/node.napi.node
generated
vendored
Normal file
BIN
node_modules/bufferutil/prebuilds/win32-x64/node.napi.node
generated
vendored
Normal file
Binary file not shown.
171
node_modules/bufferutil/src/bufferutil.c
generated
vendored
Normal file
171
node_modules/bufferutil/src/bufferutil.c
generated
vendored
Normal file
@ -0,0 +1,171 @@
|
||||
#define NAPI_VERSION 1
|
||||
#include <assert.h>
|
||||
#include <node_api.h>
|
||||
|
||||
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)
|
Reference in New Issue
Block a user