From 06c99db49e704a03001383cb73f9d5ca313ed755 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Sat, 4 Jan 2025 20:05:04 +0100 Subject: [PATCH] feat(core): Add Multibash Type & Multibase encoding CLI options to enola info digest --- docs/use/info/index.md | 7 +++++++ java/dev/enola/cli/DigestCommand.java | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/use/info/index.md b/docs/use/info/index.md index 5af7427f..a293ed92 100644 --- a/docs/use/info/index.md +++ b/docs/use/info/index.md @@ -91,6 +91,13 @@ $ ./enola info digest --http-scheme https://www.google.com ... ``` +Or alternatively: + +```bash cd ../.././.. +$ ./enola info digest --base=Base64Pad --type=sha2_256 --http-scheme https://www.google.com +... +``` + This _digest_ can be used e.g. in [`?integrity=...` of `fetch`](../fetch/index.md#integrity). ## Screencast diff --git a/java/dev/enola/cli/DigestCommand.java b/java/dev/enola/cli/DigestCommand.java index 7ca8cd1b..aa60c10e 100644 --- a/java/dev/enola/cli/DigestCommand.java +++ b/java/dev/enola/cli/DigestCommand.java @@ -42,6 +42,22 @@ public class DigestCommand extends CommandWithResourceProvider { @CommandLine.Parameters(index = "0", paramLabel = "url", description = "URL") String url; + @CommandLine.Option( + names = {"--type"}, + required = true, + defaultValue = "sha2_512", + showDefaultValue = CommandLine.Help.Visibility.ALWAYS, + description = "Multihash Type") + Multihash.Type type; + + @CommandLine.Option( + names = {"--base"}, + required = true, + defaultValue = "Base58BTC", + showDefaultValue = CommandLine.Help.Visibility.ALWAYS, + description = "Multibase") + Multibase.Base multibase; + @Override public Integer call() throws Exception { super.run(); @@ -51,8 +67,9 @@ public Integer call() throws Exception { try (var ctx = TLC.open().push(URIs.ContextKeys.BASE, Paths.get("").toUri())) { var resource = rp.getResource(uri); - var multihash = new ResourceHasher().hash(resource, Multihash.Type.sha2_512); - pw.println(Multihashes.toString(multihash, Multibase.Base.Base64)); + var multihash = new ResourceHasher().hash(resource, type); + multibase = Multibase.Base.Base64; + pw.println(Multihashes.toString(multihash, multibase)); } return 0; }