🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

binarytf

Package Overview
Dependencies
Maintainers
1
Versions
225
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binarytf - npm Package Compare versions

Comparing version

to
0.2.0

29

dist/lib/Deserializer.js

@@ -44,4 +44,7 @@ "use strict";

case constants_1.BinaryTokens.Date: return this.createObjectID(new Date(this.readFloat64()));
// eslint-disable-next-line no-new-wrappers
case constants_1.BinaryTokens.BooleanObject: return this.createObjectID(new Boolean(this.readUint8()));
// eslint-disable-next-line no-new-wrappers
case constants_1.BinaryTokens.NumberObject: return this.createObjectID(new Number(this.readFloat64()));
// eslint-disable-next-line no-new-wrappers
case constants_1.BinaryTokens.StringObject: return this.createObjectID(new String(this.readString()));

@@ -72,4 +75,7 @@ case constants_1.BinaryTokens.EmptyObject: return {};

readValueTypedArray(token) {
// Read the byte length, then create a shared ArrayBuffer for the desired
// typedArray and an Uint8Array which we write to.
const byteLength = this.readUint32();
let value;
// Fast-path if we are deserializing an Uint8Array
if (token === constants_1.BinaryTokens.Uint8Array) {

@@ -120,10 +126,9 @@ value = this._buffer.subarray(this.offset, this.offset + byteLength);

const value = this.createObjectID([]);
for (let i = 0; !this.finished; ++i) {
const raw = this.readUint8();
if (raw === constants_1.BinaryTokens.NullPointer)
break;
if (raw === constants_1.BinaryTokens.Hole)
continue;
this.offsetBack();
value[i] = this.read();
let i = 0;
while (!this.readNullTerminator()) {
if (this.readUint8() !== constants_1.BinaryTokens.Hole) {
this.offsetBack();
value[i] = this.read();
}
++i;
}

@@ -134,2 +139,5 @@ return value;

const end = this._buffer.indexOf(constants_1.BinaryTokens.NullPointer, this.offset);
if (end === -1) {
throw new DeserializerError_1.DeserializerError('Found End-Of-Buffer, expecting a `NullTerminator` before.', DeserializerError_1.DeserializerReason.UnexpectedNullTerminator);
}
const sub = this._buffer.subarray(this.offset, end);

@@ -152,4 +160,2 @@ const str = Deserializer._textDecoder.decode(sub);

readNullTerminator() {
if (this.finished)
throw new DeserializerError_1.DeserializerError('Found End-Of-Buffer, expecting a `NullTerminator` before.', DeserializerError_1.DeserializerReason.UnexpectedNullTerminator);
if (this.watchUint8() === constants_1.BinaryTokens.NullPointer) {

@@ -159,2 +165,5 @@ ++this.offset;

}
else if (this.finished) {
throw new DeserializerError_1.DeserializerError('Found End-Of-Buffer, expecting a `NullTerminator` before.', DeserializerError_1.DeserializerReason.UnexpectedNullTerminator);
}
return false;

@@ -161,0 +170,0 @@ }

@@ -7,4 +7,6 @@ "use strict";

const util_2 = require("util");
// Immutable
const MIN_INT32 = -(2 ** 31);
const MAX_INT32 = (2 ** 31) - 1;
// Mutable
const float64Array = new Float64Array(1);

@@ -42,6 +44,11 @@ const uInt8Float64Array = new Uint8Array(float64Array.buffer);

handleUnsupported(value, hint = typeof value) {
// If there's an onUnsupported handler, try to call it
if (this.onUnsupported) {
// If the serializer was handling an unsupported type, abort the serialization
// as it's most likely an error in the return type of the handler.
if (this._handlingUnsupported) {
throw new SerializerError_1.SerializerError('The modified value was not serializable.', SerializerError_1.SerializerReason.UnsupportedSerializedType);
}
// Set the serializer to handling unsupported, parse, and once it's done
// serializing the output of unSupported, set it back to false.
this._handlingUnsupported = true;

@@ -52,2 +59,3 @@ this.parse(this.onUnsupported(value));

}
// If no handler is available, throw TypeError
throw new SerializerError_1.SerializerError(`Unsupported type '${hint}'.`, SerializerError_1.SerializerReason.UnsupportedType);

@@ -97,2 +105,3 @@ }

default:
/* istanbul ignore next */
throw new Error(`Unreachable code. Got unexpected integer type ${type}`);

@@ -104,12 +113,20 @@ }

return this.parseValueNull();
// Circular reference detection
const id = this._objectIDs.get(value);
if (typeof id === 'number')
return this.parseValueReference(id);
// Set this object to the reference list
this._objectIDs.set(value, this._objectIDs.size);
// If it's an array, parse it
if (Array.isArray(value))
return this.parseValueArray(value);
// We're doing this because it's safer for the context where you
// extend the classes.
const tag = Object.prototype.toString.call(value);
switch (tag) {
// eslint-disable-next-line @typescript-eslint/ban-types
case '[object String]': return this.parseValueObjectString(value);
// eslint-disable-next-line @typescript-eslint/ban-types
case '[object Boolean]': return this.parseValueObjectBoolean(value);
// eslint-disable-next-line @typescript-eslint/ban-types
case '[object Number]': return this.parseValueObjectNumber(value);

@@ -138,2 +155,3 @@ case '[object Date]': return this.parseValueObjectDate(value);

}
// eslint-disable-next-line @typescript-eslint/ban-types
parseValueObjectString(value) {

@@ -143,2 +161,3 @@ this.write8(constants_1.BinaryTokens.StringObject);

}
// eslint-disable-next-line @typescript-eslint/ban-types
parseValueObjectBoolean(value) {

@@ -148,2 +167,3 @@ this.write8(constants_1.BinaryTokens.BooleanObject);

}
// eslint-disable-next-line @typescript-eslint/ban-types
parseValueObjectNumber(value) {

@@ -271,2 +291,3 @@ this.write8(constants_1.BinaryTokens.NumberObject);

const serialized = Serializer._textEncoder.encode(value);
// Strings must not contain a null pointer, since they are null-delimited.
if (serialized.includes(constants_1.BinaryTokens.NullPointer)) {

@@ -281,7 +302,11 @@ throw new SerializerError_1.SerializerError('Unexpected null pointer in serialized string.', SerializerError_1.SerializerReason.UnexpectedNullValue);

if (value % 1 === 0) {
// Byte (N | P)
if (value >= -0xFF && value <= 0xFF)
return sign ? constants_1.BinaryTokens.NByte : constants_1.BinaryTokens.PByte;
// Int32 (N | P)
if (value >= MIN_INT32 && value <= MAX_INT32)
return sign ? constants_1.BinaryTokens.NInt32 : constants_1.BinaryTokens.PInt32;
// Fallback to float
}
// Float64
return sign ? constants_1.BinaryTokens.NFloat64 : constants_1.BinaryTokens.PFloat64;

@@ -288,0 +313,0 @@ }

@@ -12,5 +12,2 @@ import { TypedArray, BinaryTokens } from './constants';

const BYTE: bigint | null;
function nextPowerOfTwo(n: bigint): number;
function bitCount(n: bigint): number;
function byteCount(n: bigint): number;
}

@@ -17,0 +14,0 @@ export declare namespace Numbers {

@@ -11,2 +11,3 @@ "use strict";

const u = 1 << 4;
const s = 1 << 5;
function flagsAsInteger(regExp) {

@@ -17,3 +18,4 @@ return (regExp.global ? g : 0)

| (regExp.sticky ? y : 0)
| (regExp.unicode ? u : 0);
| (regExp.unicode ? u : 0)
| (regExp.dotAll ? s : 0);
}

@@ -33,2 +35,4 @@ RegExps.flagsAsInteger = flagsAsInteger;

ret += 'u';
if (integer & s)
ret += 's';
return ret;

@@ -41,23 +45,10 @@ }

BigIntegers.SUPPORTED = typeof BigInt === 'function';
/* istanbul ignore next: This is environment-specific, unused when unsupported */
BigIntegers.ZERO = BigIntegers.SUPPORTED ? BigInt(0) : null;
/* istanbul ignore next: This is environment-specific, unused when unsupported */
BigIntegers.ONE = BigIntegers.SUPPORTED ? BigInt(1) : null;
/* istanbul ignore next: This is environment-specific, unused when unsupported */
BigIntegers.EIGHT = BigIntegers.SUPPORTED ? BigInt(8) : null;
/* istanbul ignore next: This is environment-specific, unused when unsupported */
BigIntegers.BYTE = BigIntegers.SUPPORTED ? BigInt(0xFF) : null;
function nextPowerOfTwo(n) {
return n > 0 && (n & (n - BigIntegers.ONE)) === BigIntegers.ZERO ? Number(n) : 1 << bitCount(n);
}
BigIntegers.nextPowerOfTwo = nextPowerOfTwo;
function bitCount(n) {
let count = 0;
while (n !== BigIntegers.ZERO) {
n >>= BigIntegers.ONE;
count += 1;
}
return count;
}
BigIntegers.bitCount = bitCount;
function byteCount(n) {
return Math.ceil(bitCount(n) / 8);
}
BigIntegers.byteCount = byteCount;
})(BigIntegers = exports.BigIntegers || (exports.BigIntegers = {}));

