Skip to content

Commit

Permalink
Fix formatting of IPv6 addresses.
Browse files Browse the repository at this point in the history
They now correctly show as 1234:abcd:... instead of 18::52::171::205::...
  • Loading branch information
roadrunner2 committed Aug 5, 2017
1 parent db0823f commit 142c0a0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/java/org/jruby/ext/openssl/X509Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,16 @@ private static boolean formatGeneralName(final GeneralName name, final ByteList
append(':');
final byte[] ip = ((ASN1OctetString) name.getName()).getOctets();
int len = ip.length; boolean ip4 = len == 4;
for ( int i = 0; i < ip.length; i++ ) {
out.append( ConvertBytes.intToCharBytes( ((int) ip[i]) & 0xff ) );
if ( i != len - 1 ) {
if ( ip4 ) out.append('.');
else out.append(':').append(':');
if ( ip4 ) {
for ( int i = 0; i < ip.length; i++ ) {
out.append( ConvertBytes.intToCharBytes( ((int) ip[i]) & 0xff ) );
if ( i != len - 1 ) out.append('.');
}
}
else {
for ( int i = 0; i < ip.length; i += 2 ) {
out.append( ConvertBytes.intToHexBytes( ((ip[i] & 0xff) << 8 | (ip[i+1] & 0xff)) ) );
if ( i != len - 2 ) out.append(':');
}
}
break;
Expand Down

0 comments on commit 142c0a0

Please sign in to comment.