Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmessage.js
More file actions
426 lines (375 loc) · 14.7 KB
/
Copy pathmessage.js
File metadata and controls
426 lines (375 loc) · 14.7 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
'use strict';
var mutableMapping = require('./MutableMapping');
var DecodeError = require('./lib/DecodeError');
var InvalidAlgorithmException = require('./lib/InvalidAlgorithmException');
var KeyError = require('./lib/KeyError');
var MissingRequiredAttributeError = require('./lib/MissingRequiredAttributeError');
var NotAllowedValueError = require('./lib/NotAllowedValueError');
var ParameterError = require('./lib/ParameterError');
var TooManyValuesError = require('./lib/TooManyValuesError');
var TypeError = require('./lib/TypeError');
var UnicodeEncodeError = require('./lib/UnicodeEncodeError');
var KeyIOError = require('./lib/KeyIOError');
var MessageException = require('./lib/MessageException');
var NoSuitableSigningKeysError = require('./lib/NoSuitableSigningKeysError');
var message = Message.prototype;
message = Object.create(mutableMapping);
message.constructor = Message;
function Message(kwargs){
};
message.c_param = {};
message.c_default = {};
message.c_allowed_values = {};
message.parameters = function(){
/** Returns a list of all known parameters for this message type.
:return: list of parameter names */
throw new Error("Unsupported Operation Exception");
};
message.setDefaults = function(){
/** Based on specification set a parameters value to the default value. */
throw new Error("Unsupported Operation Exception");
};
message.toUrlEncoded = function(level){
/** Creates a string using the application/x-www-form-urlencoded format
:return: A string of the application/x-www-form-urlencoded format */
try{
throw new Error("Unsupported Operation Exception");
} catch (e){
if (e instanceof MissingRequiredAttributeError){
// Statements to handle error
} else if (e instanceof InvalidKeyException){
// Statements to handle error
} else if (e instanceof InvalidValueError){
// Statements to handle error
} else if (e instanceof TypeError){
// Statements to handle error
} else if (e instanceof UnicodeEncodeError){
// Statements to handle error
} else {
// statements to handle error
}
}
};
message.fromUrlEncoded = function(urlEncoded, kwargs){
/** Starting with a string of the application/x-www-form-urlencoded format
this method creates a class instance
:param urlencoded: The string
:return: A class instance or raise an exception on error */
try{
throw new Error("Unsupported Operation Exception");
} catch (e){
if (e instanceof InvalidKeyException){
// Statements to handle error
} else if (e instanceof InvalidValueError){
// Statements to handle error
} else if (e instanceof ParameterError){
// Statements to handle error
} else if (e instanceof TooManyValuesError){
// Statements to handle error
} else {
// statements to handle error
}
}
};
message.serialize = function(method="urlencoded", lev=0, kwargs){
/** Convert this instance to another representation. Which representation
is given by the choice of serialization method.
:param method: A serialization method. Presently 'urlencoded', 'json',
'jwt' and 'dict' is supported.
:param lev:
:param kwargs: Extra key word arguments
:return: THe content of this message serialized using a chosen method */
throw new Error("Unsupported Operation Exception");
};
message.deserialize = function(info, method="urlencoded", kwargs){
/** Convert from an external representation to an internal.
:param info: The input
:param method: The method used to deserialize the info
:param kwargs: extra Keyword arguments
:return: In the normal case the Message instance */
throw new Error("Unsupported Operation Exception");
}
message.toDict = function(lev){
/** Return a dictionary representation of the class
:return: A dict */
try{
throw new Error("Unsupported Operation Exception");
} catch (e){
if (e instanceof InvalidKeyException){
// Statements to handle error
} else if (e instanceof InvalidValueError){
// Statements to handle error
} else {
// statements to handle error
}
}
};
message.fromDict = function(dictionary, kwargs){
/** Direct translation, so the value for one key might be a list or a
single value.
:param dictionary: The info
:return: A class instance or raise an exception on error*/
try{
throw new Error("Unsupported Operation Exception");
} catch (e){
if (e instanceof InvalidKeyException){
// Statements to handle error
} else if (e instanceof InvalidValueError){
// Statements to handle error
} else {
// statements to handle error
}
}
};
message.addValue = function(sKey, vTyp, key, val,_deser, isNullAllowed){
/** Main method for adding a value to the instance. Does all the
checking on type of value and if among allowed values.
:param sKey: string version of the key
:param vTyp: Type of value
:param key: original representation of the key
:param val: The value to add
:param _deser: A deserializer for this value type
:param isNullAllowed: Whether null is an allowed value for this key */
try{
throw new Error("Unsupported Operation Exception");
} catch (e){
if (e instanceof DecodeError){
// Statements to handle error
} else if (e instanceof InvalidValue){
// Statements to handle error
} else if (e instanceof IllegalArgumentException){
// Statements to handle error
} else if (e instanceof TooManyValues){
// Statements to handle error
} else {
// statements to handle error
}
}
};
message.toJson = function(lev, indent){
/** Serialize the content of this instance into a JSON string.
:param lev:
:param indent: Number of spaces that should be used for indentation
:return: */
throw new Error("Unsupported Operation Exception");
};
message.fromJson = function(txt){
/** Convert from a JSON string to an instance of this class.
:param txt: The JSON string
:param kwargs: extra keyword arguments
:return: The instantiated instance */
throw new Error("Unsupported Operation Exception");
};
message.toJwt = function(key=None, algorithm="", lev=0){
/** Create a signed JWT representation of the class instance
:param key: The signing key
:param algorithm: The signature algorithm to use
:param lev:
:param lifetime: The lifetime of the JWS
:return: A signed JWT */
throw new Error("Unsupported Operation Exception");
};
message.fromJwt = function(txt, key=None, verify=True, keyjar=None, kwargs){
/** Given a signed and/or encrypted JWT, verify its correctness and then
create a class instance from the content.
:param txt: The JWT
:param key: keys that might be used to decrypt and/or verify the
signature of the JWT
:param verify: Whether the signature should be verified or not
:param keyjar: A KeyJar that might contain the necessary key.
:param kwargs: Extra key word arguments
:return: A class instance */
try{
throw new Error("Unsupported Operation Exception");
} catch (e){
if (e instanceof AssertionError){
// Statements to handle error
} else if (e instanceof InvalidAlgorithmException){
// Statements to handle error
} else if (e instanceof InvalidSignatureValueException){
// Statements to handle error
} else if (e instanceof InvalidKeyException){
// Statements to handle error
} else {
// statements to handle error
}
}
};
message.addKey = function(keyjar, issuer, key, keyType="", kid="", noKidIssuer=None){
try{
throw new Error("Unsupported Operation Exception");
}catch (e){
if (e instanceof KeyError){
// Statements to handle error
} else {
// statements to handle error
}
}
};
message.getVerifyKeys = function(keyjar, key, jso, header, jwt, kwargs){
try{
throw new Error("Unsupported Operation Exception");
}catch (e){
if (e instanceof KeyError){
// Statements to handle error
} else {
// statements to handle error
}
}
};
message.typeCheck = function(type, allowed, val, na){
try{
throw new Error("Unsupported Operation Exception");
} catch (e){
if (e instanceof NotAllowedValueError){
// Statements to handle error
} else {
// statements to handle error
}
}
};
message.verify = function(kwargs){
/** Make sure all the required values are there and that the values are
of the correct type */
try{
throw new Error("Unsupported Operation Exception");
} catch (e){
if (e instanceof KeyError){
// Statements to handle error
} else if (e instanceof MissingRequiredAttributeError){
// Statements to handle error
} else if (e instanceof InvalidValueError){
// Statements to handle error
} else if (e instanceof NotAllowedValueError){
// Statements to handle error
} else {
// statements to handle error
}
}
};
message.getKeys= function(){
/** Return a list of attribute/keys/parameters of this class that has
values. */
throw new Error("Unsupported Operation Exception");
};
message.getItem = function(item){
/** Return the value of a specified parameter. */
throw new Error("Unsupported Operation Exception");
};
message.get = function(item, defaultValue){
/** Return the value of a specific parameter. If the parameter does not
have a value return the default value.
:param item: The name of the parameter
:param default: Default value
:return: The value of the parameter or, if that doesn't exist,
the default value */
try{
throw new Error("Unsupported Operation Exception");
} catch (e){
if (e instanceof KeyError){
// Statements to handle error
} else {
// statements to handle error
}
}
};
message.getItems = function(){
/** Return a list of tuples (key, value) representing all parameters
of this class instance that has a value.
:return: iterator */
throw new Error("Unsupported Operation Exception");
};
message.getValues = function(){
throw new Error("Unsupported Operation Exception");
};
message.request = function(location, fragmentEnc){
/** Given a URL this method will add a fragment, a query part or extend
a query part if it already exists with the information in this instance.
:param location: A URL
:param fragmentEnc: Whether the information should be placed in a
fragment (True) or in a query part (False)
:return: The extended URL */
throw new Error("Unsupported Operation Exception");
};
message.setItem = function(key, value){
try{
throw new Error("Unsupported Operation Exception");
} catch (e){
if (e instanceof KeyError){
// Statements to handle error
} else {
// statements to handle error
}
};
message.equals = function(other){
/** Compare two message instances. This with another instance.
:param other: The other instance
:return: True/False */
throw new Error("Unsupported Operation Exception");
};
message.deleteItem = function(key){
throw new Error("Unsupported Operation Exception");
};
message.getLength = function(){
/** Return the number of parameters that has a value.
:return: Number of parameters with a value. */
throw new Error("Unsupported Operation Exception");
};
message.extra = function(){
/** Return the extra parameters that this instance. Extra meaning those
that are not listed in the c_params specification.
:return: The key,value pairs for keys that are not in the c_params
specification. */
throw new Error("Unsupported Operation Exception");
};
message.onlyExtras = function(){
/** Return True if this instance only has key,value pairs for keys
that are not defined in c_params.
:return: True/False */
throw new Error("Unsupported Operation Exception");
};
message.update = function(item){
/** Update the information in this instance.
:param item: a dictionary or a Message instance */
try{
throw new Error("Unsupported Operation Exception");
} catch (e){
if (e instanceof InvalidValue){
// Statements to handle error
} else {
// statements to handle error
}
}
};
message.toJWE = function(keys, enc, alg, lev){
/** Place the information in this instance in a JSON object. Make that
JSON object the body of a JWT. Then encrypt that JWT using the
specified algorithms and the given keys. Return the encrypted JWT.
:param keys: Dictionary, keys are key type and key is the value or
simple list.
:param enc: Content Encryption Algorithm
:param alg: Key Management Algorithm
:param lev: Used for JSON construction
:return: An encrypted JWT. If encryption failed an exception will be
raised. */
throw new Error("Unsupported Operation Exception");
};
message.fromJWE = function(msg, keys){
/** Decrypt an encrypted JWT and load the JSON object that was the body
of the JWT into this object.
:param msg: An encrypted JWT
:param keys: Dictionary, keys are key type and key is the value or
simple list.
:return: The decrypted message. If decryption failed an exception
will be raised. */
throw new Error("Unsupported Operation Exception");
};
message.weed = function(){
/** Get rid of key value pairs that are not standard */
throw new Error("Unsupported Operation Exception");
};
message.removeBlanks = function(){
/** Get rid of parameters that has no value. */
throw new Error("Unsupported Operation Exception");
};
module.exports = message;
You can’t perform that action at this time.
