@@ -6,14 +6,16 @@ import AttributeTypeDictionary from "./AttributeTypeDictionary";
66/**
77 * Class from RFC5280
88 */
9- export default class AttributeTypeAndValue {
9+ export default class AttributeTypeAndValue
10+ {
1011 //**********************************************************************************
1112 /**
1213 * Constructor for AttributeTypeAndValue class
1314 * @param {Object } [parameters={}]
1415 * @param {Object } [parameters.schema] asn1js parsed value to initialize the class from
1516 */
16- constructor ( parameters = { } ) {
17+ constructor ( parameters = { } )
18+ {
1719 //region Internal properties of the object
1820 /**
1921 * @type {string }
@@ -28,7 +30,7 @@ export default class AttributeTypeAndValue {
2830 //endregion
2931
3032 //region If input argument array contains "schema" for this object
31- if ( "schema" in parameters )
33+ if ( "schema" in parameters )
3234 this . fromSchema ( parameters . schema ) ;
3335 //endregion
3436 }
@@ -37,8 +39,10 @@ export default class AttributeTypeAndValue {
3739 * Return default values for all class members
3840 * @param {string } memberName String name for a class member
3941 */
40- static defaultValues ( memberName ) {
41- switch ( memberName ) {
42+ static defaultValues ( memberName )
43+ {
44+ switch ( memberName )
45+ {
4246 case "type" :
4347 return "" ;
4448 case "value" :
@@ -65,7 +69,8 @@ export default class AttributeTypeAndValue {
6569 * @param {Object } parameters Input parameters for the schema
6670 * @returns {Object } asn1js schema object
6771 */
68- static schema ( parameters = { } ) {
72+ static schema ( parameters = { } )
73+ {
6974 /**
7075 * @type {Object }
7176 * @property {string } [blockName] Name for entire block
@@ -83,15 +88,17 @@ export default class AttributeTypeAndValue {
8388 } ) ) ;
8489 }
8590 //**********************************************************************************
86- static blockName ( ) {
91+ static blockName ( )
92+ {
8793 return "AttributeTypeAndValue" ;
8894 }
8995 //**********************************************************************************
9096 /**
9197 * Convert parsed asn1js object into current class
9298 * @param {!Object } schema
9399 */
94- fromSchema ( schema ) {
100+ fromSchema ( schema )
101+ {
95102 //region Clear input data first
96103 clearProps ( schema , [
97104 "type" ,
@@ -110,7 +117,7 @@ export default class AttributeTypeAndValue {
110117 } )
111118 ) ;
112119
113- if ( asn1 . verified === false )
120+ if ( asn1 . verified === false )
114121 throw new Error ( "Object's schema was not verified against input data for AttributeTypeAndValue" ) ;
115122 //endregion
116123
@@ -125,7 +132,8 @@ export default class AttributeTypeAndValue {
125132 * Convert current object to asn1js object and set correct values
126133 * @returns {Object } asn1js object
127134 */
128- toSchema ( ) {
135+ toSchema ( )
136+ {
129137 //region Construct and return new ASN.1 schema for this object
130138 return ( new asn1js . Sequence ( {
131139 value : [
@@ -140,12 +148,13 @@ export default class AttributeTypeAndValue {
140148 * Convertion for the class to JSON object
141149 * @returns {Object }
142150 */
143- toJSON ( ) {
151+ toJSON ( )
152+ {
144153 const _object = {
145154 type : this . type
146155 } ;
147156
148- if ( Object . keys ( this . value ) . length !== 0 )
157+ if ( Object . keys ( this . value ) . length !== 0 )
149158 _object . value = this . value . toJSON ( ) ;
150159 else
151160 _object . value = this . value ;
@@ -158,7 +167,8 @@ export default class AttributeTypeAndValue {
158167 * @param {(AttributeTypeAndValue|ArrayBuffer) } compareTo The value compare to current
159168 * @returns {boolean }
160169 */
161- isEqual ( compareTo ) {
170+ isEqual ( compareTo )
171+ {
162172 const stringBlockNames = [
163173 asn1js . Utf8String . blockName ( ) ,
164174 asn1js . BmpString . blockName ( ) ,
@@ -174,63 +184,71 @@ export default class AttributeTypeAndValue {
174184 asn1js . CharacterString . blockName ( )
175185 ] ;
176186
177- if ( compareTo . constructor . blockName ( ) === AttributeTypeAndValue . blockName ( ) ) {
178- if ( this . type !== compareTo . type )
187+ if ( compareTo . constructor . blockName ( ) === AttributeTypeAndValue . blockName ( ) )
188+ {
189+ if ( this . type !== compareTo . type )
179190 return false ;
180191
181192 //region Check we do have both strings
182193 let isString = [ false , false ] ;
183194 const thisName = this . value . constructor . blockName ( ) ;
184- for ( const name of stringBlockNames ) {
185- if ( thisName === name ) {
195+ for ( const name of stringBlockNames )
196+ {
197+ if ( thisName === name )
198+ {
186199 isString [ 0 ] = true ;
187200 }
188- if ( compareTo . value . constructor . blockName ( ) === name ) {
201+ if ( compareTo . value . constructor . blockName ( ) === name )
202+ {
189203 isString [ 1 ] = true ;
190204 }
191205 }
192- if ( isString [ 0 ] ^ isString [ 1 ] )
206+ if ( isString [ 0 ] ^ isString [ 1 ] )
193207 return false ;
194208
195209 isString = ( isString [ 0 ] && isString [ 1 ] ) ;
196210 //endregion
197211
198- if ( isString ) {
212+ if ( isString )
213+ {
199214 const value1 = stringPrep ( this . value . valueBlock . value ) ;
200215 const value2 = stringPrep ( compareTo . value . valueBlock . value ) ;
201216
202- if ( value1 . localeCompare ( value2 ) !== 0 )
217+ if ( value1 . localeCompare ( value2 ) !== 0 )
203218 return false ;
204219 }
205220 else // Comparing as two ArrayBuffers
206221 {
207- if ( isEqualBuffer ( this . value . valueBeforeDecode , compareTo . value . valueBeforeDecode ) === false )
222+ if ( isEqualBuffer ( this . value . valueBeforeDecode , compareTo . value . valueBeforeDecode ) === false )
208223 return false ;
209224 }
210225
211226 return true ;
212227 }
213228
214- if ( compareTo instanceof ArrayBuffer )
229+ if ( compareTo instanceof ArrayBuffer )
215230 return isEqualBuffer ( this . value . valueBeforeDecode , compareTo ) ;
216231
217232 return false ;
218233 }
219234 //**********************************************************************************
220235 /**
221236 * Convert an AttributeTypeAndValue to a human-readable string
222- * based on RFC4514, with escaping charaters
237+ * based on RFC4514, with escaping characters
223238 * @returns {string }
224239 */
225- toString ( ) {
240+ toString ( )
241+ {
226242 let value = this . value . valueBlock . value ;
227243
228244 value = value . replace ( / ( [ " + , ; < > \\ = ] ) / g, "\\$1" ) ;
229245
230- if ( value . startsWith ( " " ) || value . startsWith ( "#" ) ) {
246+ if ( value . startsWith ( " " ) || value . startsWith ( "#" ) )
247+ {
231248 value = "\\" + value ;
232249 }
233- if ( value . endsWith ( " " ) ) {
250+ if ( value . endsWith ( " " ) )
251+ {
234252 value = value . substring ( 0 , value . length - 1 ) + "\\" + value . substring ( value . length - 1 ) ;
235253 }
236254
0 commit comments