nsICryptoHash.idl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "nsISupports.idl"
  5. interface nsIInputStream;
  6. /**
  7. * nsICryptoHash
  8. * This interface provides crytographic hashing algorithms.
  9. */
  10. [scriptable, uuid(0a248513-dfa7-4474-8777-8c452d60dd04)]
  11. interface nsICryptoHash : nsISupports
  12. {
  13. /**
  14. * Hashing Algorithms. These values are to be used by the
  15. * |init| method to indicate which hashing function to
  16. * use. These values map directly onto the values defined
  17. * in mozilla/security/nss/lib/cryptohi/hasht.h.
  18. */
  19. const short MD2 = 1; /* String value: "md2" */
  20. const short MD5 = 2; /* String value: "md5" */
  21. const short SHA1 = 3; /* String value: "sha1" */
  22. const short SHA256 = 4; /* String value: "sha256" */
  23. const short SHA384 = 5; /* String value: "sha384" */
  24. const short SHA512 = 6; /* String value: "sha512" */
  25. const short SHA224 = 7; /* String value: "sha224" */
  26. /**
  27. * Initialize the hashing object. This method may be
  28. * called multiple times with different algorithm types.
  29. *
  30. * @param aAlgorithm the algorithm type to be used.
  31. * This value must be one of the above valid
  32. * algorithm types.
  33. *
  34. * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm
  35. * type is passed.
  36. *
  37. * NOTE: This method or initWithString must be called
  38. * before any other method on this interface is called.
  39. */
  40. void init(in unsigned long aAlgorithm);
  41. /**
  42. * Initialize the hashing object. This method may be
  43. * called multiple times with different algorithm types.
  44. *
  45. * @param aAlgorithm the algorithm type to be used.
  46. *
  47. * @throws NS_ERROR_INVALID_ARG if an unsupported algorithm
  48. * type is passed.
  49. *
  50. * NOTE: This method or init must be called before any
  51. * other method on this interface is called.
  52. */
  53. void initWithString(in ACString aAlgorithm);
  54. /**
  55. * @param aData a buffer to calculate the hash over
  56. *
  57. * @param aLen the length of the buffer |aData|
  58. *
  59. * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been
  60. * called.
  61. */
  62. void update([const, array, size_is(aLen)] in octet aData, in unsigned long aLen);
  63. /**
  64. * Calculates and updates a new hash based on a given data stream.
  65. *
  66. * @param aStream an input stream to read from.
  67. *
  68. * @param aLen how much to read from the given |aStream|. Passing
  69. * UINT32_MAX indicates that all data available will be used
  70. * to update the hash.
  71. *
  72. * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been
  73. * called.
  74. *
  75. * @throws NS_ERROR_NOT_AVAILABLE if the requested amount of
  76. * data to be calculated into the hash is not available.
  77. *
  78. */
  79. void updateFromStream(in nsIInputStream aStream, in unsigned long aLen);
  80. /**
  81. * Completes this hash object and produces the actual hash data.
  82. *
  83. * @param aASCII if true then the returned value is a base-64
  84. * encoded string. if false, then the returned value is
  85. * binary data.
  86. *
  87. * @return a hash of the data that was read by this object. This can
  88. * be either binary data or base 64 encoded.
  89. *
  90. * @throws NS_ERROR_NOT_INITIALIZED if |init| has not been
  91. * called.
  92. *
  93. * NOTE: This method may be called any time after |init|
  94. * is called. This call resets the object to its
  95. * pre-init state.
  96. */
  97. ACString finish(in boolean aASCII);
  98. };