FiloSottile / age

A simple, modern and secure encryption tool (and Go library) with small explicit keys, no config options, and UNIX-style composability.
https://age-encryption.org
BSD 3-Clause "New" or "Revised" License
15.75k stars 475 forks source link

Add --inspect flag #501

Open jamespwilliams opened 1 year ago

jamespwilliams commented 1 year ago

Fixes #56.

$ cat recipients.txt
age1lz0vhyg9y3k880cqscuh4hyfv0xdl7qnjqrlcz8euxc4a5d6eagsjhl6vc
age17hxnhlkq9ewhq594s3jf8c2e36n7gfg5mvefn0f3jqsfk76m6geszmywxr
age1ll9j2fr6nsdzmnqwk8qru9nx20sj264978jwswpnwq0nwnj4ayrsyugyqx
age160amxp02vl8w5e4z5tvvcmpdtjhdzkh20s3r9gqtzwufgyucreyqm6vw0y
age1xlauzza8tgn6l7e3ympwkps8tnt9psmpjj6jl0qfnfwkxkn7l4ws3s9xar

$ echo 'Hello age' | go run ./cmd/age -a -R recipients.txt -o encrypted.age.ascii

$ go run ./cmd/age --inspect encrypted.age.ascii | jq .
{
  "RecipientCounts": {
    "X25519": 5
  },
  "Version": "age-encryption.org/v1",
  "PayloadSize": 42
}

I've chosen to make the output JSON-encoded because the data that --inspect outputs is fairly small, so the JSON is fairly easily readable (even without jq), and outputting in JSON makes it machine-readable.

I've read https://github.com/FiloSottile/age/blob/9f0a2d25ac79da8100d68f3e8b3a1a57ea4a73ba/.github/CONTRIBUTING.md and can confirm that I won't be offended if this is reimplemented instead of being merged :smile:

digtail commented 1 year ago

Thank you for writing this. I used this feature to test some tooling that uses age, and it came in very handy.