@@ -22,28 +22,15 @@ const length_1 = require("./length");
2222const parse_1 = require ( "./parse" ) ;
2323const tag_1 = require ( "./tag" ) ;
2424class ASN1Obj {
25- constructor ( tag , headerLength , buf , subs ) {
25+ constructor ( tag , value , subs ) {
2626 this . tag = tag ;
27- this . headerLength = headerLength ;
28- this . buf = buf ;
27+ this . value = value ;
2928 this . subs = subs ;
3029 }
3130 // Constructs an ASN.1 object from a Buffer of DER-encoded bytes.
3231 static parseBuffer ( buf ) {
3332 return parseStream ( new stream_1 . ByteStream ( buf ) ) ;
3433 }
35- // Returns the raw bytes of the ASN.1 object's value. For constructed objects,
36- // this is the concatenation of the raw bytes of the values of its children.
37- // For primitive objects, this is the raw bytes of the object's value.
38- // Use the various to* methods to parse the value into a specific type.
39- get value ( ) {
40- return this . buf . subarray ( this . headerLength ) ;
41- }
42- // Returns the raw bytes of the entire ASN.1 object (including tag, length,
43- // and value)
44- get raw ( ) {
45- return this . buf ;
46- }
4734 toDER ( ) {
4835 const valueStream = new stream_1 . ByteStream ( ) ;
4936 if ( this . subs . length > 0 ) {
@@ -114,13 +101,11 @@ exports.ASN1Obj = ASN1Obj;
114101/////////////////////////////////////////////////////////////////////////////
115102// Internal stream parsing functions
116103function parseStream ( stream ) {
117- // Capture current stream position so we know where this object starts
118- const startPos = stream . position ;
119- // Parse tag and length from stream
104+ // Parse tag, length, and value from stream
120105 const tag = new tag_1 . ASN1Tag ( stream . getUint8 ( ) ) ;
121106 const len = ( 0 , length_1 . decodeLength ) ( stream ) ;
122- // Calculate length of header (tag + length)
123- const header = stream . position - startPos ;
107+ const value = stream . slice ( stream . position , len ) ;
108+ const start = stream . position ;
124109 let subs = [ ] ;
125110 // If the object is constructed, parse its children. Sometimes, children
126111 // are embedded in OCTESTRING objects, so we need to check those
@@ -140,11 +125,9 @@ function parseStream(stream) {
140125 }
141126 // If there are no children, move stream cursor to the end of the object
142127 if ( subs . length === 0 ) {
143- stream . seek ( startPos + header + len ) ;
128+ stream . seek ( start + len ) ;
144129 }
145- // Capture the raw bytes of the object (including tag, length, and value)
146- const buf = stream . slice ( startPos , header + len ) ;
147- return new ASN1Obj ( tag , header , buf , subs ) ;
130+ return new ASN1Obj ( tag , value , subs ) ;
148131}
149132function collectSubs ( stream , len ) {
150133 // Calculate end of object content
0 commit comments