Source: encrypt/consumer-db.js

  1. /**
  2. * Copyright (C) 2015-2018 Regents of the University of California.
  3. * @author: Jeff Thompson <jefft0@remap.ucla.edu>
  4. * @author: From ndn-group-encrypt src/consumer-db https://github.com/named-data/ndn-group-encrypt
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. * A copy of the GNU Lesser General Public License is in the file COPYING.
  19. */
  20. /** @ignore */
  21. var SyncPromise = require('../util/sync-promise.js').SyncPromise;
  22. /**
  23. * ConsumerDb is a base class the storage of decryption keys for the consumer. A
  24. * subclass must implement the methods. For example, see Sqlite3ConsumerDb (for
  25. * Nodejs) or IndexedDbConsumerDb (for the browser).
  26. * @note This class is an experimental feature. The API may change.
  27. * @constructor
  28. */
  29. var ConsumerDb = function ConsumerDb()
  30. {
  31. };
  32. exports.ConsumerDb = ConsumerDb;
  33. /**
  34. * Create a new ConsumerDb.Error to report an error using ConsumerDb
  35. * methods, wrapping the given error object.
  36. * Call with: throw new ConsumerDb.Error(new Error("message")).
  37. * @constructor
  38. * @param {Error} error The exception created with new Error.
  39. */
  40. ConsumerDb.Error = function ConsumerDbError(error)
  41. {
  42. if (error) {
  43. error.__proto__ = ConsumerDb.Error.prototype;
  44. return error;
  45. }
  46. };
  47. ConsumerDb.Error.prototype = new Error();
  48. ConsumerDb.Error.prototype.name = "ConsumerDbError";
  49. /**
  50. * Get the key with keyName from the database.
  51. * @param {Name} keyName The key name.
  52. * @param {boolean} useSync (optional) If true then return a SyncPromise which
  53. * is already fulfilled. If omitted or false, this may return a SyncPromise or
  54. * an async Promise.
  55. * @return {Promise|SyncPromise} A promise that returns a Blob with the encoded
  56. * key (or an isNull Blob if cannot find the key with keyName), or that is
  57. * rejected with ConsumerDb.Error for a database error.
  58. */
  59. ConsumerDb.prototype.getKeyPromise = function(keyName, useSync)
  60. {
  61. return SyncPromise.reject(new Error
  62. ("ConsumerDb.getKeyPromise is not implemented"));
  63. };
  64. /**
  65. * Add the key with keyName and keyBlob to the database.
  66. * @param {Name} keyName The key name.
  67. * @param {Blob} keyBlob The encoded key.
  68. * @param {boolean} useSync (optional) If true then return a SyncPromise which
  69. * is already fulfilled. If omitted or false, this may return a SyncPromise or
  70. * an async Promise.
  71. * @return {Promise|SyncPromise} A promise that fulfills when the key is added,
  72. * or that is rejected with ConsumerDb.Error if a key with the same keyName
  73. * already exists, or other database error.
  74. */
  75. ConsumerDb.prototype.addKeyPromise = function(keyName, keyBlob, useSync)
  76. {
  77. return SyncPromise.reject(new Error
  78. ("ConsumerDb.addKeyPromise is not implemented"));
  79. };
  80. /**
  81. * Delete the key with keyName from the database. If there is no key with
  82. * keyName, do nothing.
  83. * @param {Name} keyName The key name.
  84. * @param {boolean} useSync (optional) If true then return a SyncPromise which
  85. * is already fulfilled. If omitted or false, this may return a SyncPromise or
  86. * an async Promise.
  87. * @return {Promise|SyncPromise} A promise that fulfills when the key is deleted
  88. * (or there is no such key), or that is rejected with ConsumerDb.Error for a
  89. * database error.
  90. */
  91. ConsumerDb.prototype.deleteKeyPromise = function(keyName, useSync)
  92. {
  93. return SyncPromise.reject(new Error
  94. ("ConsumerDb.addKeyPromise is not implemented"));
  95. };