Module: util

This object contains utility functions
Source:

Requires

Methods

(static) bin2str(bin) → {String}

Convert an array of integers(0.255) to a string
Parameters:
Name Type Description
bin Array.<Integer> An array of (binary) integers to convert
Source:
Returns:
The string representation of the array
Type
String

(static) calc_checksum(Uint8Array) → {Integer}

Calculates a 16bit sum of a Uint8Array by adding each character codes modulus 65535
Parameters:
Name Type Description
Uint8Array Uint8Array to create a sum of
Source:
Returns:
An integer containing the sum of all character codes % 65535
Type
Integer

(static) concatUint8Array(Array) → {Uint8array}

Concat Uint8arrays
Parameters:
Name Type Description
Array Array.<Uint8array> of Uint8Arrays to concatenate
Source:
Returns:
Concatenated array
Type
Uint8array

(static) copyUint8Array(Array) → {Uint8Array}

Deep copy Uint8Array
Parameters:
Name Type Description
Array Uint8Array to copy
Source:
Returns:
new Uint8Array
Type
Uint8Array

(static) decode_utf8(utf8) → {String}

Convert a string of utf8 bytes to a native javascript string
Parameters:
Name Type Description
utf8 String A valid squence of utf8 bytes
Source:
Returns:
A native javascript string
Type
String

(static) detectNode()

Detect Node.js runtime.
Source:

(static) encode_utf8(str) → {String}

Convert a native javascript string to a string of utf8 bytes
Parameters:
Name Type Description
str String The string to convert
Source:
Returns:
A valid squence of utf8 bytes
Type
String

(static) equalsUint8Array(first, second) → {Boolean}

Check Uint8Array equality
Parameters:
Name Type Description
first Uint8Array array
second Uint8Array array
Source:
Returns:
equality
Type
Boolean

(static) get_hashAlgorithmString() → {String}

Return the algorithm type as string
Source:
Returns:
String representing the message type
Type
String

(static) getNodeBuffer() → {function}

Get native Node.js Buffer constructor. This should be used since Buffer is not available under browserify.
Source:
Returns:
The Buffer constructor or 'undefined'
Type
function

(static) getNodeCrypto() → {Object}

Get native Node.js crypto api. The default configuration is to use the api when available. But it can also be deactivated with config.use_native
Source:
Returns:
The crypto module or 'undefined'
Type
Object

(static) getTransferables(obj) → {Array.<ArrayBuffer>}

Get transferable objects to pass buffers with zero copy (similar to "pass by reference" in C++) See: https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage
Parameters:
Name Type Description
obj Object the options object to be passed to the web worker
Source:
Returns:
an array of binary data to be passed
Type
Array.<ArrayBuffer>

(static) getWebCrypto() → {Object}

Get native Web Cryptography api, only the current version of the spec. The default configuration is to use the api when available. But it can be deactivated with config.use_native
Source:
Returns:
The SubtleCrypto api or 'undefined'
Type
Object

(static) getWebCryptoAll() → {Object}

Get native Web Cryptography api for all browsers, including legacy implementations of the spec e.g IE11 and Safari 8/9. The default configuration is to use the api when available. But it can be deactivated with config.use_native
Source:
Returns:
The SubtleCrypto api or 'undefined'
Type
Object

(static) hex2bin(str) → {String}

Create binary string from a hex encoded string
Parameters:
Name Type Description
str String Hex string to convert
Source:
Returns:
String containing the binary values
Type
String

(static) hexidump(str) → {String}

Creating a hex string from an binary array of integers (0..255)
Parameters:
Name Type Description
str String Array of bytes to convert
Source:
Returns:
Hexadecimal representation of the array
Type
String

(static) hexstrdump(str) → {String}

Create hexstring from a binary
Parameters:
Name Type Description
str String String to convert
Source:
Returns:
String containing the hexadecimal values
Type
String

(static) print_debug(str)

Helper function to print a debug message. Debug messages are only printed if
Parameters:
Name Type Description
str String String of the debug message
Source:

(static) print_debug_hexstr_dump(str)

Helper function to print a debug message. Debug messages are only printed if
Parameters:
Name Type Description
str String String of the debug message
Source:

(static) promisify(fn) → {function}

Wraps a generic synchronous function in an ES6 Promise.
Parameters:
Name Type Description
fn function The function to be wrapped
Source:
Returns:
The function wrapped in a Promise
Type
function

(static) promisifyIE11Op(cryptoOp, errmsg) → {Promise}

Converts an IE11 web crypro api result to a promise. This is required since IE11 implements an old version of the Web Crypto specification that does not use promises.
Parameters:
Name Type Description
cryptoOp Object The return value of an IE11 web cryptro api call
errmsg String An error message for a specific operation
Source:
Returns:
The resulting Promise
Type
Promise

(static) shiftRight(value, bitcount) → {String}

Shifting a string to n bits right
Parameters:
Name Type Description
value String The string to shift
bitcount Integer Amount of bits to shift (MUST be smaller than 9)
Source:
Returns:
Resulting string.
Type
String

(static) str2bin(str) → {Array.<Integer>}

Convert a string to an array of integers(0.255)
Parameters:
Name Type Description
str String String to convert
Source:
Returns:
An array of (binary) integers
Type
Array.<Integer>

(static) str2Uint8Array(str) → {Uint8Array}

Convert a string to a Uint8Array
Parameters:
Name Type Description
str String String to convert
Source:
Returns:
The array of (binary) integers
Type
Uint8Array

(static) Uint8Array2str(bin) → {String}

Convert a Uint8Array to a string. This currently functions the same as bin2str.
Parameters:
Name Type Description
bin Uint8Array An array of (binary) integers to convert
Source:
Returns:
String representation of the array
Type
String