Comments & code style

This commit is contained in:
Daniel Huigens
2018-07-05 13:44:33 +02:00
parent 1101a05b10
commit ca537e439d
21 changed files with 354 additions and 171 deletions

View File

@@ -60,14 +60,14 @@ function Compressed() {
/**
* Compressed packet data
* @type {String}
* @type {Uint8Array | ReadableStream<Uint8Array>}
*/
this.compressed = null;
}
/**
* Parsing function for the packet.
* @param {String} bytes Payload of a tag 8 packet
* @param {Uint8Array | ReadableStream<Uint8Array>} bytes Payload of a tag 8 packet
*/
Compressed.prototype.read = async function (bytes) {
await stream.parse(bytes, async reader => {
@@ -85,7 +85,7 @@ Compressed.prototype.read = async function (bytes) {
/**
* Return the compressed packet.
* @returns {String} binary compressed packet
* @returns {Uint8Array | ReadableStream<Uint8Array>} binary compressed packet
*/
Compressed.prototype.write = function () {
if (this.compressed === null) {

View File

@@ -47,7 +47,7 @@ function Literal(date=new Date()) {
/**
* Set the packet data to a javascript native string, end of line
* will be normalized to \r\n and by default text is converted to UTF8
* @param {String} text Any native javascript string
* @param {String | ReadableStream<String>} text Any native javascript string
* @param {utf8|binary|text|mime} format (optional) The format of the string of bytes
*/
Literal.prototype.setText = function(text, format='utf8') {
@@ -59,7 +59,8 @@ Literal.prototype.setText = function(text, format='utf8') {
/**
* Returns literal data packets as native JavaScript string
* with normalized end of line to \n
* @returns {String} literal data as text
* @param {Boolean} clone (optional) Whether to return a clone so that getBytes/getText can be called again
* @returns {String | ReadableStream<String>} literal data as text
*/
Literal.prototype.getText = function(clone=false) {
if (this.text === null || util.isStream(this.text)) { // Assume that this.text has been read
@@ -86,7 +87,7 @@ Literal.prototype.getText = function(clone=false) {
/**
* Set the packet data to value represented by the provided string of bytes.
* @param {Uint8Array} bytes The string of bytes
* @param {Uint8Array | ReadableStream<Uint8Array>} bytes The string of bytes
* @param {utf8|binary|text|mime} format The format of the string of bytes
*/
Literal.prototype.setBytes = function(bytes, format) {
@@ -98,7 +99,8 @@ Literal.prototype.setBytes = function(bytes, format) {
/**
* Get the byte sequence representing the literal packet data
* @returns {Uint8Array} A sequence of bytes
* @param {Boolean} clone (optional) Whether to return a clone so that getBytes/getText can be called again
* @returns {Uint8Array | ReadableStream<Uint8Array>} A sequence of bytes
*/
Literal.prototype.getBytes = function(clone=false) {
if (this.data === null) {
@@ -135,7 +137,7 @@ Literal.prototype.getFilename = function() {
/**
* Parsing function for a literal data packet (tag 11).
*
* @param {Uint8Array} input Payload of a tag 11 packet
* @param {Uint8Array | ReadableStream<Uint8Array>} input Payload of a tag 11 packet
* @returns {module:packet.Literal} object representation
*/
Literal.prototype.read = async function(bytes) {
@@ -157,7 +159,7 @@ Literal.prototype.read = async function(bytes) {
/**
* Creates a string representation of the packet
*
* @returns {Uint8Array} Uint8Array representation of the packet
* @returns {Uint8Array | ReadableStream<Uint8Array>} Uint8Array representation of the packet
*/
Literal.prototype.write = function() {
const filename = util.str_to_Uint8Array(util.encode_utf8(this.filename));

View File

@@ -133,7 +133,7 @@ export default {
/**
* Generic static Packet Parser function
*
* @param {Uint8Array} input Input stream as string
* @param {Uint8Array | ReadableStream<Uint8Array>} input Input stream as string
* @param {Function} callback Function to call with the parsed packet
* @returns {Boolean} Returns false if the stream was empty and parsing is done, and true otherwise.
*/

View File

@@ -33,7 +33,7 @@ function List() {
/**
* Reads a stream of binary data and interprents it as a list of packets.
* @param {Uint8Array} A Uint8Array of bytes.
* @param {Uint8Array | ReadableStream<Uint8Array>} A Uint8Array of bytes.
*/
List.prototype.read = async function (bytes) {
this.stream = stream.transformPair(bytes, async (readable, writable) => {

View File

@@ -56,6 +56,7 @@ export default SymEncryptedAEADProtected;
/**
* Parse an encrypted payload of bytes in the order: version, IV, ciphertext (see specification)
* @param {Uint8Array | ReadableStream<Uint8Array>} bytes
*/
SymEncryptedAEADProtected.prototype.read = async function (bytes) {
await stream.parse(bytes, async reader => {
@@ -77,7 +78,7 @@ SymEncryptedAEADProtected.prototype.read = async function (bytes) {
/**
* Write the encrypted payload of bytes in the order: version, IV, ciphertext (see specification)
* @returns {Uint8Array} The encrypted payload
* @returns {Uint8Array | ReadableStream<Uint8Array>} The encrypted payload
*/
SymEncryptedAEADProtected.prototype.write = function () {
if (config.aead_protect_version === 4) {
@@ -90,7 +91,7 @@ SymEncryptedAEADProtected.prototype.write = function () {
* Decrypt the encrypted payload.
* @param {String} sessionKeyAlgorithm The session key's cipher algorithm e.g. 'aes128'
* @param {Uint8Array} key The session key used to encrypt the payload
* @returns {Promise<Boolean>}
* @returns {Boolean}
* @async
*/
SymEncryptedAEADProtected.prototype.decrypt = async function (sessionKeyAlgorithm, key) {
@@ -105,7 +106,6 @@ SymEncryptedAEADProtected.prototype.decrypt = async function (sessionKeyAlgorith
* Encrypt the packet list payload.
* @param {String} sessionKeyAlgorithm The session key's cipher algorithm e.g. 'aes128'
* @param {Uint8Array} key The session key used to encrypt the payload
* @returns {Promise<Boolean>}
* @async
*/
SymEncryptedAEADProtected.prototype.encrypt = async function (sessionKeyAlgorithm, key) {
@@ -122,8 +122,8 @@ SymEncryptedAEADProtected.prototype.encrypt = async function (sessionKeyAlgorith
* En/decrypt the payload.
* @param {encrypt|decrypt} fn Whether to encrypt or decrypt
* @param {Uint8Array} key The session key used to en/decrypt the payload
* @param {Uint8Array} data The data to en/decrypt
* @returns {Promise<Uint8Array>}
* @param {Uint8Array | ReadableStream<Uint8Array>} data The data to en/decrypt
* @returns {Uint8Array | ReadableStream<Uint8Array>}
* @async
*/
SymEncryptedAEADProtected.prototype.crypt = async function (fn, key, data) {

View File

@@ -87,6 +87,7 @@ SymEncryptedIntegrityProtected.prototype.write = function () {
* Encrypt the payload in the packet.
* @param {String} sessionKeyAlgorithm The selected symmetric encryption algorithm to be used e.g. 'aes128'
* @param {Uint8Array} key The key of cipher blocksize length to be used
* @param {Boolean} asStream Whether to set this.encrypted to a stream
* @returns {Promise<Boolean>}
* @async
*/
@@ -116,6 +117,7 @@ SymEncryptedIntegrityProtected.prototype.encrypt = async function (sessionKeyAlg
* Decrypts the encrypted data contained in the packet.
* @param {String} sessionKeyAlgorithm The selected symmetric encryption algorithm to be used e.g. 'aes128'
* @param {Uint8Array} key The key of cipher blocksize length to be used
* @param {Boolean} asStream Whether to read this.encrypted as a stream
* @returns {Promise<Boolean>}
* @async
*/