From 3f5e5faaa36dff84226ec04bc61d96acbb7d9ece Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Fri, 19 Apr 2024 22:36:56 +0000 Subject: [PATCH] Add support for data URI input. --- dumpASN1.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dumpASN1.js b/dumpASN1.js index 4f93fa5..9619af1 100755 --- a/dumpASN1.js +++ b/dumpASN1.js @@ -8,7 +8,8 @@ import { Defs } from './defs.js'; const colYellow = '\x1b[33m', colBlue = '\x1b[34m', - colReset = '\x1b[0m'; + colReset = '\x1b[0m', + reDataURI = /^data:(?:[a-z-]+[/][a-z.+-]+;)?base64,([A-Za-z0-9+/=\s]+)$/; function print(value, indent) { if (indent === undefined) indent = ''; @@ -40,7 +41,11 @@ function print(value, indent) { return s; } -let content = fs.readFileSync(process.argv[2]); +const filename = process.argv[2]; +const match = reDataURI.exec(filename); +let content = match + ? Buffer.from(match[1]) + : fs.readFileSync(filename); try { // try PEM first content = Base64.unarmor(content); } catch (e) { // try DER/BER then -- 2.51.2