Skip to content

Commit

Permalink
Add support for multiple input format
Browse files Browse the repository at this point in the history
i.e. DER Hex, Base64, Raw
  • Loading branch information
robinsandhu committed Aug 25, 2024
1 parent e65869a commit dbc9009
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/core/operations/ParseX509CRL.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,7 +33,7 @@ class ParseX509CRL extends Operation {
{
"name": "Input format",
"type": "option",
"value": ["PEM"]
"value": ["PEM", "DER Hex", "Base64", "Raw"]
}
];
this.checks = [
Expand All @@ -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);

Check failure on line 82 in src/core/operations/ParseX509CRL.mjs

View workflow job for this annotation

GitHub Actions / main

Unexpected console statement

const crl = new r.X509CRL(input);

let out = `Certificate Revocation List (CRL):
Expand Down

0 comments on commit dbc9009

Please sign in to comment.