From 67a32a8294397b6b958864a23e1d019441466478 Mon Sep 17 00:00:00 2001 From: Ksenia Lebedeva Date: Mon, 19 Jun 2023 16:59:09 +0200 Subject: [PATCH] lot identifier update --- index.html | 4 ++-- src/card.ts | 12 ++++++------ src/ident.ts | 2 +- src/utils.ts | 7 +++++++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index 4886495..e6024f8 100644 --- a/index.html +++ b/index.html @@ -16,8 +16,8 @@
- - + +
diff --git a/src/card.ts b/src/card.ts index cbe5e57..84480ab 100644 --- a/src/card.ts +++ b/src/card.ts @@ -1,6 +1,6 @@ import Keycard from "keycard-sdk" import { WebContents } from "electron"; -import { ipcMain, dialog } from "electron" +import { ipcMain, dialog } from "electron"; import { SessionInfo } from "./session-info"; import { Utils } from "./utils"; import { Pairing } from "keycard-sdk/dist/pairing"; @@ -193,8 +193,7 @@ export class Card { for (let i = 0; i < cards; i++) { let certificate = Certificate.generateNewCertificate(caKey); let certData = certificate.toStoreData(); - let num = Utils.formatNumtoString(i); - let cardID = lot + num; + let cardID = lot + '-' + Utils.uint20ToBase32(i); let certDataString = dataHeader + Buffer.from(certData).toString('hex'); let line = cardID + "," + certDataString + "\n"; encData += line; @@ -210,11 +209,12 @@ export class Card { this.window.send("certificate-creation-success"); } - openDestinationDialog(): void { + openDestinationDialog(lot: string): void { + let fileName = lot ? lot + '.csv.asc' : 'certificates.csv.asc'; let options = { title: 'Select the destination path to save the processed file', buttonLabel: "Choose", - defaultPath: path.join(__dirname, 'certificates.csv.asc'), + defaultPath: path.join(__dirname, fileName), filters: [ { name: 'ASC Files', @@ -296,6 +296,6 @@ export class Card { ipcMain.on("verify-pin", this.withErrorHandler(this.verifyPIN)); ipcMain.on("verify-puk", this.withErrorHandler(this.verifyPUK)); ipcMain.on("start-ident", this.withErrorHandler(this.identCert)); - ipcMain.on("open-destination-folder-dialog", (_) => this.openDestinationDialog()); + ipcMain.on("open-destination-folder-dialog", (_, lot) => this.openDestinationDialog(lot)); } } \ No newline at end of file diff --git a/src/ident.ts b/src/ident.ts index b6bc53e..cd99e3a 100644 --- a/src/ident.ts +++ b/src/ident.ts @@ -31,7 +31,7 @@ export namespace Ident { }); destinationPathBtn.addEventListener("click", (e) => { - ipcRenderer.send("open-destination-folder-dialog"); + ipcRenderer.send("open-destination-folder-dialog", lot.value); }); ipcRenderer.on("verification-success", (_) => { diff --git a/src/utils.ts b/src/utils.ts index 981656f..749a67a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,6 @@ export namespace Utils { const numStrLength = 6; + const RFC4648 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'; export function hx(arr: Uint8Array): string { return Buffer.from(arr).toString('hex'); @@ -23,4 +24,10 @@ export namespace Utils { return res; } + + + + export function uint20ToBase32(num: number): string { + return RFC4648.charAt((num >> 15) & 0x1F) + RFC4648.charAt((num >> 10) & 0x1F) + RFC4648.charAt((num >> 5) & 0x1F) + RFC4648.charAt(num & 0x1F) + } } \ No newline at end of file