@@ -22,28 +22,15 @@ const length_1 = require("./length");
22
22
const parse_1 = require ( "./parse" ) ;
23
23
const tag_1 = require ( "./tag" ) ;
24
24
class ASN1Obj {
25
- constructor ( tag , headerLength , buf , subs ) {
25
+ constructor ( tag , value , subs ) {
26
26
this . tag = tag ;
27
- this . headerLength = headerLength ;
28
- this . buf = buf ;
27
+ this . value = value ;
29
28
this . subs = subs ;
30
29
}
31
30
// Constructs an ASN.1 object from a Buffer of DER-encoded bytes.
32
31
static parseBuffer ( buf ) {
33
32
return parseStream ( new stream_1 . ByteStream ( buf ) ) ;
34
33
}
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
- }
47
34
toDER ( ) {
48
35
const valueStream = new stream_1 . ByteStream ( ) ;
49
36
if ( this . subs . length > 0 ) {
@@ -114,13 +101,11 @@ exports.ASN1Obj = ASN1Obj;
114
101
/////////////////////////////////////////////////////////////////////////////
115
102
// Internal stream parsing functions
116
103
function 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
120
105
const tag = new tag_1 . ASN1Tag ( stream . getUint8 ( ) ) ;
121
106
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 ;
124
109
let subs = [ ] ;
125
110
// If the object is constructed, parse its children. Sometimes, children
126
111
// are embedded in OCTESTRING objects, so we need to check those
@@ -140,11 +125,9 @@ function parseStream(stream) {
140
125
}
141
126
// If there are no children, move stream cursor to the end of the object
142
127
if ( subs . length === 0 ) {
143
- stream . seek ( startPos + header + len ) ;
128
+ stream . seek ( start + len ) ;
144
129
}
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 ) ;
148
131
}
149
132
function collectSubs ( stream , len ) {
150
133
// Calculate end of object content
0 commit comments