minimalistic mode

This commit is contained in:
Lev Walkin 2005-08-15 06:34:04 +00:00
parent 291d3f2b28
commit 7a080483b1
3 changed files with 18 additions and 8 deletions

View File

@ -15,7 +15,7 @@ cat<<EOM > $ORIG
</C O="14" T="[UNIVERSAL 16]" A="SEQUENCE" L="8"> </C O="14" T="[UNIVERSAL 16]" A="SEQUENCE" L="8">
EOM EOM
./enber < $ORIG - | ./unber -p -i 0 - > $TEST 2>&1 ./enber $ORIG | ./unber -p -i 0 - > $TEST 2>&1
diff $diffArgs $ORIG $TEST >/dev/null 2>&1 diff $diffArgs $ORIG $TEST >/dev/null 2>&1
diffExitCode=$? diffExitCode=$?
@ -28,7 +28,7 @@ fi
echo '</I O="14" T="[UNIVERSAL 0]" TL="2" L="16">' >> $ORIG echo '</I O="14" T="[UNIVERSAL 0]" TL="2" L="16">' >> $ORIG
# Try trancoding again # Try trancoding again
./enber < $ORIG - | ./unber -p -i 0 - > $TEST 2>&1 ./enber $ORIG | ./unber -p -i 0 - > $TEST 2>&1
diff $diffArgs $ORIG $TEST diff $diffArgs $ORIG $TEST
diffExitCode=$? diffExitCode=$?

View File

@ -12,7 +12,7 @@
.SH NAME .SH NAME
unber \- ASN.1 BER Decoder unber \- ASN.1 BER Decoder
.SH SYNOPSIS .SH SYNOPSIS
unber [\fB-1\fR] [\fB-i\fRindent] [\fB-p\fR] [\fB\-t\fR\fIdata-string\fR] [\fB-\fR] [\fIinfile\fR...] unber [\fB-1\fR] [\fB-i\fRindent] [\fB-m\fR] [\fB-p\fR] [\fB\-t\fR\fIdata-string\fR] [\fB-\fR] [\fIinfile\fR...]
.SH DESCRIPTION .SH DESCRIPTION
unber takes the BER-encoded files and dumps their internal structure as human readable text. unber takes the BER-encoded files and dumps their internal structure as human readable text.
A single dash represents the standard input. A single dash represents the standard input.
@ -28,6 +28,9 @@ By default, unber continues decoding until the end of file (input stream).
\fB\-i\fR \fIindent\fR \fB\-i\fR \fIindent\fR
Use the specified number of spaces for output indentation. Default is 4 spaces. Use the specified number of spaces for output indentation. Default is 4 spaces.
.TP .TP
\fB\-m\fR
Generate minimum amount of output while still preserving BER encoding information.
.TP
\fB\-p\fR \fB\-p\fR
Do \fInot\fR attempt pretty-printing of known ASN.1 types (OBJECT IDENTIFIER, INTEGER, BOOLEAN, etc). By default, some ASN.1 types are converted into Do \fInot\fR attempt pretty-printing of known ASN.1 types (OBJECT IDENTIFIER, INTEGER, BOOLEAN, etc). By default, some ASN.1 types are converted into
the text representation. This option is required for \&\fIenber\fR\|(1). the text representation. This option is required for \&\fIenber\fR\|(1).

View File

