1
1
mirror of https://github.com/wader/fq.git synced 2024-09-20 00:08:01 +03:00

asn1_ber: Add more doc and multiple outputs for frompem

This commit is contained in:
Mattias Wadman 2022-02-07 17:41:05 +01:00
parent ac4d15ccb9
commit 0312c92c31
4 changed files with 26 additions and 2 deletions

View File

@ -118,6 +118,17 @@ Supports `torepr` but without schema support it's not that useful:
fq -d asn1_ber torepr file.ber fq -d asn1_ber torepr file.ber
``` ```
There is also `frompem` and `topem` to help working with PEM format:
```
fq -d raw 'frompem | asn1_ber | d' cert.pem
```
If the schema is known and not that complicated it can be reproduced:
```
fq -d asn1_ber 'torepr as $r | ["version", "modulus", "private_exponent", "private_exponen", "prime1", "prime2", "exponent1", "exponent2", "coefficient"] | with_entries({key: .value, value: $r[.key]})' pkcs1.der
```
### becode ### becode
Supports `torepr`: Supports `torepr`:

View File

@ -5,3 +5,15 @@ Supports `torepr` but without schema support it's not that useful:
``` ```
fq -d asn1_ber torepr file.ber fq -d asn1_ber torepr file.ber
``` ```
There is also `frompem` and `topem` to help working with PEM format:
```
fq -d raw 'frompem | asn1_ber | d' cert.pem
```
If the schema is known and not that complicated it can be reproduced:
```
fq -d asn1_ber 'torepr as $r | ["version", "modulus", "private_exponent", "private_exponen", "prime1", "prime2", "exponent1", "exponent2", "coefficient"] | with_entries({key: .value, value: $r[.key]})' pkcs1.der
```

View File

@ -332,7 +332,7 @@ def diff($a; $b):
def frompem: def frompem:
( tobytes ( tobytes
| tostring | tostring
| first(capture("-----BEGIN(.*?)-----(?<s>.*?)-----END(.*?)-----"; "m")).s | capture("-----BEGIN(.*?)-----(?<s>.*?)-----END(.*?)-----"; "mg").s
| base64 | base64
) // error("no pem header or footer found"); ) // error("no pem header or footer found");

View File

@ -1,7 +1,8 @@
$ fq -i $ fq -i
null> "abc" | topem null> "abc" | topem
"-----BEGIN-----\nYWJj\n-----END-----\n" "-----BEGIN-----\nYWJj\n-----END-----\n"
null> "abc" | topem | frompem | tostring null> "abc" | topem | "before" + . + "between" + . + "after" | frompem | tostring
"abc"
"abc" "abc"
null> null>
null> ^D null> ^D