001 /* Copyright (c) 2002 Graz University of Technology. All rights reserved. 002 * 003 * Redistribution and use in source and binary forms, with or without 004 * modification, are permitted provided that the following conditions are met: 005 * 006 * 1. Redistributions of source code must retain the above copyright notice, 007 * this list of conditions and the following disclaimer. 008 * 009 * 2. Redistributions in binary form must reproduce the above copyright notice, 010 * this list of conditions and the following disclaimer in the documentation 011 * and/or other materials provided with the distribution. 012 * 013 * 3. The end-user documentation included with the redistribution, if any, must 014 * include the following acknowledgment: 015 * 016 * "This product includes software developed by IAIK of Graz University of 017 * Technology." 018 * 019 * Alternately, this acknowledgment may appear in the software itself, if 020 * and wherever such third-party acknowledgments normally appear. 021 * 022 * 4. The names "Graz University of Technology" and "IAIK of Graz University of 023 * Technology" must not be used to endorse or promote products derived from 024 * this software without prior written permission. 025 * 026 * 5. Products derived from this software may not be called 027 * "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior 028 * written permission of Graz University of Technology. 029 * 030 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 031 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 032 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 033 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE 034 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 035 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 036 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 037 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 038 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 039 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 040 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 041 * POSSIBILITY OF SUCH DAMAGE. 042 */ 043 044 package demo.pkcs.pkcs11; 045 046 import java.security.NoSuchAlgorithmException; 047 import java.security.Signature; 048 049 import iaik.asn1.structures.AlgorithmID; 050 051 052 053 /** 054 * This class is an adapter to enables an application to use a different 055 * implementation than the standard implementation with the IAIK-JCE. 056 * 057 * @author <a href="mailto:Karl.Scheibelhofer@iaik.at"> Karl Scheibelhofer </a> 058 * @version 0.1 059 * @invariants 060 */ 061 public class AlgorithmIDAdapter extends AlgorithmID { 062 063 /** 064 * The delegate object to use, if no concrete implementation is set for a 065 * certain engine class. 066 */ 067 protected AlgorithmID delegate_; 068 069 /** 070 * This is the signature engine to use for this object. 071 */ 072 protected Signature signatureEngine_; 073 074 /** 075 * Creates a new AlgorithmIDAdapter that uses the given delegate object 076 * to get the . 077 * 078 * @param delegate The object to get other implementations from, 079 * implementations not provided by this object. 080 * @preconditions 081 * @postconditions 082 */ 083 public AlgorithmIDAdapter(AlgorithmID delegate) { 084 super(delegate.getAlgorithm()); 085 delegate_ = delegate; 086 } 087 088 /** 089 * Set the implementation to use as signature instance. 090 * 091 * @param signatureEngine The implementation of the signature class to return 092 * upon a call to getSignatureInstance(). If null, the 093 * implementation is unset. 094 * @preconditions 095 * @postconditions 096 */ 097 public void setSignatureInstance(Signature signatureEngine) { 098 signatureEngine_ = signatureEngine; 099 } 100 101 /** 102 * If a concrete signature implementation was set using 103 * setSignatureInstance(Signature), this method returns this. Otherwise, it 104 * delegates the call to the delegate of this object. 105 * 106 * @return The signature engine to use for this algorthim. 107 * @exception NoSuchAlgorithmException If there is no signature 108 * implementation for this algorithm. 109 * @preconditions 110 * @postconditions 111 */ 112 public Signature getSignatureInstance() 113 throws NoSuchAlgorithmException 114 { 115 return (signatureEngine_ != null) ? signatureEngine_ : super.getSignatureInstance(); 116 } 117 118 /** 119 * If a concrete signature implementation was set using 120 * setSignatureInstance(Signature) and the provider name is null, this method 121 * returns this set signature implementation; otherwise, it delegates the call 122 * to the delegate of this object. 123 * 124 * @return The signature engine to use for this algorthim. 125 * @exception NoSuchAlgorithmException If there is no signature 126 * implementation for this algorithm. 127 * @preconditions 128 * @postconditions 129 */ 130 public Signature getSignatureInstance(String providerName) 131 throws NoSuchAlgorithmException 132 { 133 return (providerName == null) ? getSignatureInstance() : super.getSignatureInstance(providerName); 134 } 135 136 }