@ -45,6 +45,7 @@ static int process(const char *fname); /* Perform the BER decoding */
static int decode_tlv_from_string(const char *datastring); static int decode_tlv_from_string(const char *datastring);
static int single_type_decoding = 0; /* -1 enables that */ static int single_type_decoding = 0; /* -1 enables that */
static int minimalistic = 0; /* -m enables that */
static int pretty_printing = 1; /* -p disables that */ static int pretty_printing = 1; /* -p disables that */
static char *indent_buffer = " "; /* -i controls that */ static char *indent_buffer = " "; /* -i controls that */
@ -56,7 +57,7 @@ main(int ac, char **av) {
/* /*
* Process command-line options. * Process command-line options.
*/ */
while((ch = getopt(ac, av, "1hi:pt:v")) != -1) while((ch = getopt(ac, av, "1hi:mpt:v")) != -1)
switch(ch) { switch(ch) {
case '1': case '1':
single_type_decoding = 1; single_type_decoding = 1;
@ -65,6 +66,9 @@ main(int ac, char **av) {
if(decode_tlv_from_string(optarg)) if(decode_tlv_from_string(optarg))
exit(EX_DATAERR); exit(EX_DATAERR);
exit(0); exit(0);
case 'm':
minimalistic = 1;
break;
case 'p': case 'p':
pretty_printing = 0; pretty_printing = 0;
break; break;
@ -124,6 +128,7 @@ usage(const char *av0) {
"Options:\n" "Options:\n"
" -1 Decode only the first BER structure (otherwise, until EOF)\n" " -1 Decode only the first BER structure (otherwise, until EOF)\n"
" -i <indent> Amount of spaces for output indentation (default is 4)\n" " -i <indent> Amount of spaces for output indentation (default is 4)\n"
" -m Minimalistic mode: print as little as possible\n"
" -p Do not attempt pretty-printing of known ASN.1 types\n" " -p Do not attempt pretty-printing of known ASN.1 types\n"
" -t <data-string> Decode the given tag[/length] sequence (e.g. -t \"bf20\")\n" " -t <data-string> Decode the given tag[/length] sequence (e.g. -t \"bf20\")\n"
"\n" "\n"
@ -363,13 +368,14 @@ print_TL(int fin, asn1c_integer_t offset, int level, int constr, ssize_t tlen, b
printf(constr ? ((tlv_len == -1) ? "I" : "C") : "P"); printf(constr ? ((tlv_len == -1) ? "I" : "C") : "P");
/* Print out the offset of this boundary, even if closing tag */ /* Print out the offset of this boundary, even if closing tag */
printf(" O=\"%" PRIdASN "\"", offset); if(!minimalistic)
printf(" O=\"%" PRIdASN "\"", offset);
printf(" T=\""); printf(" T=\"");
ber_tlv_tag_fwrite(tlv_tag, stdout); ber_tlv_tag_fwrite(tlv_tag, stdout);
printf("\""); printf("\"");
if(!fin || tlv_len == -1) if(!fin || (tlv_len == -1 && !minimalistic))
printf(" TL=\"%ld\"", (long)tlen); printf(" TL=\"%ld\"", (long)tlen);
if(!fin) { if(!fin) {
if(tlv_len == -1) if(tlv_len == -1)
@ -378,7 +384,8 @@ print_TL(int fin, asn1c_integer_t offset, int level, int constr, ssize_t tlen, b
printf(" V=\"%ld\"", (long)tlv_len); printf(" V=\"%ld\"", (long)tlv_len);
} }
if(BER_TAG_CLASS(tlv_tag) == ASN_TAG_CLASS_UNIVERSAL) { if(!minimalistic
&& BER_TAG_CLASS(tlv_tag) == ASN_TAG_CLASS_UNIVERSAL) {
const char *str; const char *str;
ber_tlv_tag_t tvalue = BER_TAG_VALUE(tlv_tag); ber_tlv_tag_t tvalue = BER_TAG_VALUE(tlv_tag);
str = ASN_UNIVERSAL_TAG2STR(tvalue); str = ASN_UNIVERSAL_TAG2STR(tvalue);
@ -386,7 +393,7 @@ print_TL(int fin, asn1c_integer_t offset, int level, int constr, ssize_t tlen, b
} }
if(fin) { if(fin) {
if(constr) if(constr && !minimalistic)
printf(" L=\"%ld\"", (long)effective_size); printf(" L=\"%ld\"", (long)effective_size);
printf(">\n"); printf(">\n");
} }