Source: encrypt/decrypt-key.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/decrypt-key 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 Blob = require('../util/blob.js').Blob;
  22. /**
  23. * A DecryptKey supplies the key for decrypt.
  24. * Create a DecryptKey with the given key value.
  25. * @param {Blob|DecryptKey} value If value is another DecryptKey then copy it.
  26. * Otherwise, value is the key value.
  27. * @note This class is an experimental feature. The API may change.
  28. * @constructor
  29. */
  30. var DecryptKey = function DecryptKey(value)
  31. {
  32. if (typeof value === 'object' && value instanceof DecryptKey) {
  33. // Make a deep copy.
  34. this.keyBits_ = value.keyBits_;
  35. }
  36. else {
  37. var keyBits = value;
  38. this.keyBits_ = typeof keyBits === 'object' && keyBits instanceof Blob ?
  39. keyBits : new Blob(keyBits);
  40. }
  41. };
  42. exports.DecryptKey = DecryptKey;
  43. /**
  44. * Get the key value.
  45. * @return {Blob} The key value.
  46. */
  47. DecryptKey.prototype.getKeyBits = function() { return this.keyBits_; };