blob: 22e586ca59b7c180f9e9d157a74aa6c5b848876e [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/**
25 * @test
26 * @bug 4921802
27 * @summary Test that the SunPKCS11 provider can be serialized
28 * @author Andreas Sterbenz
29 * @library ..
30 */
31
32import java.io.*;
33import java.util.*;
34
35import java.security.*;
36
37public class SerializeProvider extends PKCS11Test {
38
39 public void main(Provider p) throws Exception {
40 if (Security.getProvider(p.getName()) != p) {
41 System.out.println("Provider not installed in Security, skipping");
42 return;
43 }
44
45 ByteArrayOutputStream out = new ByteArrayOutputStream();
46 ObjectOutputStream oout = new ObjectOutputStream(out);
47
48 oout.writeObject(p);
49 oout.close();
50
51 byte[] data = out.toByteArray();
52
53 InputStream in = new ByteArrayInputStream(data);
54 ObjectInputStream oin = new ObjectInputStream(in);
55
56 Provider p2 = (Provider)oin.readObject();
57
58 System.out.println("Reconstituted: " + p2);
59
60 if (p != p2) {
61 throw new Exception("Provider object mismatch");
62 }
63 }
64
65 public static void main(String[] args) throws Exception {
66 main(new SerializeProvider());
67 }
68
69}