summaryrefslogtreecommitdiffstats
path: root/third_party/js/PKI.js/src/errors/AsnError.ts
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/js/PKI.js/src/errors/AsnError.ts')
-rw-r--r--third_party/js/PKI.js/src/errors/AsnError.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/third_party/js/PKI.js/src/errors/AsnError.ts b/third_party/js/PKI.js/src/errors/AsnError.ts
new file mode 100644
index 0000000000..60f159695b
--- /dev/null
+++ b/third_party/js/PKI.js/src/errors/AsnError.ts
@@ -0,0 +1,31 @@
+export interface AsnFromBerResult {
+ offset: number;
+ result: any;
+}
+
+export interface AsnCompareSchemaResult {
+ verified: boolean;
+ result?: any;
+}
+
+export class AsnError extends Error {
+
+ static assertSchema(asn1: AsnCompareSchemaResult, target: string): asserts asn1 is { verified: true, result: any; } {
+ if (!asn1.verified) {
+ throw new Error(`Object's schema was not verified against input data for ${target}`);
+ }
+ }
+
+ public static assert(asn: AsnFromBerResult, target: string): void {
+ if (asn.offset === -1) {
+ throw new AsnError(`Error during parsing of ASN.1 data. Data is not correct for '${target}'.`);
+ }
+ }
+
+ constructor(message: string) {
+ super(message);
+
+ this.name = "AsnError";
+ }
+
+} \ No newline at end of file