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 */ 21 22package org.apache.harmony.security.tests.support.cert; 23 24import java.security.cert.CertPath; 25import java.security.cert.CertificateEncodingException; 26import java.util.Collections; 27import java.util.Iterator; 28import java.util.List; 29import java.util.Vector; 30 31 32/** 33 * Stub class for <code>java.security.cert.CertPath</code> tests 34 */ 35public class MyCertPath extends CertPath { 36 /** 37 * my certificates list 38 */ 39 private final Vector certificates; 40 /** 41 * List of encodings supported 42 */ 43 private final Vector encodingNames; 44 /** 45 * my cert path the only encoding 46 */ 47 private final byte[] encoding; 48 49 /** 50 * Constructs new instance of <code>MyCertPath</code> 51 * 52 * @param type 53 * @param encoding 54 */ 55 public MyCertPath(byte[] encoding) { 56 super("MyEncoding"); 57 this.encoding = encoding; 58 certificates = new Vector(); 59 certificates.add(new MyCertificate("MyEncoding", encoding)); 60 encodingNames = new Vector(); 61 encodingNames.add("MyEncoding"); 62 } 63 64 /** 65 * @return certificates list 66 * @see java.security.cert.CertPath#getCertificates() 67 */ 68 public List getCertificates() { 69 return Collections.unmodifiableList(certificates); 70 } 71 72 /** 73 * @return default encoded form of this cert path 74 * @see java.security.cert.CertPath#getEncoded() 75 */ 76 public byte[] getEncoded() throws CertificateEncodingException { 77 return encoding.clone(); 78 } 79 80 /** 81 * @return encoded form of this cert path as specified by 82 * <code>encoding</code> parameter 83 * @throws CertificateEncodingException if <code>encoding</code> 84 * not equals "MyEncoding" 85 * @see java.security.cert.CertPath#getEncoded(java.lang.String) 86 */ 87 public byte[] getEncoded(String encoding) 88 throws CertificateEncodingException { 89 if (getType().equals(encoding)) { 90 return this.encoding.clone(); 91 } 92 throw new CertificateEncodingException("Encoding not supported: " + 93 encoding); 94 } 95 96 /** 97 * @return iterator through encodings supported 98 * @see java.security.cert.CertPath#getEncodings() 99 */ 100 public Iterator getEncodings() { 101 return Collections.unmodifiableCollection(encodingNames).iterator(); 102 } 103 104} 105