Skip to content

Commit

Permalink
improved asn1 dump for short bit and octet strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Kramer committed Nov 23, 2013
1 parent f0a012c commit 0e8f892
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions kse/src/net/sf/keystore_explorer/utilities/asn1/Asn1Dump.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,12 @@ private String dumpOctetString(ASN1OctetString asn1OctetString) throws IOExcepti
sb.append(encapsulated);
} catch (Exception e) {
sb.append("=");
sb.append(NEWLINE);
sb.append(dumpOctetStringValue(asn1OctetString));
if (bytes.length < 8) {
sb.append(HexUtil.getHexString(bytes));
} else {
sb.append(NEWLINE);
sb.append(dumpHexClear(bytes));
}
}
sb.append(NEWLINE);

Expand All @@ -328,14 +332,20 @@ private String dumpBitString(DERBitString asn1BitString) throws IOException {
sb.append(dump);
} catch (Exception e) {
sb.append("=");
sb.append(NEWLINE);
sb.append(dumpHexClear(bytes));

// print short bit strings as string of bits and long ones as hex dump
if (bytes.length < 8) {
sb.append(new BigInteger(1, bytes).toString(2));
} else {
sb.append(NEWLINE);
sb.append(dumpHexClear(bytes));
}
}
sb.append(NEWLINE);

return sb.toString();
}

private String dumpObjectIdentifier(ASN1ObjectIdentifier asn1ObjectIdentifier) {
StringBuffer sb = new StringBuffer();

Expand Down Expand Up @@ -521,9 +531,6 @@ private String dumpString(ASN1String asn1String) {
return sb.toString();
}

private String dumpOctetStringValue(ASN1OctetString asn1OctetString) throws IOException {
return dumpHexClear(asn1OctetString.getOctets());
}

private String dumpHexClear(byte[] der) throws IOException {
try {
Expand All @@ -532,7 +539,7 @@ private String dumpHexClear(byte[] der) throws IOException {
// Get hex/clear dump of value
String hexClearDump = HexUtil.getHexClearDump(der);

// Put indent at the start of ech line of teh dump
// Put indent at the start of each line of the dump
LineNumberReader lnr = new LineNumberReader(new StringReader(hexClearDump));

StringBuffer sb = new StringBuffer();
Expand Down

0 comments on commit 0e8f892

Please sign in to comment.