1. /*
  2. * @(#)AlgorithmParametersSpi.java 1.12 04/05/05
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security;
  8. import java.io.*;
  9. import java.security.spec.AlgorithmParameterSpec;
  10. import java.security.spec.InvalidParameterSpecException;
  11. /**
  12. * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
  13. * for the <code>AlgorithmParameters</code> class, which is used to manage
  14. * algorithm parameters.
  15. *
  16. * <p> All the abstract methods in this class must be implemented by each
  17. * cryptographic service provider who wishes to supply parameter management
  18. * for a particular algorithm.
  19. *
  20. * @author Jan Luehe
  21. *
  22. * @version 1.12, 05/05/04
  23. *
  24. * @see AlgorithmParameters
  25. * @see java.security.spec.AlgorithmParameterSpec
  26. * @see java.security.spec.DSAParameterSpec
  27. *
  28. * @since 1.2
  29. */
  30. public abstract class AlgorithmParametersSpi {
  31. /**
  32. * Initializes this parameters object using the parameters
  33. * specified in <code>paramSpec</code>.
  34. *
  35. * @param paramSpec the parameter specification.
  36. *
  37. * @exception InvalidParameterSpecException if the given parameter
  38. * specification is inappropriate for the initialization of this parameter
  39. * object.
  40. */
  41. protected abstract void engineInit(AlgorithmParameterSpec paramSpec)
  42. throws InvalidParameterSpecException;
  43. /**
  44. * Imports the specified parameters and decodes them
  45. * according to the primary decoding format for parameters.
  46. * The primary decoding format for parameters is ASN.1, if an ASN.1
  47. * specification for this type of parameters exists.
  48. *
  49. * @param params the encoded parameters.
  50. *
  51. * @exception IOException on decoding errors
  52. */
  53. protected abstract void engineInit(byte[] params)
  54. throws IOException;
  55. /**
  56. * Imports the parameters from <code>params</code> and
  57. * decodes them according to the specified decoding format.
  58. * If <code>format</code> is null, the
  59. * primary decoding format for parameters is used. The primary decoding
  60. * format is ASN.1, if an ASN.1 specification for these parameters
  61. * exists.
  62. *
  63. * @param params the encoded parameters.
  64. *
  65. * @param format the name of the decoding format.
  66. *
  67. * @exception IOException on decoding errors
  68. */
  69. protected abstract void engineInit(byte[] params, String format)
  70. throws IOException;
  71. /**
  72. * Returns a (transparent) specification of this parameters
  73. * object.
  74. * <code>paramSpec</code> identifies the specification class in which
  75. * the parameters should be returned. It could, for example, be
  76. * <code>DSAParameterSpec.class</code>, to indicate that the
  77. * parameters should be returned in an instance of the
  78. * <code>DSAParameterSpec</code> class.
  79. *
  80. * @param paramSpec the the specification class in which
  81. * the parameters should be returned.
  82. *
  83. * @return the parameter specification.
  84. *
  85. * @exception InvalidParameterSpecException if the requested parameter
  86. * specification is inappropriate for this parameter object.
  87. */
  88. protected abstract
  89. <T extends AlgorithmParameterSpec>
  90. T engineGetParameterSpec(Class<T> paramSpec)
  91. throws InvalidParameterSpecException;
  92. /**
  93. * Returns the parameters in their primary encoding format.
  94. * The primary encoding format for parameters is ASN.1, if an ASN.1
  95. * specification for this type of parameters exists.
  96. *
  97. * @return the parameters encoded using the specified encoding scheme.
  98. *
  99. * @exception IOException on encoding errors.
  100. */
  101. protected abstract byte[] engineGetEncoded() throws IOException;
  102. /**
  103. * Returns the parameters encoded in the specified format.
  104. * If <code>format</code> is null, the
  105. * primary encoding format for parameters is used. The primary encoding
  106. * format is ASN.1, if an ASN.1 specification for these parameters
  107. * exists.
  108. *
  109. * @param format the name of the encoding format.
  110. *
  111. * @return the parameters encoded using the specified encoding scheme.
  112. *
  113. * @exception IOException on encoding errors.
  114. */
  115. protected abstract byte[] engineGetEncoded(String format)
  116. throws IOException;
  117. /**
  118. * Returns a formatted string describing the parameters.
  119. *
  120. * @return a formatted string describing the parameters.
  121. */
  122. protected abstract String engineToString();
  123. }