From 75a5fc0ddc05e451587e5ccfc91fe5c98fd53ec2 Mon Sep 17 00:00:00 2001 From: bwhitn Date: Fri, 15 Dec 2017 19:46:21 -0500 Subject: [PATCH] Added Test, function checks, and cleaned some output. --- src/core/operations/NetBIOS.js | 23 +++++++++++++++------ test/index.js | 1 + test/tests/operations/NetBIOS.js | 34 ++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 test/tests/operations/NetBIOS.js diff --git a/src/core/operations/NetBIOS.js b/src/core/operations/NetBIOS.js index f97672c9..1ca1f897 100644 --- a/src/core/operations/NetBIOS.js +++ b/src/core/operations/NetBIOS.js @@ -1,3 +1,5 @@ +import Utils from "../Utils.js"; + /** * NetBIOS operations. * @@ -26,9 +28,15 @@ const NetBIOS = { let output = [], offset = args[0]; - for (let i = 0; i < input.length; i++) { - output.push((input[i] >> 4) + offset); - output.push((input[i] & 0xf) + offset); + if (input.length <= 16) { + for (let i = 0; i < input.length; i++) { + output.push((input[i] >> 4) + offset); + output.push((input[i] & 0xf) + offset); + } + for (let i = input.length; i < 16; i++) { + output.push(67); + output.push(65); + } } return output; @@ -46,9 +54,12 @@ const NetBIOS = { let output = [], offset = args[0]; - for (let i = 0; i < input.length; i += 2) { - output.push((((input[i] & 0xff) - offset) << 4) | - (((input[i + 1] & 0xff) - offset) & 0xf)); + if (input.length <= 32 && (input.length % 2) == 0) { + for (let i = 0; i < input.length; i += 2) { + output.push((((input[i] & 0xff) - offset) << 4) | + (((input[i + 1] & 0xff) - offset) & 0xf)); + } + output = Utils.strToByteArray(Utils.byteArrayToChars(output).trim()); } return output; diff --git a/test/index.js b/test/index.js index 748e1103..9c7e3ca8 100644 --- a/test/index.js +++ b/test/index.js @@ -26,6 +26,7 @@ import "./tests/operations/Image.js"; import "./tests/operations/MorseCode.js"; import "./tests/operations/MS.js"; import "./tests/operations/PHP.js"; +import "./tests/operations/NetBIOS.js"; import "./tests/operations/StrUtils.js"; import "./tests/operations/SeqUtils.js"; diff --git a/test/tests/operations/NetBIOS.js b/test/tests/operations/NetBIOS.js new file mode 100644 index 00000000..2994b79e --- /dev/null +++ b/test/tests/operations/NetBIOS.js @@ -0,0 +1,34 @@ +/** + * NetBIOS tests. + * + * @author bwhitn [brian.m.whitney@outlook.com] + * + * @copyright Crown Copyright 2017 + * @license Apache-2.0 + */ +import TestRegister from "../../TestRegister.js"; + +TestRegister.addTests([ + { + name: "Encode NetBIOS name", + input: "The NetBIOS name", + expectedOutput: "FEGIGFCAEOGFHEECEJEPFDCAGOGBGNGF", + recipeConfig: [ + { + op: "Encode NetBIOS Name", + args: [65], + }, + ], + }, + { + name: "Decode NetBIOS Name", + input: "FEGIGFCAEOGFHEECEJEPFDCAGOGBGNGF", + expectedOutput: "The NetBIOS name", + recipeConfig: [ + { + op: "Decode NetBIOS Name", + args: [65], + }, + ], + }, +]);