Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: cryptix/pki/KeyIDFactory.java


1   /* $Id: KeyIDFactory.java,v 1.2 2005/03/13 17:47:10 woudt Exp $
2    *
3    * Copyright (C) 1999-2005 The Cryptix Foundation Limited.
4    * All rights reserved.
5    * 
6    * Use, modification, copying and distribution of this software is subject 
7    * the terms and conditions of the Cryptix General Licence. You should have 
8    * received a copy of the Cryptix General License along with this library; 
9    * if not, you can download a copy from http://www.cryptix.org/ .
10   */
11  
12  package cryptix.pki;
13  
14  
15  import java.security.InvalidKeyException;
16  import java.security.Key;
17  import java.security.NoSuchAlgorithmException;
18  import java.security.NoSuchProviderException;
19  import java.security.Provider;
20  
21  
22  /**
23   * A class for generating a KeyID
24   *
25   * @author  Edwin Woudt <edwin@cryptix.org>
26   * @version $Revision: 1.2 $
27   */
28  public class KeyIDFactory {
29  
30  
31  // Instance variables
32  // ..........................................................................
33  
34      private final KeyIDFactorySpi spi;
35      private final Provider provider;
36      private final String format;
37      
38  
39  // Constructor
40  // ..........................................................................
41  
42      /**
43       * Create a new KeyIDFactory object containing the given
44       * SPI object.
45       */
46      protected KeyIDFactory(KeyIDFactorySpi builderSpi,
47                             Provider provider, String format)
48      {
49          this.spi      = builderSpi;
50          this.provider = provider;
51          this.format   = format;
52      }
53  
54  
55  // getInstance methods
56  // ..........................................................................
57  
58      /**
59       * Returns a KeyIDFactory that implements the given format.
60       */
61      public static KeyIDFactory getInstance(String format) 
62          throws NoSuchAlgorithmException
63      {
64          Object[] o = Support.getImplementation("KeyIDFactory", 
65                                                 format);
66          return new KeyIDFactory( (KeyIDFactorySpi)o[0],
67                                   (Provider)o[1], format);
68      }
69      
70  
71      /**
72       * Returns a KeyIDFactory from the given provider that 
73       * implements the given format.
74       */
75      public static KeyIDFactory getInstance(String format, 
76                                             String provider) 
77          throws NoSuchAlgorithmException, NoSuchProviderException
78      {
79          Object[] o = Support.getImplementation("KeyIDFactory", 
80                                                 format, provider);
81          return new KeyIDFactory( (KeyIDFactorySpi)o[0],
82                                   (Provider)o[1], format);
83      }
84      
85  
86      /**
87       * Returns a KeyIDFactory from the given provider that 
88       * implements the given format.
89       */
90      public static KeyIDFactory getInstance(String format, 
91                                             Provider provider) 
92          throws NoSuchAlgorithmException, NoSuchProviderException
93      {
94          Object[] o = Support.getImplementation("KeyIDFactory", 
95                                                 format, provider);
96          return new KeyIDFactory( (KeyIDFactorySpi)o[0],
97                                   (Provider)o[1], format);
98      }
99      
100 
101 // Non-SPI getters
102 // ..........................................................................
103 
104     /**
105      * Returns the provider of this object.
106      */
107     public final Provider getProvider() {
108         return this.provider;
109     }
110     
111 
112     /**
113      * Returns the name of the format of this object.
114      */
115     public final String getFormat() {
116         return this.format;
117     }
118 
119 
120 // Wrapped SPI functions
121 // ..........................................................................
122 
123 
124     /**
125      * Generates a KeyID from a key.
126      *
127      * @throws InvalidKeyException if the given key is not of the right type
128      *         to produce a KeyID.
129      */
130     public final KeyID generateKeyID(Key key) 
131         throws InvalidKeyException
132     {
133         return this.spi.engineGenerateKeyID(key);
134     }
135     
136 
137 }