11/*
2- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2323
2424/*
2525 * @test
26- * @bug 8298127
26+ * @bug 8298127 8347596
2727 * @library /test/lib
2828 * @summary tests for HSS/LMS provider
2929 * @modules java.base/sun.security.util
4040import java .security .spec .X509EncodedKeySpec ;
4141import java .util .HexFormat ;
4242
43+ import jdk .test .lib .Asserts ;
4344import sun .security .util .*;
4445
4546import jdk .test .lib .util .SerializationUtils ;
@@ -61,9 +62,7 @@ public static void main(String[] args) throws Exception {
6162 i ++;
6263 }
6364
64- if (!serializeTest ()) {
65- throw new RuntimeException ("serializeTest failed" );
66- }
65+ serializeTest ();
6766
6867 System .out .println ("All tests passed" );
6968 }
@@ -88,7 +87,7 @@ static boolean kat(TestCase t) throws Exception {
8887 }
8988 }
9089
91- static boolean serializeTest () throws Exception {
90+ static void serializeTest () throws Exception {
9291 final ObjectIdentifier oid ;
9392 var pk = decode ("""
9493 00000002
@@ -106,7 +105,19 @@ static boolean serializeTest() throws Exception {
106105 throw new AssertionError (e );
107106 }
108107
109- var keyBits = new DerOutputStream ().putOctetString (pk ).toByteArray ();
108+ // Encoding without inner OCTET STRING
109+ var pk0 = makeKey (oid , pk );
110+ // Encoding with inner OCTET STRING
111+ var pk1 = makeKey (oid , new DerOutputStream ().putOctetString (pk ).toByteArray ());
112+ Asserts .assertEquals (pk0 , pk1 );
113+
114+ PublicKey pk2 = (PublicKey ) SerializationUtils
115+ .deserialize (SerializationUtils .serialize (pk1 ));
116+ Asserts .assertEquals (pk1 , pk2 );
117+ }
118+
119+ static PublicKey makeKey (ObjectIdentifier oid , byte [] keyBits )
120+ throws Exception {
110121 var oidBytes = new DerOutputStream ().write (DerValue .tag_Sequence ,
111122 new DerOutputStream ().putOID (oid ));
112123 var x509encoding = new DerOutputStream ().write (DerValue .tag_Sequence ,
@@ -115,11 +126,7 @@ static boolean serializeTest() throws Exception {
115126 .toByteArray ();
116127
117128 var x509KeySpec = new X509EncodedKeySpec (x509encoding );
118- var pk1 = KeyFactory .getInstance (ALG ).generatePublic (x509KeySpec );
119-
120- PublicKey pk2 = (PublicKey ) SerializationUtils
121- .deserialize (SerializationUtils .serialize (pk1 ));
122- return pk2 .equals (pk1 );
129+ return KeyFactory .getInstance (ALG ).generatePublic (x509KeySpec );
123130 }
124131
125132 static boolean verify (byte [] pk , byte [] sig , byte [] msg ) throws Exception {
0 commit comments