AsnError.ts (742B)
1 export interface AsnFromBerResult { 2 offset: number; 3 result: any; 4 } 5 6 export interface AsnCompareSchemaResult { 7 verified: boolean; 8 result?: any; 9 } 10 11 export class AsnError extends Error { 12 13 static assertSchema(asn1: AsnCompareSchemaResult, target: string): asserts asn1 is { verified: true, result: any; } { 14 if (!asn1.verified) { 15 throw new Error(`Object's schema was not verified against input data for ${target}`); 16 } 17 } 18 19 public static assert(asn: AsnFromBerResult, target: string): void { 20 if (asn.offset === -1) { 21 throw new AsnError(`Error during parsing of ASN.1 data. Data is not correct for '${target}'.`); 22 } 23 } 24 25 constructor(message: string) { 26 super(message); 27 28 this.name = "AsnError"; 29 } 30 31 }