@@ -76,9 +67,15 @@ var Numbers;

Float32Array, Float64Array, DataView];
/* istanbul ignore next: This is environment-specific, unused when unsupported */
if (typeof BigInt64Array === 'function')
TypedArrays.constructors.push(BigInt64Array);
/* istanbul ignore next: This is environment-specific, unused when unsupported */
if (typeof BigUint64Array === 'function')
TypedArrays.constructors.push(BigUint64Array);
TypedArrays.typedArrayTags = new Map(TypedArrays.constructors.map(typedArray => [Object.prototype.toString.call(new typedArray(new ArrayBuffer(0))), constants_1.BinaryTokens[typedArray.name]]));
TypedArrays.typedArrayTagToConstructor = new Map(TypedArrays.constructors.map(typedArray => [constants_1.BinaryTokens[typedArray.name], typedArray]));
TypedArrays.typedArrayTags = new Map(TypedArrays.constructors.map(typedArray =>
// @ts-ignore
[Object.prototype.toString.call(new typedArray(new ArrayBuffer(0))), constants_1.BinaryTokens[typedArray.name]]));
TypedArrays.typedArrayTagToConstructor = new Map(TypedArrays.constructors.map(typedArray =>
// @ts-ignore
[constants_1.BinaryTokens[typedArray.name], typedArray]));
})(TypedArrays = exports.TypedArrays || (exports.TypedArrays = {}));
//# sourceMappingURL=util.js.map
{
"name": "binarytf",
"version": "0.1.0",
"version": "0.2.0",
"description": "Binary Term Format",

@@ -12,4 +12,6 @@ "main": "dist/index.js",

"test": "yarn build && node dist/test/suite.js",
"build": "tsc.cmd -p .",
"watch": "tsc.cmd -p . -w"
"coverage": "yarn nyc --require ts-node/register --require source-map-support/register tape src/test/suite.ts | yarn tap-nyc",
"coverage:report": "yarn nyc report --reporter=cobertura",
"build": "tsc -p .",
"watch": "tsc -p . -w"
},

