summaryrefslogtreecommitdiffstats
path: root/third_party/js/PKI.js/src/SafeBagValueFactory.ts
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /third_party/js/PKI.js/src/SafeBagValueFactory.ts
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/js/PKI.js/src/SafeBagValueFactory.ts')
-rw-r--r--third_party/js/PKI.js/src/SafeBagValueFactory.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/third_party/js/PKI.js/src/SafeBagValueFactory.ts b/third_party/js/PKI.js/src/SafeBagValueFactory.ts
new file mode 100644
index 0000000000..3bbfe558bc
--- /dev/null
+++ b/third_party/js/PKI.js/src/SafeBagValueFactory.ts
@@ -0,0 +1,41 @@
+export type BagType = PrivateKeyInfo | PKCS8ShroudedKeyBag | CertBag | CRLBag | SecretBag | SafeContents;
+export type BagTypeJson = PrivateKeyInfoJson | JsonWebKey | PKCS8ShroudedKeyBagJson | CertBagJson | CRLBagJson | SecretBagJson | SafeContentsJson;
+
+export interface BagTypeConstructor<T extends BagType> {
+ new(params: { schema: any; }): T;
+}
+
+export class SafeBagValueFactory {
+ private static items?: Record<string, BagTypeConstructor<BagType>>;
+
+ private static getItems(): Record<string, BagTypeConstructor<BagType>> {
+ if (!this.items) {
+ this.items = {};
+
+ SafeBagValueFactory.register("1.2.840.113549.1.12.10.1.1", PrivateKeyInfo);
+ SafeBagValueFactory.register("1.2.840.113549.1.12.10.1.2", PKCS8ShroudedKeyBag);
+ SafeBagValueFactory.register("1.2.840.113549.1.12.10.1.3", CertBag);
+ SafeBagValueFactory.register("1.2.840.113549.1.12.10.1.4", CRLBag);
+ SafeBagValueFactory.register("1.2.840.113549.1.12.10.1.5", SecretBag);
+ SafeBagValueFactory.register("1.2.840.113549.1.12.10.1.6", SafeContents);
+ }
+
+ return this.items;
+ }
+ public static register<T extends BagType = BagType>(id: string, type: BagTypeConstructor<T>): void {
+ this.getItems()[id] = type;
+ }
+
+ public static find(id: string): BagTypeConstructor<BagType> | null {
+ return this.getItems()[id] || null;
+ }
+
+}
+
+//! NOTE Bag type must be imported after the SafeBagValueFactory declaration
+import { CertBag, CertBagJson } from "./CertBag";
+import { CRLBag, CRLBagJson } from "./CRLBag";
+import { PKCS8ShroudedKeyBag, PKCS8ShroudedKeyBagJson } from "./PKCS8ShroudedKeyBag";
+import { PrivateKeyInfo, PrivateKeyInfoJson } from "./PrivateKeyInfo";
+import { SafeContents, SafeContentsJson } from "./SafeContents";
+import { SecretBag, SecretBagJson } from "./SecretBag"; \ No newline at end of file