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