Skip to content

Commit

Permalink
feat(core): Add Multibash Type & Multibase encoding CLI options to en…
Browse files Browse the repository at this point in the history
…ola info digest
  • Loading branch information
vorburger committed Jan 4, 2025
1 parent c2c5487 commit 06c99db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/use/info/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions java/dev/enola/cli/DigestCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down

0 comments on commit 06c99db

Please sign in to comment.