Skip to content

Commit 4a2edb0

Browse files
committed
refactor(parser): streamline sequence handling and remove manual mapping logic
1 parent c5e77b6 commit 4a2edb0

File tree

1 file changed

+1
-77
lines changed

1 file changed

+1
-77
lines changed

packages/schema/src/parser.ts

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ export class AsnParser {
5555

5656
// Handle SEQUENCE types with special logic
5757
const sequenceResult = this.handleSequenceTypes(asn1Schema, schema, target, targetSchema);
58-
59-
// If manual mapping was used, return the result directly
60-
if (sequenceResult && "isManualMapping" in sequenceResult) {
61-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
62-
return (sequenceResult as any).result;
63-
}
64-
65-
const asn1ComparedSchema = sequenceResult;
66-
6758
const res = new target() as unknown as Record<string, unknown>;
6859

6960
// Handle array types
@@ -72,7 +63,7 @@ export class AsnParser {
7263
}
7364

7465
// Process schema items
75-
this.processSchemaItems(schema, asn1ComparedSchema, res);
66+
this.processSchemaItems(schema, sequenceResult, res);
7667

7768
return res;
7869
} catch (error) {
@@ -164,27 +155,6 @@ export class AsnParser {
164155
targetSchema: AsnSchemaType,
165156
): asn1js.CompareSchemaResult {
166157
if (schema.type === AsnTypeTypes.Sequence) {
167-
// Check for optional CHOICE fields
168-
const optionalChoiceFields = Object.keys(schema.items).filter((key) => {
169-
const item = schema.items[key];
170-
return (
171-
item.optional &&
172-
typeof item.type === "function" &&
173-
schemaStorage.has(item.type as IEmptyConstructor) &&
174-
schemaStorage.get(item.type as IEmptyConstructor).type === AsnTypeTypes.Choice
175-
);
176-
});
177-
178-
// Use manual mapping for specific problematic cases
179-
if (
180-
optionalChoiceFields.length > 0 &&
181-
"value" in asn1Schema.valueBlock &&
182-
Array.isArray(asn1Schema.valueBlock.value) &&
183-
target.name === "CertReqMsg"
184-
) {
185-
return this.handleManualMapping(asn1Schema, schema, target);
186-
}
187-
188158
// Try normal schema comparison
189159
const asn1ComparedSchema = asn1js.compareSchema(
190160
{} as unknown as asn1js.AsnType,
@@ -215,52 +185,6 @@ export class AsnParser {
215185
}
216186
}
217187

218-
/**
219-
* Handles manual mapping for SEQUENCE with optional CHOICE fields
220-
*/
221-
private static handleManualMapping(
222-
asn1Schema: asn1js.AsnType,
223-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
224-
schema: any,
225-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
226-
target: IEmptyConstructor<any>,
227-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
228-
): any {
229-
const res = new target() as unknown as Record<string, unknown>;
230-
const asn1Elements = (asn1Schema.valueBlock as { value: asn1js.AsnType[] }).value;
231-
const schemaKeys = Object.keys(schema.items);
232-
let asn1Index = 0;
233-
234-
for (let i = 0; i < schemaKeys.length; i++) {
235-
const key = schemaKeys[i];
236-
const schemaItem = schema.items[key];
237-
238-
if (asn1Index >= asn1Elements.length) break;
239-
240-
if (schemaItem.repeated) {
241-
res[key] = this.processRepeatedField(asn1Elements, asn1Index, schemaItem);
242-
break; // After repeated field, we're done
243-
} else if (typeof schemaItem.type === "number") {
244-
res[key] = this.processPrimitiveField(asn1Elements[asn1Index], schemaItem);
245-
asn1Index++;
246-
} else if (this.isOptionalChoiceField(schemaItem)) {
247-
const result = this.processOptionalChoiceField(asn1Elements[asn1Index], schemaItem);
248-
if (result.processed) {
249-
res[key] = result.value;
250-
asn1Index++;
251-
}
252-
// If not processed, skip this field and continue
253-
} else {
254-
res[key] = this.fromASN(asn1Elements[asn1Index], schemaItem.type as IEmptyConstructor);
255-
asn1Index++;
256-
}
257-
}
258-
259-
// Return a special result that indicates manual mapping was used
260-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
261-
return { result: res, verified: true, isManualMapping: true } as any;
262-
}
263-
264188
/**
265189
* Processes repeated fields in manual mapping
266190
*/

0 commit comments

Comments
 (0)