Source: digest-sha256-signature.js

  1. /**
  2. * This class represents an NDN Data Signature object.
  3. * Copyright (C) 2014-2016 Regents of the University of California.
  4. * @author: Jeff Thompson <jefft0@remap.ucla.edu>
  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 DigestSha256Signature extends Signature and holds the signature bits (which
  24. * are only the SHA256 digest) and an empty SignatureInfo for a data packet or
  25. * signed interest.
  26. *
  27. * Create a new DigestSha256Signature object, possibly copying values from
  28. * another object.
  29. *
  30. * @param {DigestSha256Signature} value (optional) If value is a
  31. * DigestSha256Signature, copy its values. If value is omitted, the signature
  32. * is unspecified.
  33. * @constructor
  34. */
  35. var DigestSha256Signature = function DigestSha256Signature(value)
  36. {
  37. if (typeof value === 'object' && value instanceof DigestSha256Signature)
  38. // Copy the values.
  39. this.signature_ = value.signature_;
  40. else
  41. this.signature_ = new Blob();
  42. this.changeCount_ = 0;
  43. };
  44. exports.DigestSha256Signature = DigestSha256Signature;
  45. /**
  46. * Create a new DigestSha256Signature which is a copy of this object.
  47. * @returns {DigestSha256Signature} A new object which is a copy of this object.
  48. */
  49. DigestSha256Signature.prototype.clone = function()
  50. {
  51. return new DigestSha256Signature(this);
  52. };
  53. /**
  54. * Get the signature bytes (which are only the digest).
  55. * @returns {Blob} The signature bytes. If not specified, the value isNull().
  56. */
  57. DigestSha256Signature.prototype.getSignature = function()
  58. {
  59. return this.signature_;
  60. };
  61. /**
  62. * Set the signature bytes to the given value.
  63. * @param {Blob} signature
  64. */
  65. DigestSha256Signature.prototype.setSignature = function(signature)
  66. {
  67. this.signature_ = typeof signature === 'object' && signature instanceof Blob ?
  68. signature : new Blob(signature);
  69. ++this.changeCount_;
  70. };
  71. /**
  72. * Get the change count, which is incremented each time this object is changed.
  73. * @returns {number} The change count.
  74. */
  75. DigestSha256Signature.prototype.getChangeCount = function()
  76. {
  77. return this.changeCount_;
  78. };
  79. // Define properties so we can change member variable types and implement changeCount_.
  80. /**
  81. * @@deprecated Use getSignature and setSignature.
  82. */
  83. Object.defineProperty(DigestSha256Signature.prototype, "signature",
  84. { get: function() { return this.getSignature(); },
  85. set: function(val) { this.setSignature(val); } });