Change option layout

This commit is contained in:
Andy Wang 2020-01-14 00:03:33 +00:00
parent 4b90743ba8
commit f30000e62f

View file

@ -40,17 +40,6 @@ class Chacha20Poly1305Encrypt extends Operation {
"value": "", "value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"] "toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
}, },
{
"name": "Authenticated Encryption",
"type": "boolean",
"value": "true"
},
{
"name": "Additional Authentication Data",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
},
{ {
"name": "Input", "name": "Input",
"type": "option", "type": "option",
@ -60,6 +49,17 @@ class Chacha20Poly1305Encrypt extends Operation {
"name": "Output", "name": "Output",
"type": "option", "type": "option",
"value": ["Hex", "Raw"] "value": ["Hex", "Raw"]
},
{
"name": "Mode",
"type": "option",
"value": ["Chacha20", "Chacha20-Poly1305"]
},
{
"name": "Optional Additional Authentication Data",
"type": "toggleString",
"value": "",
"toggleValues": ["Hex", "UTF8", "Latin1", "Base64"]
} }
]; ];
} }
@ -72,10 +72,10 @@ class Chacha20Poly1305Encrypt extends Operation {
run(input, args) { run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option), const key = Utils.convertToByteArray(args[0].string, args[0].option),
nonce = Utils.convertToByteArray(args[1].string, args[1].option), nonce = Utils.convertToByteArray(args[1].string, args[1].option),
useAEAD = args[2], inputType = args[2],
aad = Utils.convertToByteArray(args[3].string, args[3].option), outputType = args[3],
inputType = args[4], mode = args[4],
outputType = args[5]; aad = Utils.convertToByteArray(args[5].string, args[5].option);
if (key.length !== 32) { if (key.length !== 32) {
throw new OperationError(`Invalid key length: ${key.length} bytes throw new OperationError(`Invalid key length: ${key.length} bytes
@ -89,6 +89,8 @@ Chacha20 requires a nonce length of 8 or 12 bytes`);
} }
input = Utils.convertToByteArray(input, inputType); input = Utils.convertToByteArray(input, inputType);
const useAEAD = mode === "Chacha20-Poly1305";
if (useAEAD) { if (useAEAD) {
const aead = new Chacha20Poly1305(key, nonce); const aead = new Chacha20Poly1305(key, nonce);
const ret = aead.seal(input, aad); const ret = aead.seal(input, aad);