summaryrefslogtreecommitdiffstats
path: root/crypto/bio
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2000-07-27 17:28:25 +0000
committerRichard Levitte <levitte@openssl.org>2000-07-27 17:28:25 +0000
commitca1e465f6dd96d8dc15e418eda13fc3bd26362b2 (patch)
tree96936fa929c8d9280868e0d634196b627b4ebb38 /crypto/bio
parentf6c1c9e95dd7ceadae070bd32e59cfa20726b42e (diff)
Add the possibility to get hexdumps of unprintable data when using
'openssl asn1parse'. As a side effect, the functions ASN1_parse_dump and BIO_dump_indent are added.
Diffstat (limited to 'crypto/bio')
-rw-r--r--crypto/bio/b_dump.c41
-rw-r--r--crypto/bio/bio.h1
2 files changed, 30 insertions, 12 deletions
diff --git a/crypto/bio/b_dump.c b/crypto/bio/b_dump.c
index f5aeb237f5..7cbe4f22b5 100644
--- a/crypto/bio/b_dump.c
+++ b/crypto/bio/b_dump.c
@@ -66,13 +66,20 @@
#define TRUNCATE
#define DUMP_WIDTH 16
+#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
int BIO_dump(BIO *bio, const char *s, int len)
+ {
+ return BIO_dump_indent(bio, s, len, 0);
+ }
+
+int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
{
int ret=0;
- char buf[160+1],tmp[20];
+ char buf[288+1],tmp[20],str[128+1];
int i,j,rows,trunc;
unsigned char ch;
+ int dump_width;
trunc=0;
@@ -81,27 +88,37 @@ int BIO_dump(BIO *bio, const char *s, int len)
trunc++;
#endif
- rows=(len/DUMP_WIDTH);
- if ((rows*DUMP_WIDTH)<len)
+ if (indent < 0)
+ indent = 0;
+ if (indent) {
+ if (indent > 128) indent=128;
+ memset(str,' ',indent);
+ }
+ str[indent]='\0';
+
+ dump_width=DUMP_WIDTH_LESS_INDENT(indent);
+ rows=(len/dump_width);
+ if ((rows*dump_width)<len)
rows++;
for(i=0;i<rows;i++) {
buf[0]='\0'; /* start with empty string */
- sprintf(tmp,"%04x - ",i*DUMP_WIDTH);
- strcpy(buf,tmp);
- for(j=0;j<DUMP_WIDTH;j++) {
- if (((i*DUMP_WIDTH)+j)>=len) {
+ strcpy(buf,str);
+ sprintf(tmp,"%04x - ",i*dump_width);
+ strcat(buf,tmp);
+ for(j=0;j<dump_width;j++) {
+ if (((i*dump_width)+j)>=len) {
strcat(buf," ");
} else {
- ch=((unsigned char)*(s+i*DUMP_WIDTH+j)) & 0xff;
+ ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
sprintf(tmp,"%02x%c",ch,j==7?'-':' ');
strcat(buf,tmp);
}
}
strcat(buf," ");
- for(j=0;j<DUMP_WIDTH;j++) {
- if (((i*DUMP_WIDTH)+j)>=len)
+ for(j=0;j<dump_width;j++) {
+ if (((i*dump_width)+j)>=len)
break;
- ch=((unsigned char)*(s+i*DUMP_WIDTH+j)) & 0xff;
+ ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
#ifndef CHARSET_EBCDIC
sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.');
#else
@@ -119,7 +136,7 @@ int BIO_dump(BIO *bio, const char *s, int len)
}
#ifdef TRUNCATE
if (trunc > 0) {
- sprintf(buf,"%04x - <SPACES/NULS>\n",len+trunc);
+ sprintf(buf,"%s%04x - <SPACES/NULS>\n",str,len+trunc);
ret+=BIO_write(bio,(char *)buf,strlen(buf));
}
#endif
diff --git a/crypto/bio/bio.h b/crypto/bio/bio.h
index 5634a96a79..76748e05d8 100644
--- a/crypto/bio/bio.h
+++ b/crypto/bio/bio.h
@@ -559,6 +559,7 @@ int BIO_sock_non_fatal_error(int error);
int BIO_fd_should_retry(int i);
int BIO_fd_non_fatal_error(int error);
int BIO_dump(BIO *b,const char *bytes,int len);
+int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent);
struct hostent *BIO_gethostbyname(const char *name);
/* We might want a thread-safe interface too: