55import {
66 TextConverter , TextObject , TextObjectConvertible ,
77} from "./text_converter" ;
8+ import { ParseOptions } from "./types" ;
89
910export type AsnDataStringFormat = "asn" | "text" | "hex" | "base64" | "base64url" ;
1011
@@ -16,6 +17,18 @@ export abstract class AsnData<T> implements TextObjectConvertible {
1617
1718 #rawData! : ArrayBuffer ;
1819
20+ /**
21+ * ASN.1 parse options
22+ */
23+ #options?: ParseOptions ;
24+
25+ /**
26+ * Gets the ASN.1 parse options the instance was created with
27+ */
28+ protected get parseOptions ( ) : ParseOptions | undefined {
29+ return this . #options;
30+ }
31+
1932 /**
2033 * Gets a DER encoded buffer
2134 */
@@ -37,16 +50,17 @@ export abstract class AsnData<T> implements TextObjectConvertible {
3750 * @param raw DER encoded buffer
3851 * @param type ASN.1 convertible class for `@peculiar/asn1-schema` schema
3952 */
40- public constructor ( raw : BufferSource , type : new ( ) => T ) ;
53+ public constructor ( raw : BufferSource , type : new ( ) => T , options ?: ParseOptions ) ;
4154 /**
4255 * ASN.1 object
4356 * @param asn
4457 */
4558 public constructor ( asn : T ) ;
4659 public constructor ( ...args : any [ ] ) {
4760 if ( BufferSourceConverter . isBufferSource ( args [ 0 ] ) ) {
48- // raw, type
49- this . asn = AsnConvert . parse < T > ( args [ 0 ] , args [ 1 ] ) ;
61+ // raw, type, options?
62+ this . #options = args [ 2 ] ;
63+ this . asn = AsnConvert . parse < T > ( args [ 0 ] , args [ 1 ] , args [ 2 ] ) ;
5064 this . #rawData = BufferSourceConverter . toArrayBuffer ( args [ 0 ] ) ;
5165 this . onInit ( this . asn ) ;
5266 } else {
@@ -77,7 +91,7 @@ export abstract class AsnData<T> implements TextObjectConvertible {
7791 public toString ( format : AsnDataStringFormat = "text" ) : string {
7892 switch ( format ) {
7993 case "asn" :
80- return AsnConvert . toString ( this . rawData ) ;
94+ return AsnConvert . toString ( this . rawData , this . #options ) ;
8195 case "text" :
8296 return TextConverter . serialize ( this . toTextObject ( ) ) ;
8397 case "hex" :
0 commit comments