3
3
4
4
namespace builtins {
5
5
6
+ CryptoKeyUsages::CryptoKeyUsages (uint8_t mask) { this ->mask = mask; };
7
+ CryptoKeyUsages::CryptoKeyUsages (bool encrypt, bool decrypt, bool sign, bool verify,
8
+ bool derive_key, bool derive_bits, bool wrap_key,
9
+ bool unwrap_key) {
10
+ this ->mask = 0 ;
11
+ if (encrypt) {
12
+ this ->mask |= encrypt_flag;
13
+ }
14
+ if (decrypt) {
15
+ this ->mask |= decrypt_flag;
16
+ }
17
+ if (sign) {
18
+ this ->mask |= sign_flag;
19
+ }
20
+ if (verify) {
21
+ this ->mask |= verify_flag;
22
+ }
23
+ if (derive_key) {
24
+ this ->mask |= derive_key_flag;
25
+ }
26
+ if (derive_bits) {
27
+ this ->mask |= derive_bits_flag;
28
+ }
29
+ if (wrap_key) {
30
+ this ->mask |= wrap_key_flag;
31
+ }
32
+ if (unwrap_key) {
33
+ this ->mask |= unwrap_key_flag;
34
+ }
35
+ };
36
+
6
37
bool CryptoKey::algorithm_get (JSContext *cx, unsigned argc, JS::Value *vp) {
7
38
METHOD_HEADER (0 );
8
39
@@ -114,7 +145,7 @@ bool CryptoKey::usages_get(JSContext *cx, unsigned argc, JS::Value *vp) {
114
145
}
115
146
// Else, grab the CryptoKeyUsageBitmap value from Slots::Usages and convert
116
147
// it into a JS Array and store the result in Slots::UsagesArray.
117
- auto usage = JS::GetReservedSlot (self, Slots::Usages).toInt32 ();
148
+ auto usage = CryptoKeyUsages ( JS::GetReservedSlot (self, Slots::Usages).toInt32 () );
118
149
// The result is ordered alphabetically.
119
150
JS::RootedValueVector result (cx);
120
151
JS::RootedString str (cx);
@@ -128,42 +159,42 @@ bool CryptoKey::usages_get(JSContext *cx, unsigned argc, JS::Value *vp) {
128
159
}
129
160
return true ;
130
161
};
131
- if (usage & CryptoKeyUsageDecrypt ) {
162
+ if (usage. canDecrypt () ) {
132
163
if (!append (" decrypt" )) {
133
164
return false ;
134
165
}
135
166
}
136
- if (usage & CryptoKeyUsageDeriveBits ) {
167
+ if (usage. canDeriveBits () ) {
137
168
if (!append (" deriveBits" )) {
138
169
return false ;
139
170
}
140
171
}
141
- if (usage & CryptoKeyUsageDeriveKey ) {
172
+ if (usage. canDeriveKey () ) {
142
173
if (!append (" deriveKey" )) {
143
174
return false ;
144
175
}
145
176
}
146
- if (usage & CryptoKeyUsageEncrypt ) {
177
+ if (usage. canEncrypt () ) {
147
178
if (!append (" encrypt" )) {
148
179
return false ;
149
180
}
150
181
}
151
- if (usage & CryptoKeyUsageSign ) {
182
+ if (usage. canSign () ) {
152
183
if (!append (" sign" )) {
153
184
return false ;
154
185
}
155
186
}
156
- if (usage & CryptoKeyUsageUnwrapKey ) {
187
+ if (usage. canUnwrapKey () ) {
157
188
if (!append (" unwrapKey" )) {
158
189
return false ;
159
190
}
160
191
}
161
- if (usage & CryptoKeyUsageVerify ) {
192
+ if (usage. canVerify () ) {
162
193
if (!append (" verify" )) {
163
194
return false ;
164
195
}
165
196
}
166
- if (usage & CryptoKeyUsageWrapKey ) {
197
+ if (usage. canWrapKey () ) {
167
198
if (!append (" wrapKey" )) {
168
199
return false ;
169
200
}
0 commit comments