2 * Copyright (c) 2014-2015 Sylvain Peyrefitte
4 * This file is part of node-rdpjs.
6 * node-rdpjs is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20var inherits = require('util').inherits;
21var type = require('../core').type;
22var error = require('../core').error;
44 * @param tagClass {TagClass}
45 * @param tagFormat {TagFormat}
46 * @param tagNumber {integer}
48function Asn1Tag(tagClass, tagFormat, tagNumber) {
49 this.tagClass = tagClass;
50 this.tagFormat = tagFormat;
51 this.tagNumber = tagNumber;
56 * @param tag {Asn1Tag}
58function Asn1Spec(tag) {
66 * @param tag {Asn1Tag}
69Asn1Spec.prototype.implicitTag = function(tag) {
75 * Set optional to true
78Asn1Spec.prototype.optional = function() {
85 * Append new tag header to existing tag
86 * @param tag {Asn1Tag}
87 * @returns {Asn1SpecExplicitTag}
89Asn1Spec.prototype.explicitTag = function(tag) {
90 return new Asn1SpecExplicitTag(tag, this);
94 * Decode must be implemented by all sub type
95 * @param s {type.Stream}
98Asn1Spec.prototype.decode = function(s, decoder) {
99 throw new error.FatalError('NODE_RDP_AS1_SPEC_DECODE_NOT_IMPLEMENTED');
103 * Encode must be implemented by all sub type
106Asn1Spec.prototype.encode = function(encoder) {
107 throw new error.FatalError('NODE_RDP_AS1_SPEC_ENCODE_NOT_IMPLEMENTED');
111 * Component Asn1Spec object
113function Asn1SpecExplicitTag(tag, spec) {
114 Asn1Spec.call(this, tag);
118inherits(Asn1SpecExplicitTag, Asn1Spec);
121 * Decode first header
122 * @param s {type.Stream}
125Asn1Spec.prototype.decode = function(s, decoder) {
126 var specStream = new type.Stream(decoder.decode(s, this.tag).value);
127 this.spec.decode(specStream, decoder);
135 TagFormat : TagFormat,
138 Asn1SpecExplicitTag : Asn1SpecExplicitTag