Skip to content

Commit 142c0a0

Browse files
committed
Fix formatting of IPv6 addresses.
They now correctly show as 1234:abcd:... instead of 18::52::171::205::...
1 parent db0823f commit 142c0a0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/main/java/org/jruby/ext/openssl/X509Extension.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,16 @@ private static boolean formatGeneralName(final GeneralName name, final ByteList
661661
append(':');
662662
final byte[] ip = ((ASN1OctetString) name.getName()).getOctets();
663663
int len = ip.length; boolean ip4 = len == 4;
664-
for ( int i = 0; i < ip.length; i++ ) {
665-
out.append( ConvertBytes.intToCharBytes( ((int) ip[i]) & 0xff ) );
666-
if ( i != len - 1 ) {
667-
if ( ip4 ) out.append('.');
668-
else out.append(':').append(':');
664+
if ( ip4 ) {
665+
for ( int i = 0; i < ip.length; i++ ) {
666+
out.append( ConvertBytes.intToCharBytes( ((int) ip[i]) & 0xff ) );
667+
if ( i != len - 1 ) out.append('.');
668+
}
669+
}
670+
else {
671+
for ( int i = 0; i < ip.length; i += 2 ) {
672+
out.append( ConvertBytes.intToHexBytes( ((ip[i] & 0xff) << 8 | (ip[i+1] & 0xff)) ) );
673+
if ( i != len - 2 ) out.append(':');
669674
}
670675
}
671676
break;

0 commit comments

Comments
 (0)