diff --git a/lib/filters/ext_filter.js b/lib/filters/ext_filter.js index 8de19cf..8f84031 100644 --- a/lib/filters/ext_filter.js +++ b/lib/filters/ext_filter.js @@ -82,12 +82,49 @@ ExtensibleFilter.prototype.matches = function(target) { if (typeof(target) !== 'object') throw new TypeError('target (object) required'); + if (this.dnAttribute) + throw new Error('ExtensibleMatch dnAttributes not supported'); + + if (!this.value) + return false; + + var self = this; + if (this.matchType && target.hasOwnProperty(this.matchType)) { + return Filter.multi_test(function(v) { + if (self.rule === '2.5.13.2') + return self.value.toLowerCase() === v.toLowerCase(); + + return self.value === v; + }, target[this.matchType]); + } + return false; }; ExtensibleFilter.prototype.parse = function(ber) { - throw new Error('ExtensibleFilter not supported'); + var end = ber.offset + ber.length; + while (ber.offset < end) { + var tag = ber.peek(); + switch (tag) { + case 0x81: + this.rule = ber.readString(tag); + break; + case 0x82: + this.matchType = ber.readString(tag); + break; + case 0x83: + this.value = ber.readString(tag); + break; + case 0x84: + this.dnAttributes = ber.readBoolean(tag); + break; + default: + throw new Error('Invalid ext_match filter type: 0x' + tag.toString(16)); + } + } + + return true; };