node-ldapjs/lib/controls/control.js

69 lines
1.4 KiB
JavaScript
Raw Normal View History

2011-08-04 20:32:01 +00:00
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert-plus');
2011-08-04 20:32:01 +00:00
var util = require('util');
var asn1 = require('asn1');
var Protocol = require('../protocol');
2011-08-04 20:32:01 +00:00
2011-08-04 20:32:01 +00:00
///--- Globals
2011-08-04 20:32:01 +00:00
var Ber = asn1.Ber;
2011-08-04 20:32:01 +00:00
///--- API
function Control(options) {
assert.optionalObject(options);
options = options || {};
assert.optionalString(options.type);
assert.optionalBool(options.criticality);
if (options.value) {
console.log(assert.buffer.toString());
assert.buffer(options.value);
2011-08-04 20:32:01 +00:00
}
this.type = options.type || '';
this.criticality = options.critical || options.criticality || false;
this.value = options.value || null;
2011-08-04 20:32:01 +00:00
}
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);
}
}
});
2011-08-04 20:32:01 +00:00
Control.prototype.toBer = function toBer(ber) {
2011-09-16 16:06:07 +00:00
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);
}
2011-09-16 16:06:07 +00:00
ber.endSequence();
return;
};
Control.prototype.toString = function toString() {
return this.json;
2011-09-16 16:06:07 +00:00
};
///--- Exports
module.exports = Control;