2011-08-04 20:32:01 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function invalidDN(name) {
|
|
|
|
var e = new Error();
|
|
|
|
e.name = 'InvalidDistinguishedNameError';
|
|
|
|
e.message = name;
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function isAlphaNumeric(c) {
|
|
|
|
var re = /[A-Za-z0-9]/;
|
|
|
|
return re.test(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function isWhitespace(c) {
|
|
|
|
var re = /\s/;
|
|
|
|
return re.test(c);
|
|
|
|
}
|
|
|
|
|
2011-08-30 18:12:34 +00:00
|
|
|
function RDN(obj) {
|
|
|
|
var self = this;
|
2015-02-16 20:53:42 +00:00
|
|
|
this.attrs = {};
|
2011-08-30 18:12:34 +00:00
|
|
|
|
|
|
|
if (obj) {
|
2012-02-18 08:15:52 +00:00
|
|
|
Object.keys(obj).forEach(function (k) {
|
2015-02-16 20:53:42 +00:00
|
|
|
self.set(k, obj[k]);
|
2011-08-30 18:12:34 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
RDN.prototype.set = function set(name, value, opts) {
|
|
|
|
if (typeof (name) !== 'string')
|
|
|
|
throw new TypeError('name (string) required');
|
|
|
|
if (typeof (value) !== 'string')
|
|
|
|
throw new TypeError('value (string) required');
|
2011-08-04 20:32:01 +00:00
|
|
|
var self = this;
|
2015-02-16 20:53:42 +00:00
|
|
|
var lname = name.toLowerCase();
|
|
|
|
this.attrs[lname] = {
|
|
|
|
value: value,
|
|
|
|
name: name
|
|
|
|
};
|
|
|
|
if (opts && typeof (opts) === 'object') {
|
|
|
|
Object.keys(opts).forEach(function (k) {
|
|
|
|
if (k !== 'value')
|
|
|
|
self.attrs[lname][k] = opts[k];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
RDN.prototype.equals = function equals(rdn) {
|
|
|
|
if (typeof (rdn) !== 'object')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var ourKeys = Object.keys(this.attrs);
|
|
|
|
var theirKeys = Object.keys(rdn.attrs);
|
|
|
|
if (ourKeys.length !== theirKeys.length)
|
|
|
|
return false;
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
ourKeys.sort();
|
|
|
|
theirKeys.sort();
|
|
|
|
|
|
|
|
for (var i = 0; i < ourKeys.length; i++) {
|
|
|
|
if (ourKeys[i] !== theirKeys[i])
|
|
|
|
return false;
|
|
|
|
if (this.attrs[ourKeys[i]].value !== rdn.attrs[ourKeys[i]].value)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert RDN to string according to specified formatting options.
|
|
|
|
* (see: DN.format for option details)
|
|
|
|
*/
|
|
|
|
RDN.prototype.format = function format(options) {
|
|
|
|
if (options) {
|
|
|
|
if (typeof (options) !== 'object')
|
|
|
|
throw new TypeError('options must be an object');
|
|
|
|
} else {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
var self = this;
|
2011-08-04 20:32:01 +00:00
|
|
|
var str = '';
|
2015-02-16 20:53:42 +00:00
|
|
|
|
|
|
|
function escapeValue(val, forceQuote) {
|
|
|
|
var out = '';
|
|
|
|
var cur = 0;
|
|
|
|
var len = val.length;
|
|
|
|
var quoted = false;
|
|
|
|
/* BEGIN JSSTYLED */
|
|
|
|
var escaped = /[\\\"]/;
|
|
|
|
var special = /[,=+<>#;]/;
|
|
|
|
/* END JSSTYLED */
|
|
|
|
|
|
|
|
if (len > 0) {
|
|
|
|
// Wrap strings with trailing or leading spaces in quotes
|
|
|
|
quoted = forceQuote || (val[0] == ' ' || val[len-1] == ' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
while (cur < len) {
|
|
|
|
if (escaped.test(val[cur]) || (!quoted && special.test(val[cur]))) {
|
|
|
|
out += '\\';
|
|
|
|
}
|
|
|
|
out += val[cur++];
|
|
|
|
}
|
|
|
|
if (quoted)
|
|
|
|
out = '"' + out + '"';
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
function sortParsed(a, b) {
|
|
|
|
return self.attrs[a].order - self.attrs[b].order;
|
|
|
|
}
|
|
|
|
function sortStandard(a, b) {
|
|
|
|
var nameCompare = a.localeCompare(b);
|
|
|
|
if (nameCompare === 0) {
|
|
|
|
// TODO: Handle binary values
|
|
|
|
return self.attrs[a].value.localeCompare(self.attrs[b].value);
|
|
|
|
} else {
|
|
|
|
return nameCompare;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var keys = Object.keys(this.attrs);
|
|
|
|
if (options.keepOrder) {
|
|
|
|
keys.sort(sortParsed);
|
|
|
|
} else {
|
|
|
|
keys.sort(sortStandard);
|
|
|
|
}
|
|
|
|
|
|
|
|
keys.forEach(function (key) {
|
|
|
|
var attr = self.attrs[key];
|
2011-08-04 20:32:01 +00:00
|
|
|
if (str.length)
|
|
|
|
str += '+';
|
2011-08-10 17:57:58 +00:00
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
if (options.keepCase) {
|
|
|
|
str += attr.name;
|
|
|
|
} else {
|
|
|
|
if (options.upperName)
|
|
|
|
str += key.toUpperCase();
|
|
|
|
else
|
|
|
|
str += key;
|
|
|
|
}
|
|
|
|
|
|
|
|
str += '=' + escapeValue(attr.value, (options.keepQuote && attr.quoted));
|
2011-08-04 20:32:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return str;
|
|
|
|
};
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
|
|
|
|
RDN.prototype.toString = function toString() {
|
|
|
|
return this.format();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-08-10 17:57:58 +00:00
|
|
|
// Thank you OpenJDK!
|
2011-08-04 20:32:01 +00:00
|
|
|
function parse(name) {
|
2012-02-18 08:15:52 +00:00
|
|
|
if (typeof (name) !== 'string')
|
2011-08-04 20:32:01 +00:00
|
|
|
throw new TypeError('name (string) required');
|
|
|
|
|
|
|
|
var cur = 0;
|
|
|
|
var len = name.length;
|
|
|
|
|
|
|
|
function parseRdn() {
|
|
|
|
var rdn = new RDN();
|
2015-02-16 20:53:42 +00:00
|
|
|
var order = 0;
|
|
|
|
rdn.spLead = trim();
|
2011-08-04 20:32:01 +00:00
|
|
|
while (cur < len) {
|
2015-02-16 20:53:42 +00:00
|
|
|
var opts = {
|
|
|
|
order: order
|
|
|
|
};
|
2011-08-04 20:32:01 +00:00
|
|
|
var attr = parseAttrType();
|
|
|
|
trim();
|
|
|
|
if (cur >= len || name[cur++] !== '=')
|
|
|
|
throw invalidDN(name);
|
|
|
|
|
|
|
|
trim();
|
2015-02-16 20:53:42 +00:00
|
|
|
// Parameters about RDN value are set in 'opts' by parseAttrValue
|
|
|
|
var value = parseAttrValue(opts);
|
|
|
|
rdn.set(attr, value, opts);
|
|
|
|
rdn.spTrail = trim();
|
2011-08-04 20:32:01 +00:00
|
|
|
if (cur >= len || name[cur] !== '+')
|
|
|
|
break;
|
|
|
|
++cur;
|
2015-02-16 20:53:42 +00:00
|
|
|
++order;
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
return rdn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function trim() {
|
2013-10-24 23:27:42 +00:00
|
|
|
var count = 0;
|
|
|
|
while ((cur < len) && isWhitespace(name[cur])) {
|
2011-08-04 20:32:01 +00:00
|
|
|
++cur;
|
2013-10-24 23:27:42 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return count;
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function parseAttrType() {
|
|
|
|
var beg = cur;
|
|
|
|
while (cur < len) {
|
|
|
|
var c = name[cur];
|
|
|
|
if (isAlphaNumeric(c) ||
|
|
|
|
c == '.' ||
|
|
|
|
c == '-' ||
|
|
|
|
c == ' ') {
|
|
|
|
++cur;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Back out any trailing spaces.
|
|
|
|
while ((cur > beg) && (name[cur - 1] == ' '))
|
|
|
|
--cur;
|
|
|
|
|
|
|
|
if (beg == cur)
|
|
|
|
throw invalidDN(name);
|
|
|
|
|
|
|
|
return name.slice(beg, cur);
|
|
|
|
}
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
function parseAttrValue(opts) {
|
2011-08-04 20:32:01 +00:00
|
|
|
if (cur < len && name[cur] == '#') {
|
2015-02-16 20:53:42 +00:00
|
|
|
opts.binary = true;
|
2011-08-04 20:32:01 +00:00
|
|
|
return parseBinaryAttrValue();
|
|
|
|
} else if (cur < len && name[cur] == '"') {
|
2015-02-16 20:53:42 +00:00
|
|
|
opts.quoted = true;
|
2011-08-04 20:32:01 +00:00
|
|
|
return parseQuotedAttrValue();
|
|
|
|
} else {
|
|
|
|
return parseStringAttrValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseBinaryAttrValue() {
|
|
|
|
var beg = cur++;
|
|
|
|
while (cur < len && isAlphaNumeric(name[cur]))
|
|
|
|
++cur;
|
|
|
|
|
|
|
|
return name.slice(beg, cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseQuotedAttrValue() {
|
2015-02-16 20:53:42 +00:00
|
|
|
var str = '';
|
|
|
|
++cur; // Consume the first quote
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
while ((cur < len) && name[cur] != '"') {
|
|
|
|
if (name[cur] === '\\')
|
2015-02-16 20:53:42 +00:00
|
|
|
cur++;
|
|
|
|
str += name[cur++];
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
if (cur++ >= len) // no closing quote
|
|
|
|
throw invalidDN(name);
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
return str;
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function parseStringAttrValue() {
|
|
|
|
var beg = cur;
|
2015-02-16 20:53:42 +00:00
|
|
|
var str = '';
|
2011-08-04 20:32:01 +00:00
|
|
|
var esc = -1;
|
|
|
|
|
|
|
|
while ((cur < len) && !atTerminator()) {
|
|
|
|
if (name[cur] === '\\') {
|
2015-02-16 20:53:42 +00:00
|
|
|
// Consume the backslash and mark its place just in case it's escaping
|
|
|
|
// whitespace which needs to be preserved.
|
|
|
|
esc = cur++;
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
2015-02-16 20:53:42 +00:00
|
|
|
if (cur === len) // backslash followed by nothing
|
|
|
|
throw invalidDN(name);
|
|
|
|
str += name[cur++];
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
// Trim off (unescaped) trailing whitespace and rewind cursor to the end of
|
|
|
|
// the AttrValue to record whitespace length.
|
|
|
|
for (; cur > beg; cur--) {
|
|
|
|
if (!isWhitespace(name[cur - 1]) || (esc === (cur - 1)))
|
2011-08-04 20:32:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-16 20:53:42 +00:00
|
|
|
return str.slice(0, cur - beg);
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function atTerminator() {
|
|
|
|
return (cur < len &&
|
|
|
|
(name[cur] === ',' ||
|
|
|
|
name[cur] === ';' ||
|
|
|
|
name[cur] === '+'));
|
|
|
|
}
|
|
|
|
|
|
|
|
var rdns = [];
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
// Short-circuit for empty DNs
|
|
|
|
if (len === 0)
|
|
|
|
return new DN(rdns);
|
|
|
|
|
2011-08-04 20:32:01 +00:00
|
|
|
rdns.push(parseRdn());
|
|
|
|
while (cur < len) {
|
|
|
|
if (name[cur] === ',' || name[cur] === ';') {
|
|
|
|
++cur;
|
|
|
|
rdns.push(parseRdn());
|
|
|
|
} else {
|
|
|
|
throw invalidDN(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
return new DN(rdns);
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///--- API
|
|
|
|
|
|
|
|
|
|
|
|
function DN(rdns) {
|
|
|
|
if (!Array.isArray(rdns))
|
|
|
|
throw new TypeError('rdns ([object]) required');
|
2012-02-18 08:15:52 +00:00
|
|
|
rdns.forEach(function (rdn) {
|
|
|
|
if (typeof (rdn) !== 'object')
|
2011-08-04 20:32:01 +00:00
|
|
|
throw new TypeError('rdns ([object]) required');
|
|
|
|
});
|
|
|
|
|
|
|
|
this.rdns = rdns.slice();
|
2015-02-16 20:53:42 +00:00
|
|
|
this._format = {};
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
this.__defineGetter__('length', function () {
|
2011-08-04 20:32:01 +00:00
|
|
|
return this.rdns.length;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
/**
|
|
|
|
* Convert DN to string according to specified formatting options.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* - options: formatting parameters (optional, details below)
|
|
|
|
*
|
|
|
|
* Options are divided into two types:
|
|
|
|
* - Preservation options: Using data recorded during parsing, details of the
|
|
|
|
* original DN are preserved when converting back into a string.
|
|
|
|
* - Modification options: Alter string formatting defaults.
|
|
|
|
*
|
|
|
|
* Preservation options _always_ take precedence over modification options.
|
|
|
|
*
|
|
|
|
* Preservation Options:
|
|
|
|
* - keepOrder: Order of multi-value RDNs.
|
|
|
|
* - keepQuote: RDN values which were quoted will remain so.
|
|
|
|
* - keepSpace: Leading/trailing spaces will be output.
|
|
|
|
* - keepCase: Parsed attr name will be output instead of lowercased version.
|
|
|
|
*
|
|
|
|
* Modification Options:
|
|
|
|
* - upperName: RDN names will be uppercased instead of lowercased.
|
|
|
|
* - skipSpace: Disable trailing space after RDN separators
|
|
|
|
*/
|
|
|
|
DN.prototype.format = function (options) {
|
|
|
|
if (options) {
|
|
|
|
if (typeof (options) !== 'object')
|
|
|
|
throw new TypeError('options must be an object');
|
|
|
|
} else {
|
|
|
|
options = this._format;
|
|
|
|
}
|
|
|
|
var str = '';
|
|
|
|
function repeatChar(c, n) {
|
|
|
|
var out = '';
|
|
|
|
var max = n ? n : 0;
|
|
|
|
for (var i = 0; i < max; i++)
|
|
|
|
out += c;
|
|
|
|
return out;
|
|
|
|
}
|
2012-02-18 08:15:52 +00:00
|
|
|
this.rdns.forEach(function (rdn) {
|
2015-02-16 20:53:42 +00:00
|
|
|
var rdnString = rdn.format(options);
|
|
|
|
if (str.length !== 0) {
|
|
|
|
str += ',';
|
|
|
|
}
|
|
|
|
if (options.keepSpace) {
|
|
|
|
str += (repeatChar(' ', rdn.spLead) +
|
|
|
|
rdnString + repeatChar(' ', rdn.spTrail));
|
|
|
|
} else if (options.skipSpace === true || str.length === 0) {
|
|
|
|
str += rdnString;
|
|
|
|
} else {
|
|
|
|
str += ' ' + rdnString;
|
|
|
|
}
|
2011-08-04 20:32:01 +00:00
|
|
|
});
|
2015-02-16 20:53:42 +00:00
|
|
|
return str;
|
2013-10-24 23:27:42 +00:00
|
|
|
};
|
|
|
|
|
2014-09-30 23:39:19 +00:00
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
/**
|
|
|
|
* Set default string formatting options.
|
|
|
|
*/
|
|
|
|
DN.prototype.setFormat = function setFormat(options) {
|
|
|
|
if (typeof (options) !== 'object')
|
|
|
|
throw new TypeError('options must be an object');
|
|
|
|
this._format = options;
|
2011-08-04 20:32:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
DN.prototype.toString = function () {
|
|
|
|
return this.format();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DN.prototype.parentOf = function parentOf(dn) {
|
2012-02-18 08:15:52 +00:00
|
|
|
if (typeof (dn) !== 'object')
|
2011-08-04 20:32:01 +00:00
|
|
|
dn = parse(dn);
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
if (this.rdns.length >= dn.rdns.length)
|
2011-08-04 20:32:01 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
var diff = dn.rdns.length - this.rdns.length;
|
|
|
|
for (var i = this.rdns.length - 1; i >= 0; i--) {
|
|
|
|
var myRDN = this.rdns[i];
|
|
|
|
var theirRDN = dn.rdns[i + diff];
|
2011-11-08 01:23:38 +00:00
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
if (!myRDN.equals(theirRDN))
|
2011-11-08 01:23:38 +00:00
|
|
|
return false;
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
DN.prototype.childOf = function childOf(dn) {
|
2012-02-18 08:15:52 +00:00
|
|
|
if (typeof (dn) !== 'object')
|
2011-08-04 20:32:01 +00:00
|
|
|
dn = parse(dn);
|
2015-02-16 20:53:42 +00:00
|
|
|
return dn.parentOf(this);
|
|
|
|
};
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
|
2015-02-16 20:53:42 +00:00
|
|
|
DN.prototype.isEmpty = function isEmpty() {
|
|
|
|
return (this.rdns.length === 0);
|
2011-08-04 20:32:01 +00:00
|
|
|
};
|
|
|
|
|
2011-08-16 00:52:05 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
DN.prototype.equals = function (dn) {
|
|
|
|
if (typeof (dn) !== 'object')
|
2011-08-15 16:44:31 +00:00
|
|
|
dn = parse(dn);
|
2011-08-10 17:57:58 +00:00
|
|
|
|
|
|
|
if (this.rdns.length !== dn.rdns.length)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (var i = 0; i < this.rdns.length; i++) {
|
2015-02-16 20:53:42 +00:00
|
|
|
if (!this.rdns[i].equals(dn.rdns[i]))
|
2011-09-23 15:54:48 +00:00
|
|
|
return false;
|
2011-08-10 17:57:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
DN.prototype.parent = function () {
|
2015-02-16 20:53:42 +00:00
|
|
|
if (this.rdns.length !== 0) {
|
2011-08-10 17:57:58 +00:00
|
|
|
var save = this.rdns.shift();
|
|
|
|
var dn = new DN(this.rdns);
|
|
|
|
this.rdns.unshift(save);
|
|
|
|
return dn;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
DN.prototype.clone = function () {
|
2015-02-16 20:53:42 +00:00
|
|
|
var dn = new DN(this.rdns);
|
|
|
|
dn._format = this._format;
|
|
|
|
return dn;
|
2011-10-18 15:50:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
DN.prototype.reverse = function () {
|
2011-10-18 15:50:44 +00:00
|
|
|
this.rdns.reverse();
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
DN.prototype.pop = function () {
|
2011-10-18 15:50:44 +00:00
|
|
|
return this.rdns.pop();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
DN.prototype.push = function (rdn) {
|
|
|
|
if (typeof (rdn) !== 'object')
|
2011-10-18 15:50:44 +00:00
|
|
|
throw new TypeError('rdn (RDN) required');
|
|
|
|
|
|
|
|
return this.rdns.push(rdn);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
DN.prototype.shift = function () {
|
2011-10-18 15:50:44 +00:00
|
|
|
return this.rdns.shift();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
DN.prototype.unshift = function (rdn) {
|
|
|
|
if (typeof (rdn) !== 'object')
|
2011-10-18 15:50:44 +00:00
|
|
|
throw new TypeError('rdn (RDN) required');
|
|
|
|
|
|
|
|
return this.rdns.unshift(rdn);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-30 23:39:19 +00:00
|
|
|
DN.isDN = function (dn) {
|
|
|
|
if (!dn || typeof (dn) !== 'object') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (dn instanceof DN) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Array.isArray(dn.rdns)) {
|
|
|
|
// Really simple duck-typing for now
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2011-10-18 15:50:44 +00:00
|
|
|
|
|
|
|
///--- Exports
|
|
|
|
|
2011-08-04 20:32:01 +00:00
|
|
|
module.exports = {
|
|
|
|
|
|
|
|
parse: parse,
|
|
|
|
|
|
|
|
DN: DN,
|
|
|
|
|
|
|
|
RDN: RDN
|
|
|
|
|
|
|
|
};
|