1
1
mirror of https://github.com/wader/fq.git synced 2024-12-23 05:13:30 +03:00

Merge pull request #132 from wader/asn1-frompem-doc

asn1_ber: Add more doc and multiple outputs for frompem
This commit is contained in:
Mattias Wadman 2022-02-07 18:04:12 +01:00 committed by GitHub
commit 2dc2a24f92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
```
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
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
```
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:
( tobytes
| tostring
| first(capture("-----BEGIN(.*?)-----(?<s>.*?)-----END(.*?)-----"; "m")).s
| capture("-----BEGIN(.*?)-----(?<s>.*?)-----END(.*?)-----"; "mg").s
| base64
) // error("no pem header or footer found");

View File

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