@@ -101,6 +101,12 @@ Writer.prototype.writeInt = function(i, tag) {
101
101
} ;
102
102
103
103
104
+ Writer . prototype . writeNull = function ( ) {
105
+ this . writeByte ( ASN1 . Null ) ;
106
+ this . writeByte ( 0x00 ) ;
107
+ } ;
108
+
109
+
104
110
Writer . prototype . writeEnumeration = function ( i , tag ) {
105
111
if ( typeof ( i ) !== 'number' )
106
112
throw new TypeError ( 'argument must be a Number' ) ;
@@ -151,6 +157,50 @@ Writer.prototype.writeStringArray = function(strings) {
151
157
} ) ;
152
158
} ;
153
159
160
+ // This is really to solve DER cases, but whatever for now
161
+ Writer . prototype . writeOID = function ( s , tag ) {
162
+ if ( typeof ( s ) !== 'string' )
163
+ throw new TypeError ( 'argument must be a string' ) ;
164
+ if ( typeof ( tag ) !== 'number' )
165
+ tag = ASN1 . OID ;
166
+
167
+ if ( ! / ^ ( [ 0 - 9 ] + \. ) { 3 , } [ 0 - 9 ] + $ / . test ( s ) )
168
+ throw new Error ( 'argument is not a valid OID string' ) ;
169
+
170
+ function encodeOctet ( bytes , octet ) {
171
+ if ( octet < 128 ) {
172
+ bytes . push ( octet ) ;
173
+ } else if ( octet < 16384 ) {
174
+ bytes . push ( ( octet >>> 7 ) | 0x80 ) ;
175
+ bytes . push ( octet & 0x7F ) ;
176
+ } else if ( octet < 2097152 ) {
177
+ bytes . push ( ( octet >>> 14 ) | 0x80 ) ;
178
+ bytes . push ( ( ( octet >>> 7 ) | 0x80 ) & 0xFF ) ;
179
+ bytes . push ( octet & 0x7F ) ;
180
+ } else if ( id < 268435456 ) {
181
+ bytes . push ( ( octet >>> 21 ) | 0x80 ) ;
182
+ bytes . push ( ( ( octet >>> 14 ) | 0x80 ) & 0xFF ) ;
183
+ bytes . push ( ( ( octet >>> 7 ) | 0x80 ) & 0xFF ) ;
184
+ bytes . push ( octet & 0x7F ) ;
185
+ }
186
+ }
187
+
188
+ var tmp = s . split ( '.' ) ;
189
+ var bytes = [ ] ;
190
+ bytes . push ( parseInt ( tmp [ 0 ] , 10 ) * 40 + parseInt ( tmp [ 1 ] , 10 ) ) ;
191
+ tmp . slice ( 2 ) . forEach ( function ( b ) {
192
+ encodeOctet ( bytes , parseInt ( b , 10 ) ) ;
193
+ } ) ;
194
+
195
+ var self = this ;
196
+ this . _ensure ( 2 + bytes . length ) ;
197
+ this . writeByte ( tag ) ;
198
+ this . writeLength ( bytes . length ) ;
199
+ bytes . forEach ( function ( b ) {
200
+ self . writeByte ( b ) ;
201
+ } ) ;
202
+ } ;
203
+
154
204
155
205
Writer . prototype . writeLength = function ( len ) {
156
206
if ( typeof ( len ) !== 'number' )
@@ -212,7 +262,7 @@ Writer.prototype.endSequence = function() {
212
262
this . _buf [ seq + 2 ] = len >> 8 ;
213
263
this . _buf [ seq + 3 ] = len ;
214
264
} else {
215
- throw newInvalidAsn1ERror ( 'Sequence too long' ) ;
265
+ throw newInvalidAsn1Error ( 'Sequence too long' ) ;
216
266
}
217
267
} ;
218
268
0 commit comments