ExemptionMechanismSpi.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* ExemptionMechanismSpi.java -- Exemption mechanism service provider interface.
  2. Copyright (C) 2004 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.crypto;
  32. import java.security.AlgorithmParameters;
  33. import java.security.InvalidAlgorithmParameterException;
  34. import java.security.InvalidKeyException;
  35. import java.security.Key;
  36. import java.security.spec.AlgorithmParameterSpec;
  37. /**
  38. * The <i>Service Provider Interface</i> (<b>SPI</b>) for the {@link
  39. * ExemptionMechanism} class.
  40. *
  41. * @author Casey Marshall (csm@gnu.org)
  42. * @since 1.4
  43. */
  44. public abstract class ExemptionMechanismSpi
  45. {
  46. // Constructor.
  47. // ------------------------------------------------------------------------
  48. /**
  49. * Create a new exemption mechanism SPI.
  50. */
  51. public ExemptionMechanismSpi()
  52. {
  53. }
  54. // Abstract instance methods.
  55. // ------------------------------------------------------------------------
  56. /**
  57. * Return a key blob for the key that this mechanism was initialized
  58. * with.
  59. *
  60. * @return The key blob.
  61. * @throws javax.crypto.ExemptionMechanismException If generating the
  62. * blob fails.
  63. */
  64. protected abstract byte[] engineGenExemptionBlob()
  65. throws ExemptionMechanismException;
  66. /**
  67. * Generate a key blob for the key that this mechanism was initialized
  68. * with, storing it into the given byte array.
  69. *
  70. * @param output The destination for the key blob.
  71. * @param outputOffset The index in the output array to start.
  72. * @return The size of the key blob.
  73. * @throws javax.crypto.ExemptionMechanismException If generating the
  74. * blob fails.
  75. * @throws javax.crypto.ShortBufferException If the output array is
  76. * not large enough for the key blob.
  77. */
  78. protected abstract int engineGenExemptionBlob(byte[] output, int outputOffset)
  79. throws ExemptionMechanismException, ShortBufferException;
  80. /**
  81. * Get the size of the output blob given an input key size. The actual
  82. * blob may be shorter than the value returned by this method. Both
  83. * values are in bytes.
  84. *
  85. * @param inputLength The input size.
  86. * @return The output size.
  87. */
  88. protected abstract int engineGetOutputSize(int inputLength);
  89. /**
  90. * Initialize this mechanism with a key.
  91. *
  92. * @param key The key.
  93. * @throws javax.crypto.ExemptionMechanismException If generating the
  94. * blob fails.
  95. * @throws java.security.InvalidKeyException If the supplied key
  96. * cannot be used.
  97. */
  98. protected abstract void engineInit(Key key)
  99. throws ExemptionMechanismException, InvalidKeyException;
  100. /**
  101. * Initialize this mechanism with a key and parameters.
  102. *
  103. * @param key The key.
  104. * @param params The parameters.
  105. * @throws javax.crypto.ExemptionMechanismException If generating the
  106. * blob fails.
  107. * @throws java.security.InvalidAlgorithmParameterExceptin If the
  108. * supplied parameters are inappropriate.
  109. * @throws java.security.InvalidKeyException If the supplied key
  110. * cannot be used.
  111. */
  112. protected abstract void engineInit(Key key, AlgorithmParameters params)
  113. throws ExemptionMechanismException, InvalidAlgorithmParameterException,
  114. InvalidKeyException;
  115. /**
  116. * Initialize this mechanism with a key and parameters.
  117. *
  118. * @param key The key.
  119. * @param params The parameters.
  120. * @throws javax.crypto.ExemptionMechanismException If generating the
  121. * blob fails.
  122. * @throws java.security.InvalidAlgorithmParameterExceptin If the
  123. * supplied parameters are inappropriate.
  124. * @throws java.security.InvalidKeyException If the supplied key
  125. * cannot be used.
  126. */
  127. protected abstract void engineInit(Key key, AlgorithmParameterSpec params)
  128. throws ExemptionMechanismException, InvalidAlgorithmParameterException,
  129. InvalidKeyException;
  130. }