forked from google/u2f-ref-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequesthelper.js
83 lines (73 loc) · 2.08 KB
/
requesthelper.js
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
// Copyright 2014 Google Inc. All rights reserved
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
/**
* @fileoverview Provides a "bottom half" helper to assist with raw requests.
* This fills the same role as the Authenticator-Specific Module component of
* U2F documents, although the API is different.
*/
'use strict';
/**
* @typedef {{
* type: string,
* timeout: number
* }}
*/
var HelperRequest;
/**
* @typedef {{
* type: string,
* code: (number|undefined)
* }}
*/
var HelperReply;
/**
* A helper to process requests.
* @interface
*/
function RequestHelper() {}
/**
* Gets a handler for a request.
* @param {HelperRequest} request The request to handle.
* @return {RequestHandler} A handler for the request.
*/
RequestHelper.prototype.getHandler = function(request) {};
/**
* A handler to track an outstanding request.
* @extends {Closeable}
* @interface
*/
function RequestHandler() {}
/** @typedef {function(HelperReply, string=)} */
var RequestHandlerCallback;
/**
* @param {RequestHandlerCallback} cb Called with the result of the request,
* and an optional source for the result.
* @return {boolean} Whether this handler could be run.
*/
RequestHandler.prototype.run = function(cb) {};
/** Closes this handler. */
RequestHandler.prototype.close = function() {};
/**
* Makes a response to a helper request with an error code.
* @param {HelperRequest} request The request to make a response to.
* @param {DeviceStatusCodes} code The error code to return.
* @param {string=} opt_defaultType The default response type, if none is
* present in the request.
* @return {HelperReply} The helper error response.
*/
function makeHelperErrorResponse(request, code, opt_defaultType) {
var type;
if (request && request.type) {
type = request.type.replace(/_request$/, '_reply');
} else {
type = opt_defaultType || 'unknown_type_reply';
}
var reply = {
'type': type,
'code': /** @type {number} */ (code)
};
return reply;
}