From 2c7bad8e76b52facf3080fd1fef1c414d96c6c93 Mon Sep 17 00:00:00 2001 From: Robin Sandhu Date: Sun, 25 Aug 2024 05:44:45 +0100 Subject: [PATCH] Add support multiple input format i.e. DER Hex, Base64, Raw --- src/core/operations/ParseX509CRL.mjs | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/core/operations/ParseX509CRL.mjs b/src/core/operations/ParseX509CRL.mjs index aa0842825..91509ff14 100644 --- a/src/core/operations/ParseX509CRL.mjs +++ b/src/core/operations/ParseX509CRL.mjs @@ -6,8 +6,11 @@ import r from "jsrsasign"; import Operation from "../Operation.mjs"; +import { fromBase64 } from "../lib/Base64.mjs"; +import { toHex } from "../lib/Hex.mjs"; import { formatDnObj } from "../lib/PublicKey.mjs"; import OperationError from "../errors/OperationError.mjs"; +import Utils from "../Utils.mjs"; /** * Parse X.509 CRL operation @@ -30,7 +33,7 @@ class ParseX509CRL extends Operation { { "name": "Input format", "type": "option", - "value": ["PEM"] + "value": ["PEM", "DER Hex", "Base64", "Raw"] } ]; this.checks = [ @@ -52,6 +55,32 @@ class ParseX509CRL extends Operation { return "No input"; } + const inputFormat = args[0]; + + let undefinedInputFormat = false; + try { + switch (inputFormat) { + case "DER Hex": + input = input.replace(/\s/g, "").toLowerCase(); + break; + case "PEM": + break; + case "Base64": + input = toHex(fromBase64(input, null, "byteArray"), ""); + break; + case "Raw": + input = toHex(Utils.strToArrayBuffer(input), ""); + break; + default: + undefinedInputFormat = true; + } + } catch (e) { + throw "Certificate load error (non-certificate input?)"; + } + if (undefinedInputFormat) throw "Undefined input format"; + + console.log(input); + const crl = new r.X509CRL(input); let out = `Certificate Revocation List (CRL):