lot identifier update

This commit is contained in:
Ksenia Lebedeva 2023-06-19 16:59:09 +02:00
parent 2ccc5223ea
commit 67a32a8294
4 changed files with 16 additions and 9 deletions

View File

@ -16,8 +16,8 @@
<div class="keycard-ident__form-container" id="ident-form">
<div class="keycard-ident__form">
<div class="keycard-ident__form-field-container group">
<label for="lot-number" class="keycard-ident__form-field-label">Lot number</label>
<input type="text" class="keycard-ident__form-field-input-text keycard__inp-right" id="lot-number" name="lot-number" placeholder="Lot number" required>
<label for="lot-number" class="keycard-ident__form-field-label">Version &amp; lot identifier</label>
<input type="text" class="keycard-ident__form-field-input-text keycard__inp-right" id="lot-number" name="lot-number" placeholder="V2XX" required>
</div>
<div class="keycard-ident__form-field-container group">
<label for="card-quantity" class="keycard-ident__form-field-label">Number of cards</label>

View File

@ -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));
}
}

View File

@ -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", (_) => {

View File

@ -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)
}
}