This repository was archived by the owner on Oct 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathsha256-with-rsa-signature.js
More file actions
163 lines (148 loc) · 5.42 KB
/
sha256-with-rsa-signature.js
File metadata and controls
163 lines (148 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* This class represents an NDN Data Signature object.
* Copyright (C) 2014-2019 Regents of the University of California.
* @author: Meki Cheraoui
* @author: Jeff Thompson <jefft0@remap.ucla.edu>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* A copy of the GNU Lesser General Public License is in the file COPYING.
*/
/** @ignore */
var Blob = require('./util/blob.js').Blob; /** @ignore */
var ChangeCounter = require('./util/change-counter.js').ChangeCounter; /** @ignore */
var KeyLocator = require('./key-locator.js').KeyLocator; /** @ignore */
var ValidityPeriod = require('./security/validity-period.js').ValidityPeriod;
/**
* Create a new Sha256WithRsaSignature object, possibly copying values from
* another object.
*
* @param {Sha256WithRsaSignature} value (optional) If value is a
* Sha256WithRsaSignature, copy its values. If value is omitted, the keyLocator
* is the default with unspecified values and the signature is unspecified.
* @constructor
*/
var Sha256WithRsaSignature = function Sha256WithRsaSignature(value)
{
if (typeof value === 'object' && value instanceof Sha256WithRsaSignature) {
// Copy the values.
this.keyLocator_ = new ChangeCounter(new KeyLocator(value.getKeyLocator()));
this.validityPeriod_ = new ChangeCounter(new ValidityPeriod
(value.getValidityPeriod()));
this.signature_ = value.signature_;
}
else {
this.keyLocator_ = new ChangeCounter(new KeyLocator());
this.validityPeriod_ = new ChangeCounter(new ValidityPeriod());
this.signature_ = new Blob();
}
this.changeCount_ = 0;
};
exports.Sha256WithRsaSignature = Sha256WithRsaSignature;
/**
* Create a new Sha256WithRsaSignature which is a copy of this object.
* @return {Sha256WithRsaSignature} A new object which is a copy of this object.
*/
Sha256WithRsaSignature.prototype.clone = function()
{
return new Sha256WithRsaSignature(this);
};
/**
* Get the key locator.
* @return {KeyLocator} The key locator.
*/
Sha256WithRsaSignature.prototype.getKeyLocator = function()
{
return this.keyLocator_.get();
};
/**
* Get the validity period.
* @return {ValidityPeriod} The validity period.
*/
Sha256WithRsaSignature.prototype.getValidityPeriod = function()
{
return this.validityPeriod_.get();
};
/**
* Get the data packet's signature bytes.
* @return {Blob} The signature bytes. If not specified, the value isNull().
*/
Sha256WithRsaSignature.prototype.getSignature = function()
{
return this.signature_;
};
/**
* @deprecated Use getSignature. This method returns a Buffer which is the former
* behavior of getSignature, and should only be used while updating your code.
*/
Sha256WithRsaSignature.prototype.getSignatureAsBuffer = function()
{
return this.signature_.buf();
};
/**
* Set the key locator to a copy of the given keyLocator.
* @param {KeyLocator} keyLocator The KeyLocator to copy.
*/
Sha256WithRsaSignature.prototype.setKeyLocator = function(keyLocator)
{
this.keyLocator_.set(typeof keyLocator === 'object' &&
keyLocator instanceof KeyLocator ?
new KeyLocator(keyLocator) : new KeyLocator());
++this.changeCount_;
};
/**
* Set the validity period to a copy of the given ValidityPeriod.
* @param {ValidityPeriod} validityPeriod The ValidityPeriod which is copied.
*/
Sha256WithRsaSignature.prototype.setValidityPeriod = function(validityPeriod)
{
this.validityPeriod_.set(typeof validityPeriod === 'object' &&
validityPeriod instanceof ValidityPeriod ?
new ValidityPeriod(validityPeriod) : new ValidityPeriod());
++this.changeCount_;
};
/**
* Set the data packet's signature bytes.
* @param {Blob} signature
*/
Sha256WithRsaSignature.prototype.setSignature = function(signature)
{
this.signature_ = typeof signature === 'object' && signature instanceof Blob ?
signature : new Blob(signature);
++this.changeCount_;
};
/**
* Get the change count, which is incremented each time this object (or a child
* object) is changed.
* @return {number} The change count.
*/
Sha256WithRsaSignature.prototype.getChangeCount = function()
{
// Make sure each of the checkChanged is called.
var changed = this.keyLocator_.checkChanged();
changed = this.validityPeriod_.checkChanged() || changed;
if (changed)
// A child object has changed, so update the change count.
++this.changeCount_;
return this.changeCount_;
};
// Define properties so we can change member variable types and implement changeCount_.
Object.defineProperty(Sha256WithRsaSignature.prototype, "keyLocator",
{ get: function() { return this.getKeyLocator(); },
set: function(val) { this.setKeyLocator(val); } });
/**
* @@deprecated Use getSignature and setSignature.
*/
Object.defineProperty(Sha256WithRsaSignature.prototype, "signature",
{ get: function() { return this.getSignatureAsBuffer(); },
set: function(val) { this.setSignature(val); } });