node_modules updated, buefy add to lib folder
This commit is contained in:
+67
@@ -0,0 +1,67 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var asn1 = require('asn1');
|
||||
|
||||
var Protocol = require('../protocol');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var Ber = asn1.Ber;
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function Control(options) {
|
||||
assert.optionalObject(options);
|
||||
options = options || {};
|
||||
assert.optionalString(options.type);
|
||||
assert.optionalBool(options.criticality);
|
||||
if (options.value) {
|
||||
assert.buffer(options.value);
|
||||
}
|
||||
|
||||
this.type = options.type || '';
|
||||
this.criticality = options.critical || options.criticality || false;
|
||||
this.value = options.value || null;
|
||||
}
|
||||
Object.defineProperties(Control.prototype, {
|
||||
json: {
|
||||
get: function getJson() {
|
||||
var obj = {
|
||||
controlType: this.type,
|
||||
criticality: this.criticality,
|
||||
controlValue: this.value
|
||||
};
|
||||
return (typeof (this._json) === 'function' ? this._json(obj) : obj);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Control.prototype.toBer = function toBer(ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
ber.startSequence();
|
||||
ber.writeString(this.type || '');
|
||||
ber.writeBoolean(this.criticality);
|
||||
if (typeof (this._toBer) === 'function') {
|
||||
this._toBer(ber);
|
||||
} else {
|
||||
if (this.value)
|
||||
ber.writeString(this.value);
|
||||
}
|
||||
|
||||
ber.endSequence();
|
||||
return;
|
||||
};
|
||||
|
||||
Control.prototype.toString = function toString() {
|
||||
return this.json;
|
||||
};
|
||||
|
||||
|
||||
///--- Exports
|
||||
module.exports = Control;
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var asn1 = require('asn1');
|
||||
|
||||
var Control = require('./control');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var BerReader = asn1.BerReader;
|
||||
var BerWriter = asn1.BerWriter;
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function EntryChangeNotificationControl(options) {
|
||||
assert.optionalObject(options);
|
||||
options = options || {};
|
||||
options.type = EntryChangeNotificationControl.OID;
|
||||
if (options.value) {
|
||||
if (Buffer.isBuffer(options.value)) {
|
||||
this.parse(options.value);
|
||||
} else if (typeof (options.value) === 'object') {
|
||||
this._value = options.value;
|
||||
} else {
|
||||
throw new TypeError('options.value must be a Buffer or Object');
|
||||
}
|
||||
options.value = null;
|
||||
}
|
||||
Control.call(this, options);
|
||||
}
|
||||
util.inherits(EntryChangeNotificationControl, Control);
|
||||
Object.defineProperties(EntryChangeNotificationControl.prototype, {
|
||||
value: {
|
||||
get: function () { return this._value || {}; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
EntryChangeNotificationControl.prototype.parse = function parse(buffer) {
|
||||
assert.ok(buffer);
|
||||
|
||||
var ber = new BerReader(buffer);
|
||||
if (ber.readSequence()) {
|
||||
this._value = {
|
||||
changeType: ber.readInt()
|
||||
};
|
||||
|
||||
// if the operation was moddn, then parse the optional previousDN attr
|
||||
if (this._value.changeType === 8)
|
||||
this._value.previousDN = ber.readString();
|
||||
|
||||
this._value.changeNumber = ber.readInt();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
EntryChangeNotificationControl.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
if (!this._value)
|
||||
return;
|
||||
|
||||
var writer = new BerWriter();
|
||||
writer.startSequence();
|
||||
writer.writeInt(this.value.changeType);
|
||||
if (this.value.previousDN)
|
||||
writer.writeString(this.value.previousDN);
|
||||
|
||||
writer.writeInt(parseInt(this.value.changeNumber, 10));
|
||||
writer.endSequence();
|
||||
|
||||
ber.writeBuffer(writer.buffer, 0x04);
|
||||
};
|
||||
|
||||
EntryChangeNotificationControl.prototype._json = function (obj) {
|
||||
obj.controlValue = this.value;
|
||||
return obj;
|
||||
};
|
||||
|
||||
EntryChangeNotificationControl.OID = '2.16.840.1.113730.3.4.7';
|
||||
|
||||
|
||||
///--- Exports
|
||||
module.exports = EntryChangeNotificationControl;
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert');
|
||||
var Ber = require('asn1').Ber;
|
||||
|
||||
var Control = require('./control');
|
||||
var EntryChangeNotificationControl =
|
||||
require('./entry_change_notification_control');
|
||||
var PersistentSearchControl = require('./persistent_search_control');
|
||||
var PagedResultsControl = require('./paged_results_control');
|
||||
var ServerSideSortingRequestControl =
|
||||
require('./server_side_sorting_request_control.js');
|
||||
var ServerSideSortingResponseControl =
|
||||
require('./server_side_sorting_response_control.js');
|
||||
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
module.exports = {
|
||||
|
||||
getControl: function getControl(ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
if (ber.readSequence() === null)
|
||||
return null;
|
||||
|
||||
var type;
|
||||
var opts = {
|
||||
criticality: false,
|
||||
value: null
|
||||
};
|
||||
|
||||
if (ber.length) {
|
||||
var end = ber.offset + ber.length;
|
||||
|
||||
type = ber.readString();
|
||||
if (ber.offset < end) {
|
||||
if (ber.peek() === Ber.Boolean)
|
||||
opts.criticality = ber.readBoolean();
|
||||
}
|
||||
|
||||
if (ber.offset < end)
|
||||
opts.value = ber.readString(Ber.OctetString, true);
|
||||
}
|
||||
|
||||
var control;
|
||||
switch (type) {
|
||||
case PersistentSearchControl.OID:
|
||||
control = new PersistentSearchControl(opts);
|
||||
break;
|
||||
case EntryChangeNotificationControl.OID:
|
||||
control = new EntryChangeNotificationControl(opts);
|
||||
break;
|
||||
case PagedResultsControl.OID:
|
||||
control = new PagedResultsControl(opts);
|
||||
break;
|
||||
case ServerSideSortingRequestControl.OID:
|
||||
control = new ServerSideSortingRequestControl(opts);
|
||||
break;
|
||||
case ServerSideSortingResponseControl.OID:
|
||||
control = new ServerSideSortingResponseControl(opts);
|
||||
break;
|
||||
default:
|
||||
opts.type = type;
|
||||
control = new Control(opts);
|
||||
break;
|
||||
}
|
||||
|
||||
return control;
|
||||
},
|
||||
|
||||
Control: Control,
|
||||
EntryChangeNotificationControl: EntryChangeNotificationControl,
|
||||
PagedResultsControl: PagedResultsControl,
|
||||
PersistentSearchControl: PersistentSearchControl,
|
||||
ServerSideSortingRequestControl: ServerSideSortingRequestControl,
|
||||
ServerSideSortingResponseControl: ServerSideSortingResponseControl
|
||||
};
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var asn1 = require('asn1');
|
||||
|
||||
var Control = require('./control');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var BerReader = asn1.BerReader;
|
||||
var BerWriter = asn1.BerWriter;
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function PagedResultsControl(options) {
|
||||
assert.optionalObject(options);
|
||||
options = options || {};
|
||||
options.type = PagedResultsControl.OID;
|
||||
if (options.value) {
|
||||
if (Buffer.isBuffer(options.value)) {
|
||||
this.parse(options.value);
|
||||
} else if (typeof (options.value) === 'object') {
|
||||
this._value = options.value;
|
||||
} else {
|
||||
throw new TypeError('options.value must be a Buffer or Object');
|
||||
}
|
||||
options.value = null;
|
||||
}
|
||||
Control.call(this, options);
|
||||
}
|
||||
util.inherits(PagedResultsControl, Control);
|
||||
Object.defineProperties(PagedResultsControl.prototype, {
|
||||
value: {
|
||||
get: function () { return this._value || {}; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
PagedResultsControl.prototype.parse = function parse(buffer) {
|
||||
assert.ok(buffer);
|
||||
|
||||
var ber = new BerReader(buffer);
|
||||
if (ber.readSequence()) {
|
||||
this._value = {};
|
||||
this._value.size = ber.readInt();
|
||||
this._value.cookie = ber.readString(asn1.Ber.OctetString, true);
|
||||
//readString returns '' instead of a zero-length buffer
|
||||
if (!this._value.cookie)
|
||||
this._value.cookie = new Buffer(0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
PagedResultsControl.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
if (!this._value)
|
||||
return;
|
||||
|
||||
var writer = new BerWriter();
|
||||
writer.startSequence();
|
||||
writer.writeInt(this.value.size);
|
||||
if (this.value.cookie && this.value.cookie.length > 0) {
|
||||
writer.writeBuffer(this.value.cookie, asn1.Ber.OctetString);
|
||||
} else {
|
||||
writer.writeString(''); //writeBuffer rejects zero-length buffers
|
||||
}
|
||||
writer.endSequence();
|
||||
|
||||
ber.writeBuffer(writer.buffer, 0x04);
|
||||
};
|
||||
|
||||
PagedResultsControl.prototype._json = function (obj) {
|
||||
obj.controlValue = this.value;
|
||||
return obj;
|
||||
};
|
||||
|
||||
PagedResultsControl.OID = '1.2.840.113556.1.4.319';
|
||||
|
||||
|
||||
///--- Exports
|
||||
module.exports = PagedResultsControl;
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
||||
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var asn1 = require('asn1');
|
||||
|
||||
var Control = require('./control');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var BerReader = asn1.BerReader;
|
||||
var BerWriter = asn1.BerWriter;
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function PersistentSearchControl(options) {
|
||||
assert.optionalObject(options);
|
||||
options = options || {};
|
||||
options.type = PersistentSearchControl.OID;
|
||||
|
||||
if (options.value) {
|
||||
if (Buffer.isBuffer(options.value)) {
|
||||
this.parse(options.value);
|
||||
} else if (typeof (options.value) === 'object') {
|
||||
this._value = options.value;
|
||||
} else {
|
||||
throw new TypeError('options.value must be a Buffer or Object');
|
||||
}
|
||||
options.value = null;
|
||||
}
|
||||
Control.call(this, options);
|
||||
}
|
||||
util.inherits(PersistentSearchControl, Control);
|
||||
Object.defineProperties(PersistentSearchControl.prototype, {
|
||||
value: {
|
||||
get: function () { return this._value || {}; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
PersistentSearchControl.prototype.parse = function parse(buffer) {
|
||||
assert.ok(buffer);
|
||||
|
||||
var ber = new BerReader(buffer);
|
||||
if (ber.readSequence()) {
|
||||
this._value = {
|
||||
changeTypes: ber.readInt(),
|
||||
changesOnly: ber.readBoolean(),
|
||||
returnECs: ber.readBoolean()
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
PersistentSearchControl.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
if (!this._value)
|
||||
return;
|
||||
|
||||
var writer = new BerWriter();
|
||||
writer.startSequence();
|
||||
writer.writeInt(this.value.changeTypes);
|
||||
writer.writeBoolean(this.value.changesOnly);
|
||||
writer.writeBoolean(this.value.returnECs);
|
||||
writer.endSequence();
|
||||
|
||||
ber.writeBuffer(writer.buffer, 0x04);
|
||||
};
|
||||
|
||||
PersistentSearchControl.prototype._json = function (obj) {
|
||||
obj.controlValue = this.value;
|
||||
return obj;
|
||||
};
|
||||
|
||||
PersistentSearchControl.OID = '2.16.840.1.113730.3.4.3';
|
||||
|
||||
///--- Exports
|
||||
module.exports = PersistentSearchControl;
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var asn1 = require('asn1');
|
||||
|
||||
var Control = require('./control');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var BerReader = asn1.BerReader;
|
||||
var BerWriter = asn1.BerWriter;
|
||||
|
||||
|
||||
///--- API
|
||||
|
||||
function ServerSideSortingRequestControl(options) {
|
||||
assert.optionalObject(options);
|
||||
options = options || {};
|
||||
options.type = ServerSideSortingRequestControl.OID;
|
||||
if (options.value) {
|
||||
if (Buffer.isBuffer(options.value)) {
|
||||
this.parse(options.value);
|
||||
} else if (Array.isArray(options.value)) {
|
||||
assert.arrayOfObject(options.value, 'options.value must be Objects');
|
||||
for (var i = 0; i < options.value.length; i++) {
|
||||
if (!options.value[i].hasOwnProperty('attributeType')) {
|
||||
throw new Error('Missing required key: attributeType');
|
||||
}
|
||||
}
|
||||
this._value = options.value;
|
||||
} else if (typeof (options.value) === 'object') {
|
||||
if (!options.value.hasOwnProperty('attributeType')) {
|
||||
throw new Error('Missing required key: attributeType');
|
||||
}
|
||||
this._value = [options.value];
|
||||
} else {
|
||||
throw new TypeError('options.value must be a Buffer, Array or Object');
|
||||
}
|
||||
options.value = null;
|
||||
}
|
||||
Control.call(this, options);
|
||||
}
|
||||
util.inherits(ServerSideSortingRequestControl, Control);
|
||||
Object.defineProperties(ServerSideSortingRequestControl.prototype, {
|
||||
value: {
|
||||
get: function () { return this._value || []; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
ServerSideSortingRequestControl.prototype.parse = function parse(buffer) {
|
||||
assert.ok(buffer);
|
||||
|
||||
var ber = new BerReader(buffer);
|
||||
var item;
|
||||
if (ber.readSequence(0x30)) {
|
||||
this._value = [];
|
||||
|
||||
while (ber.readSequence(0x30)) {
|
||||
item = {};
|
||||
item.attributeType = ber.readString(asn1.Ber.OctetString);
|
||||
if (ber.peek() == 0x80) {
|
||||
item.orderingRule = ber.readString(0x80);
|
||||
}
|
||||
if (ber.peek() == 0x81) {
|
||||
item.reverseOrder = (ber._readTag(0x81) === 0 ? false : true);
|
||||
}
|
||||
this._value.push(item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
ServerSideSortingRequestControl.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
if (!this._value || this.value.length === 0)
|
||||
return;
|
||||
|
||||
var writer = new BerWriter();
|
||||
writer.startSequence(0x30);
|
||||
for (var i = 0; i < this.value.length; i++) {
|
||||
var item = this.value[i];
|
||||
writer.startSequence(0x30);
|
||||
if (item.attributeType) {
|
||||
writer.writeString(item.attributeType, asn1.Ber.OctetString);
|
||||
}
|
||||
if (item.orderingRule) {
|
||||
writer.writeString(item.orderingRule, 0x80);
|
||||
}
|
||||
if (item.reverseOrder) {
|
||||
writer.writeBoolean(item.reverseOrder, 0x81);
|
||||
}
|
||||
writer.endSequence();
|
||||
}
|
||||
writer.endSequence();
|
||||
ber.writeBuffer(writer.buffer, 0x04);
|
||||
};
|
||||
|
||||
ServerSideSortingRequestControl.prototype._json = function (obj) {
|
||||
obj.controlValue = this.value;
|
||||
return obj;
|
||||
};
|
||||
|
||||
ServerSideSortingRequestControl.OID = '1.2.840.113556.1.4.473';
|
||||
|
||||
|
||||
///---Exports
|
||||
|
||||
module.exports = ServerSideSortingRequestControl;
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
var assert = require('assert-plus');
|
||||
var util = require('util');
|
||||
|
||||
var asn1 = require('asn1');
|
||||
|
||||
var Control = require('./control');
|
||||
var CODES = require('../errors/codes');
|
||||
|
||||
|
||||
///--- Globals
|
||||
|
||||
var BerReader = asn1.BerReader;
|
||||
var BerWriter = asn1.BerWriter;
|
||||
|
||||
var VALID_CODES = [
|
||||
CODES.LDAP_SUCCESS,
|
||||
CODES.LDAP_OPERATIONS_ERROR,
|
||||
CODES.LDAP_TIME_LIMIT_EXCEEDED,
|
||||
CODES.LDAP_STRONG_AUTH_REQUIRED,
|
||||
CODES.LDAP_ADMIN_LIMIT_EXCEEDED,
|
||||
CODES.LDAP_NO_SUCH_ATTRIBUTE,
|
||||
CODES.LDAP_INAPPROPRIATE_MATCHING,
|
||||
CODES.LDAP_INSUFFICIENT_ACCESS_RIGHTS,
|
||||
CODES.LDAP_BUSY,
|
||||
CODES.LDAP_UNWILLING_TO_PERFORM,
|
||||
CODES.LDAP_OTHER
|
||||
];
|
||||
|
||||
function ServerSideSortingResponseControl(options) {
|
||||
assert.optionalObject(options);
|
||||
options = options || {};
|
||||
options.type = ServerSideSortingResponseControl.OID;
|
||||
options.criticality = false;
|
||||
|
||||
if (options.value) {
|
||||
if (Buffer.isBuffer(options.value)) {
|
||||
this.parse(options.value);
|
||||
} else if (typeof (options.value) === 'object') {
|
||||
if (VALID_CODES.indexOf(options.value.result) === -1) {
|
||||
throw new Error('Invalid result code');
|
||||
}
|
||||
if (options.value.failedAttribute &&
|
||||
typeof (options.value.failedAttribute) !== 'string') {
|
||||
throw new Error('failedAttribute must be String');
|
||||
}
|
||||
|
||||
this._value = options.value;
|
||||
} else {
|
||||
throw new TypeError('options.value must be a Buffer or Object');
|
||||
}
|
||||
options.value = null;
|
||||
}
|
||||
Control.call(this, options);
|
||||
}
|
||||
util.inherits(ServerSideSortingResponseControl, Control);
|
||||
Object.defineProperties(ServerSideSortingResponseControl.prototype, {
|
||||
value: {
|
||||
get: function () { return this._value || {}; },
|
||||
configurable: false
|
||||
}
|
||||
});
|
||||
|
||||
ServerSideSortingResponseControl.prototype.parse = function parse(buffer) {
|
||||
assert.ok(buffer);
|
||||
|
||||
var ber = new BerReader(buffer);
|
||||
if (ber.readSequence(0x30)) {
|
||||
this._value = {};
|
||||
this._value.result = ber.readEnumeration();
|
||||
if (ber.peek() == 0x80) {
|
||||
this._value.failedAttribute = ber.readString(0x80);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
ServerSideSortingResponseControl.prototype._toBer = function (ber) {
|
||||
assert.ok(ber);
|
||||
|
||||
if (!this._value || this.value.length === 0)
|
||||
return;
|
||||
|
||||
var writer = new BerWriter();
|
||||
writer.startSequence(0x30);
|
||||
writer.writeEnumeration(this.value.result);
|
||||
if (this.value.result !== CODES.LDAP_SUCCESS && this.value.failedAttribute) {
|
||||
writer.writeString(this.value.failedAttribute, 0x80);
|
||||
}
|
||||
writer.endSequence();
|
||||
ber.writeBuffer(writer.buffer, 0x04);
|
||||
};
|
||||
|
||||
ServerSideSortingResponseControl.prototype._json = function (obj) {
|
||||
obj.controlValue = this.value;
|
||||
return obj;
|
||||
};
|
||||
|
||||
ServerSideSortingResponseControl.OID = '1.2.840.113556.1.4.474';
|
||||
|
||||
|
||||
///--- Exports
|
||||
module.exports = ServerSideSortingResponseControl;
|
||||
Reference in New Issue
Block a user