2011-12-08 22:54:40 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2011-12-08 19:22:35 +00:00
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
var Control = require('./control');
|
|
|
|
var PersistentSearchControl = require('./persistent_search_control');
|
|
|
|
|
2011-12-08 22:54:40 +00:00
|
|
|
|
2011-12-08 19:22:35 +00:00
|
|
|
|
|
|
|
///--- API
|
|
|
|
|
|
|
|
module.exports = {
|
2011-12-08 22:54:40 +00:00
|
|
|
|
|
|
|
getControl: function getControl(ber) {
|
2011-12-08 19:22:35 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
|
|
|
if (ber.readSequence() === null)
|
2011-12-08 22:54:40 +00:00
|
|
|
return null;
|
|
|
|
|
|
|
|
var type;
|
|
|
|
var critical = false;
|
|
|
|
var value;
|
2011-12-08 19:22:35 +00:00
|
|
|
|
|
|
|
if (ber.length) {
|
2011-12-08 22:54:40 +00:00
|
|
|
var end = ber.offset + ber.length;
|
|
|
|
|
|
|
|
type = ber.readString();
|
2011-12-08 19:22:35 +00:00
|
|
|
if (ber.offset < end) {
|
2011-12-08 22:54:40 +00:00
|
|
|
if (ber.peek() === 0x01)
|
|
|
|
critical = ber.readBoolean();
|
2011-12-08 19:22:35 +00:00
|
|
|
}
|
2011-12-08 22:54:40 +00:00
|
|
|
|
|
|
|
if (ber.offset < end)
|
|
|
|
value = ber.readString(0x04, true);
|
2011-12-08 19:22:35 +00:00
|
|
|
}
|
2011-12-08 22:54:40 +00:00
|
|
|
|
|
|
|
var control;
|
|
|
|
switch (type) {
|
|
|
|
case PersistentSearchControl.OID:
|
|
|
|
control = new PersistentSearchControl({
|
|
|
|
critical: critical,
|
|
|
|
value: value
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
control = new Control({
|
|
|
|
type: type,
|
|
|
|
critical: critical,
|
|
|
|
value: value.toString('utf8')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return control;
|
2011-12-08 19:22:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Control: Control,
|
|
|
|
PersistentSearchControl: PersistentSearchControl
|
|
|
|
};
|