@@ -29,2 +31,3 @@ "keywords": [

"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^0.1.3",
"@types/node": "^12.0.8",

@@ -36,5 +39,9 @@ "@types/tape": "^4.2.33",

"eslint-config-bamboo": "^1.3.0",
"nyc": "^14.1.1",
"source-map-support": "^0.5.12",
"tap-nyc": "^1.0.3",
"tape": "^4.10.2",
"ts-node": "^8.2.0",
"typescript": "^3.5.2"
}
}

@@ -14,5 +14,8 @@ # binarytf

</a>
<a href="https://dev.azure.com/kyranet/kyranet.public/_build/latest?definitionId=1&branchName=master">
<a href="https://dev.azure.com/kyranet/kyranet.public/_build/latest?definitionId=12&branchName=master">
<img src="https://dev.azure.com/kyranet/kyranet.public/_apis/build/status/kyranet.binarytf?branchName=master" alt="Build status" />
</a>
<a href="https://dev.azure.com/kyranet/kyranet.public/_build/latest?definitionId=12&branchName=master">
<img src="https://img.shields.io/azure-devops/coverage/kyranet/kyranet.public/12/master.svg" alt="Azure DevOps coverage">
</a>
<a href="https://lgtm.com/projects/g/kyranet/binarytf/alerts/">

@@ -19,0 +22,0 @@ <img src="https://img.shields.io/lgtm/alerts/g/kyranet/binarytf.svg?logo=lgtm&logoWidth=18" alt="Total alerts">

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet