1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/** 19* @author Vladimir N. Molotkov 20* @version $Revision$ 21*/ 22 23package org.apache.harmony.security.tests.support.cert; 24 25import java.io.ObjectStreamException; 26import java.security.cert.CertPath; 27import java.security.cert.CertificateEncodingException; 28import java.util.Collections; 29import java.util.Iterator; 30import java.util.List; 31import java.util.Vector; 32 33 34/** 35 * Stub class for <code>java.security.cert.CertPath</code> tests 36 * 37 */ 38public class MyCertPath extends CertPath { 39 private static final long serialVersionUID = 7444835599161870893L; 40 /** 41 * my certificates list 42 */ 43 private final Vector<MyCertificate> certificates; 44 45 /** 46 * List of encodings supported 47 */ 48 private final Vector<String> encodingNames; 49 /** 50 * my cert path the only encoding 51 */ 52 private final byte[] encoding; 53 54 /** 55 * Constructs new instance of <code>MyCertPath</code> 56 * 57 */ 58 public MyCertPath(byte[] encoding) { 59 super("MyEncoding"); 60 this.encoding = encoding; 61 certificates = new Vector<MyCertificate>(); 62 certificates.add(new MyCertificate("MyEncoding", encoding)); 63 encodingNames = new Vector<String>(); 64 encodingNames.add("MyEncoding"); 65 } 66 67 /** 68 * @return certificates list 69 * @see java.security.cert.CertPath#getCertificates() 70 */ 71 public List<MyCertificate> getCertificates() { 72 return Collections.unmodifiableList(certificates); 73 } 74 75 /** 76 * @return default encoded form of this cert path 77 * @throws CertificateEncodingException 78 * @see java.security.cert.CertPath#getEncoded() 79 */ 80 public byte[] getEncoded() throws CertificateEncodingException { 81 return encoding.clone(); 82 } 83 84 /** 85 * @return encoded form of this cert path as specified by 86 * <code>encoding</code> parameter 87 * @throws CertificateEncodingException 88 * if <code>encoding</code> not equals "MyEncoding" 89 * @see java.security.cert.CertPath#getEncoded(java.lang.String) 90 */ 91 public byte[] getEncoded(String encoding) 92 throws CertificateEncodingException { 93 if (getType().equals(encoding)) { 94 return this.encoding.clone(); 95 } 96 throw new CertificateEncodingException("Encoding not supported: " + 97 encoding); 98 } 99 100 /** 101 * @return iterator through encodings supported 102 * @see java.security.cert.CertPath#getEncodings() 103 */ 104 public Iterator<String> getEncodings() { 105 return Collections.unmodifiableCollection(encodingNames).iterator(); 106 } 107 108 /** 109 * @return the CertPathRep to be serialized 110 * @see java.security.cert.CertPath#writeReplace() 111 */ 112 public Object writeReplace() throws ObjectStreamException { 113 return super.writeReplace(); 114 } 115 116 public class MyCertPathRep extends CertPath.CertPathRep { 117 118 private static final long serialVersionUID = 1609000085450479173L; 119 120 private String type; 121 private byte[] data; 122 123 public MyCertPathRep(String type, byte[] data) { 124 super(type, data); 125 this.data = data; 126 this.type = type; 127 } 128 129 public Object readResolve() throws ObjectStreamException { 130 return super.readResolve(); 131 } 132 133 public String getType() { 134 return type; 135 } 136 137 public byte[] getData() { 138 return data; 139 } 140 } 141} 142