IKeyring.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* IKeyring.java --
  2. Copyright (C) 2003, 2006 Free Software Foundation, Inc.
  3. This file is a 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 of the License, or (at
  7. your option) 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; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
  15. 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 gnu.javax.crypto.keyring;
  32. import java.io.IOException;
  33. import java.util.Enumeration;
  34. import java.util.List;
  35. import java.util.Map;
  36. /**
  37. * The top-level interface to a <i>keyring:</i> a file that is used to store
  38. * and protect public and private cryptographic keys.
  39. * <p>
  40. * A <i>keyring</i> is modelled as a mapping of one <i>alias</i> to one or
  41. * more <i>entries</i> (optionally of different types).
  42. * <p>
  43. * See also the sub-interfaces {@link IPublicKeyring} and
  44. * {@link IPrivateKeyring} for special types of <i>keyrings</i> --the
  45. * difference being in the type of entries they contain.
  46. */
  47. public interface IKeyring
  48. {
  49. /**
  50. * Property name for the source of data to load the keyring from. The value
  51. * mapped must be a {@link java.io.InputStream}.
  52. */
  53. public static final String KEYRING_DATA_IN = "gnu.crypto.keyring.data.in";
  54. /**
  55. * Property name for the data sink to store the keyring to. The value mapped
  56. * must be a {@link java.io.OutputStream}.
  57. */
  58. public static final String KEYRING_DATA_OUT = "gun.crypto.keyring.data.out";
  59. /**
  60. * Property name for the keyring's top-level password, used to authenticate
  61. * and/or transform the store itself. The mapped value must be a char array.
  62. */
  63. public static final String KEYRING_PASSWORD = "gnu.crypto.keyring.password";
  64. /**
  65. * Loads a keyring into memory.
  66. * <p>
  67. * What happens to the current contents of this keyring? are the new ones
  68. * merged with the current ones or do they simply replace them?
  69. *
  70. * @param attributes The attributes that designate the source where the store
  71. * is to be loaded from. What happens
  72. * @throws IllegalArgumentException If the attributes are inappropriate.
  73. * @throws IOException If the keyring file cannot be read.
  74. * @throws SecurityException If the given password is incorrect, or if the
  75. * top-level authentication or decryption fails.
  76. */
  77. void load(Map attributes) throws IOException;
  78. /**
  79. * Stores the contents of this keyring to persistent storage as specified by
  80. * the designated <code>attributes</code>.
  81. *
  82. * @param attributes the attributes that define where the contents of this
  83. * keyring will be stored.
  84. * @throws IOException if an exception occurs during the process.
  85. */
  86. void store(Map attributes) throws IOException;
  87. /**
  88. * Resets this keyring, clearing all sensitive data. This method always
  89. * suceeds.
  90. */
  91. void reset();
  92. /**
  93. * Returns the number of entries in this keyring.
  94. *
  95. * @return The number of current entries in this keyring.
  96. */
  97. int size();
  98. /**
  99. * Returns an {@link Enumeration} of all aliases (instances of {@link String})
  100. * in this keyring.
  101. *
  102. * @return The enumeration of {@link String}s each representing an <i>alias</i>
  103. * found in this keyring.
  104. */
  105. Enumeration aliases();
  106. /**
  107. * Tests whether or not this keyring contains the given alias.
  108. *
  109. * @param alias The alias to check.
  110. * @return true if this keyring contains the alias.
  111. */
  112. boolean containsAlias(String alias);
  113. /**
  114. * Returns a {@link List} of entries (instances of {@link Entry}) for the
  115. * given <code>alias</code>, or <code>null</code> if there no such entry
  116. * exists.
  117. *
  118. * @param alias The alias of the entry(ies) to return.
  119. * @return A list of all entries (instances of {@link Entry} that have the
  120. * given <code>alias</code>, or <code>null</code> if no one
  121. * {@link Entry} can be found with the designated <code>alias</code>.
  122. */
  123. List get(String alias);
  124. /**
  125. * Adds a designated {@link Entry} to this keyring.
  126. * <p>
  127. * What happens if there is already an entry with the same alias?
  128. *
  129. * @param entry The entry to put in this keyring.
  130. */
  131. void add(Entry entry);
  132. /**
  133. * Removes an entry with the designated <code>alias</code> from this
  134. * keyring. Does nothing if there was no such entry.
  135. * <p>
  136. * What happens if there are more than one?
  137. *
  138. * @param alias The alias of the entry to remove.
  139. */
  140. void remove(String alias);
  141. }