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 d59cdf8 commit e896515
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
11 changes: 9 additions & 2 deletions docs/use/info/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,22 @@ $ ./enola info metadata --load=test/metadata-label-property.ttl https://example.

## Digest

```bash cd ../.././..
```bash $? cd ../.././..
$ ./enola info digest --help
...
```

So for example:

```bash cd ../.././..
$ ./enola info digest --http-scheme https://www.google.com
$ ./enola info digest --http-scheme https://www.vorburger.ch/hello.md
...
```

Or alternatively:

```bash cd ../.././..
$ ./enola info digest --base=Base64Pad --type=sha2_256 --http-scheme https://www.vorburger.ch/hello.md
...
```

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 e896515

Please sign in to comment.