Commit d5608529 authored by Ray Bellis's avatar Ray Bellis

more type checks, todo/fixme updates

parent 90f69f8f
......@@ -178,7 +178,7 @@ class Attribute {
let abuf = this.avalue.toBuffer();
// convert encrypted attributes
// FIXME: support additional algorithms
// @TODO: support additional algorithms
if (dict.flags.encrypt === 1) {
abuf = encodeMD5(abuf, secret, authenticator);
}
......@@ -299,7 +299,7 @@ class Attribute {
if (encrypt === 1) {
data = decodeMD5(data, secret, authenticator);
} else {
// FIXME: support additional algorithms
// @TODO: support additional algorithms
throw new Error('attribute uses unsupported encryption scheme');
}
}
......
......@@ -38,7 +38,8 @@ function parseAttributes(buf, offset, secret, authenticator)
const attr = Attribute.fromWire(data, secret, authenticator);
attrs.push(attr);
n += len;
// TODO account for multiple sub-attributes in a single VSA
// @TODO account for multiple sub-attributes in a single VSA
}
}
return attrs;
......@@ -55,8 +56,21 @@ class AttributeList {
*/
constructor(attrs = [], readonly = false) {
// TODO - check parameters
// check parameters
if (!Array.isArray(attrs)) {
throw new TypeError('attrs must be an array');
}
if (typeof readonly !== 'boolean') {
throw new TypeError('readonly must be a boolean');
}
// check that element is an attribute
if (!attrs.every(a => a instanceof Attribute)) {
throw new TypeError('non-Attribute entry found in attrs array');
}
// copy the array
const list = attrs.slice(0);
/**
......
......@@ -156,10 +156,15 @@ class AString extends ABuffer {
* @param {string} value - the value
*/
static fromValue(value) {
// TODO: typecheck for buffer
// type checks
if (typeof value === 'string') {
value = Buffer.from(value, 'utf-8');
}
if (!(value instanceof Buffer)) {
throw new TypeError('value must be a string or a buffer');
}
return this.fromBuffer(value);
}
......
......@@ -22,20 +22,20 @@ const typeMap = new Map([
[ 'uint16', AV.Short ],
[ 'short', AV.Short ],
[ 'integer', AV.Integer ],
[ 'uint64', AV.Buffer ], // @FIXME
[ 'integer64', AV.Buffer ], // @FIXME
[ 'signed', AV.Integer ], // @FIXME
[ 'uint64', AV.Buffer ], // @TODO
[ 'integer64', AV.Buffer ], // @TODO
[ 'signed', AV.Integer ], // @TODO
[ 'ipaddr', AV.Inet4 ],
[ 'ipv4prefix', AV.Buffer ], // @FIXME
[ 'ipv6addr', AV.Buffer ], // @FIXME
[ 'ipv6prefix', AV.Buffer ], // @FIXME
[ 'ifid', AV.Buffer ], // @FIXME
[ 'ipv4prefix', AV.Buffer ], // @TODO
[ 'ipv6addr', AV.Buffer ], // @TODO
[ 'ipv6prefix', AV.Buffer ], // @TODO
[ 'ifid', AV.Buffer ], // @TODO
[ 'date', AV.Date ],
[ 'tlv', AV.Buffer ], // @FIXME
[ 'combo-ip', AV.Buffer ], // @FIXME
[ 'abinary', AV.Buffer ], // @FIXME
[ 'ether', AV.Buffer ], // @FIXME
[ 'struct', AV.Buffer ], // @FIXME
[ 'tlv', AV.Buffer ], // @TODO
[ 'combo-ip', AV.Buffer ], // @TODO
[ 'abinary', AV.Buffer ], // @TODO
[ 'ether', AV.Buffer ], // @TODO
[ 'struct', AV.Buffer ], // @TODO
// [ 'extended', AV.Buffer ],
// [ 'long-extended', AV.Buffer ],
[ 'vsa', AV.VSA ],
......@@ -55,7 +55,8 @@ class DictionaryEntry {
type = type.toLowerCase();
// @FIXME: ignore field width spec for octets[n]
// ignore field width spec for octets[n]
// @TODO - add support
if (type.match(/^octets\[\d+\]$/)) {
type = 'octets';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment