Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2389)

Unified Diff: chrome/browser/resources/cryptotoken/gnubby.js

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/cryptotoken/gnubby.js
diff --git a/chrome/browser/resources/cryptotoken/gnubby.js b/chrome/browser/resources/cryptotoken/gnubby.js
index 410ec29121857509d32a46a9647f89566e32b89e..28910ce98a6e2de4406bd5e0094366b6bddcf099 100644
--- a/chrome/browser/resources/cryptotoken/gnubby.js
+++ b/chrome/browser/resources/cryptotoken/gnubby.js
@@ -49,10 +49,9 @@ Gnubby.setGnubbies = function(gnubbies) {
* @return {string} hexadecimal string.
*/
Gnubby.hexCid = function(cid) {
- var tmp = [(cid >>> 24) & 255,
- (cid >>> 16) & 255,
- (cid >>> 8) & 255,
- (cid >>> 0) & 255];
+ var tmp = [
+ (cid >>> 24) & 255, (cid >>> 16) & 255, (cid >>> 8) & 255, (cid >>> 0) & 255
+ ];
return UTIL_BytesToHex(tmp);
};
@@ -172,10 +171,9 @@ Gnubby.prototype.close = function() {
// Wait a bit in case simpleton client tries open next gnubby.
// Without delay, gnubbies would drop all idle devices, before client
// gets to the next one.
- window.setTimeout(
- function() {
- Gnubby.gnubbies_.removeClient(dev, self);
- }, 300);
+ window.setTimeout(function() {
+ Gnubby.gnubbies_.removeClient(dev, self);
+ }, 300);
}
};
@@ -186,11 +184,13 @@ Gnubby.prototype.close = function() {
Gnubby.prototype.closeWhenIdle = function(cb) {
if (!this.inUse_()) {
this.close();
- if (cb) cb();
+ if (cb)
+ cb();
return;
}
this.closingWhenIdle = true;
- if (cb) this.notifyOnClose.push(cb);
+ if (cb)
+ this.notifyOnClose.push(cb);
};
/**
@@ -222,7 +222,8 @@ Gnubby.prototype.idleClose_ = function() {
Gnubby.prototype.notifyFrame_ = function(cb) {
if (this.rxframes.length != 0) {
// Already have frames; continue.
- if (cb) window.setTimeout(cb, 0);
+ if (cb)
+ window.setTimeout(cb, 0);
} else {
this.rxcb = cb;
}
@@ -235,7 +236,8 @@ Gnubby.prototype.notifyFrame_ = function(cb) {
* frames from its device.
*/
Gnubby.prototype.receivedFrame = function(frame) {
- if (this.closed) return false; // No longer interested.
+ if (this.closed)
+ return false; // No longer interested.
if (!this.checkCID_(frame)) {
// Not for me, ignore.
@@ -247,7 +249,8 @@ Gnubby.prototype.receivedFrame = function(frame) {
// Callback self in case we were waiting. Once.
var cb = this.rxcb;
this.rxcb = null;
- if (cb) window.setTimeout(cb, 0);
+ if (cb)
+ window.setTimeout(cb, 0);
return true;
};
@@ -264,7 +267,8 @@ Gnubby.prototype.getLastReadError = function() {
* @private
*/
Gnubby.prototype.readFrame_ = function() {
- if (this.rxframes.length == 0) throw 'rxframes empty!';
+ if (this.rxframes.length == 0)
+ throw 'rxframes empty!';
var frame = this.rxframes.shift();
return frame;
@@ -277,8 +281,14 @@ Gnubby.prototype.readFrame_ = function() {
* @private
*/
Gnubby.prototype.read_ = function(cmd, timeout, cb) {
- if (this.closed) { cb(-GnubbyDevice.GONE); return; }
- if (!this.dev) { cb(-GnubbyDevice.GONE); return; }
+ if (this.closed) {
+ cb(-GnubbyDevice.GONE);
+ return;
+ }
+ if (!this.dev) {
+ cb(-GnubbyDevice.GONE);
+ return;
+ }
var tid = null; // timeout timer id.
var callback = cb;
@@ -304,16 +314,19 @@ Gnubby.prototype.read_ = function(cmd, timeout, cb) {
var c = callback;
if (c) {
callback = null;
- window.setTimeout(function() { c(a, b); }, 0);
+ window.setTimeout(function() {
+ c(a, b);
+ }, 0);
}
- if (self.closingWhenIdle) self.idleClose_();
+ if (self.closingWhenIdle)
+ self.idleClose_();
}
function read_timeout() {
- if (!callback || !tid) return; // Already done.
+ if (!callback || !tid)
+ return; // Already done.
- console.error(UTIL_fmt(
- '[' + Gnubby.hexCid(self.cid) + '] timeout!'));
+ console.error(UTIL_fmt('[' + Gnubby.hexCid(self.cid) + '] timeout!'));
if (self.dev) {
self.dev.destroy(); // Stop pretending this thing works.
@@ -325,7 +338,8 @@ Gnubby.prototype.read_ = function(cmd, timeout, cb) {
}
function cont_frame() {
- if (!callback || !tid) return; // Already done.
+ if (!callback || !tid)
+ return; // Already done.
var f = new Uint8Array(self.readFrame_());
var rcmd = f[4];
@@ -376,7 +390,8 @@ Gnubby.prototype.read_ = function(cmd, timeout, cb) {
}
function init_frame() {
- if (!callback || !tid) return; // Already done.
+ if (!callback || !tid)
+ return; // Already done.
var f = new Uint8Array(self.readFrame_());
@@ -439,13 +454,13 @@ Gnubby.prototype.read_ = function(cmd, timeout, cb) {
};
/**
- * @const
- */
+ * @const
+ */
Gnubby.NOTIFICATION_CID = 0;
/**
- * @const
- */
+ * @const
+ */
Gnubby.BROADCAST_CID = (0xff << 24) | (0xff << 16) | (0xff << 8) | 0xff;
/**
@@ -455,12 +470,8 @@ Gnubby.BROADCAST_CID = (0xff << 24) | (0xff << 16) | (0xff << 8) | 0xff;
*/
Gnubby.prototype.checkCID_ = function(frame) {
var f = new Uint8Array(frame);
- var c = (f[0] << 24) |
- (f[1] << 16) |
- (f[2] << 8) |
- (f[3]);
- return c === this.cid ||
- c === Gnubby.NOTIFICATION_CID;
+ var c = (f[0] << 24) | (f[1] << 16) | (f[2] << 8) | (f[3]);
+ return c === this.cid || c === Gnubby.NOTIFICATION_CID;
};
/**
@@ -470,8 +481,10 @@ Gnubby.prototype.checkCID_ = function(frame) {
* @private
*/
Gnubby.prototype.write_ = function(cmd, data) {
- if (this.closed) return;
- if (!this.dev) return;
+ if (this.closed)
+ return;
+ if (!this.dev)
+ return;
this.commandPending = true;
@@ -520,8 +533,10 @@ Gnubby.SYS_TIMER_ = new WindowTimer();
Gnubby.defaultCallback = function(rc, data) {
var msg = 'defaultCallback(' + rc;
if (data) {
- if (typeof data == 'string') msg += ', ' + data;
- else msg += ', ' + UTIL_BytesToHex(new Uint8Array(data));
+ if (typeof data == 'string')
+ msg += ', ' + data;
+ else
+ msg += ', ' + UTIL_BytesToHex(new Uint8Array(data));
}
msg += ')';
console.log(UTIL_fmt(msg));
@@ -535,7 +550,8 @@ Gnubby.defaultCallback = function(rc, data) {
* @param {?function(...)} cb Callback
*/
Gnubby.prototype.sync = function(cb) {
- if (!cb) cb = Gnubby.defaultCallback;
+ if (!cb)
+ cb = Gnubby.defaultCallback;
if (this.closed) {
cb(-GnubbyDevice.GONE);
return;
@@ -549,7 +565,8 @@ Gnubby.prototype.sync = function(cb) {
function returnValue(rc) {
done = true;
window.setTimeout(cb.bind(null, rc), 0);
- if (self.closingWhenIdle) self.idleClose_();
+ if (self.closingWhenIdle)
+ self.idleClose_();
}
function callback(rc, opt_frame) {
@@ -569,13 +586,15 @@ Gnubby.prototype.sync = function(cb) {
}
function syncSentinelEquals(f) {
- return (f[4] == GnubbyDevice.CMD_SYNC &&
+ return (
+ f[4] == GnubbyDevice.CMD_SYNC &&
(f.length == 7 || /* fw pre-0.2.1 bug: does not echo sentinel */
f[7] == self.synccnt));
}
function syncCompletionAction(rc, opt_frame) {
- if (rc) console.warn(UTIL_fmt('sync failed: ' + rc));
+ if (rc)
+ console.warn(UTIL_fmt('sync failed: ' + rc));
returnValue(rc);
}
@@ -591,16 +610,15 @@ Gnubby.prototype.sync = function(cb) {
}
function initSentinelEquals(f) {
- return (f[4] == GnubbyDevice.CMD_INIT &&
- f.length >= nonce.length + 7 &&
+ return (
+ f[4] == GnubbyDevice.CMD_INIT && f.length >= nonce.length + 7 &&
UTIL_equalArrays(f.subarray(7, nonce.length + 7), nonce));
}
function initCmdUnsupported(rc) {
// Different firmwares fail differently on different inputs, so treat any
// of the following errors as indicating the INIT command isn't supported.
- return rc == -GnubbyDevice.INVALID_CMD ||
- rc == -GnubbyDevice.INVALID_PAR ||
+ return rc == -GnubbyDevice.INVALID_CMD || rc == -GnubbyDevice.INVALID_PAR ||
rc == -GnubbyDevice.INVALID_LEN;
}
@@ -626,10 +644,8 @@ Gnubby.prototype.sync = function(cb) {
}
// Accept the provided cid.
var offs = HEADER_LENGTH + nonce.length;
- self.cid = (opt_frame[offs] << 24) |
- (opt_frame[offs + 1] << 16) |
- (opt_frame[offs + 2] << 8) |
- opt_frame[offs + 3];
+ self.cid = (opt_frame[offs] << 24) | (opt_frame[offs + 1] << 16) |
+ (opt_frame[offs + 2] << 8) | opt_frame[offs + 3];
returnValue(rc);
}
@@ -637,8 +653,7 @@ Gnubby.prototype.sync = function(cb) {
var f = new Uint8Array(self.readFrame_());
// Stop on errors and return them.
- if (f[4] == GnubbyDevice.CMD_ERROR &&
- f[5] == 0 && f[6] == 1) {
+ if (f[4] == GnubbyDevice.CMD_ERROR && f[5] == 0 && f[6] == 1) {
if (f[7] == GnubbyDevice.BUSY) {
// Not spec but some devices do this; retry.
sendSentinel();
@@ -665,7 +680,8 @@ Gnubby.prototype.sync = function(cb) {
}
function timeoutLoop() {
- if (done) return;
+ if (done)
+ return;
if (trycount == 0) {
// Failed.
@@ -720,7 +736,8 @@ Gnubby.MAX_TIMEOUT = 31;
* @param {?function(...)} cb Callback
*/
Gnubby.prototype.blink = function(data, cb) {
- if (!cb) cb = Gnubby.defaultCallback;
+ if (!cb)
+ cb = Gnubby.defaultCallback;
if (typeof data == 'number') {
var d = new Uint8Array([data]);
data = d.buffer;
@@ -733,7 +750,8 @@ Gnubby.prototype.blink = function(data, cb) {
* @param {?function(...)} cb Callback
*/
Gnubby.prototype.lock = function(data, cb) {
- if (!cb) cb = Gnubby.defaultCallback;
+ if (!cb)
+ cb = Gnubby.defaultCallback;
if (typeof data == 'number') {
var d = new Uint8Array([data]);
data = d.buffer;
@@ -745,28 +763,30 @@ Gnubby.prototype.lock = function(data, cb) {
* @param {?function(...)} cb Callback
*/
Gnubby.prototype.unlock = function(cb) {
- if (!cb) cb = Gnubby.defaultCallback;
+ if (!cb)
+ cb = Gnubby.defaultCallback;
var data = new Uint8Array([0]);
- this.exchange_(GnubbyDevice.CMD_LOCK, data.buffer,
- Gnubby.NORMAL_TIMEOUT, cb);
+ this.exchange_(GnubbyDevice.CMD_LOCK, data.buffer, Gnubby.NORMAL_TIMEOUT, cb);
};
/** Request system information data.
* @param {?function(...)} cb Callback
*/
Gnubby.prototype.sysinfo = function(cb) {
- if (!cb) cb = Gnubby.defaultCallback;
- this.exchange_(GnubbyDevice.CMD_SYSINFO, new ArrayBuffer(0),
- Gnubby.NORMAL_TIMEOUT, cb);
+ if (!cb)
+ cb = Gnubby.defaultCallback;
+ this.exchange_(
+ GnubbyDevice.CMD_SYSINFO, new ArrayBuffer(0), Gnubby.NORMAL_TIMEOUT, cb);
};
/** Send wink command
* @param {?function(...)} cb Callback
*/
Gnubby.prototype.wink = function(cb) {
- if (!cb) cb = Gnubby.defaultCallback;
- this.exchange_(GnubbyDevice.CMD_WINK, new ArrayBuffer(0),
- Gnubby.NORMAL_TIMEOUT, cb);
+ if (!cb)
+ cb = Gnubby.defaultCallback;
+ this.exchange_(
+ GnubbyDevice.CMD_WINK, new ArrayBuffer(0), Gnubby.NORMAL_TIMEOUT, cb);
};
/** Send DFU (Device firmware upgrade) command
@@ -774,7 +794,8 @@ Gnubby.prototype.wink = function(cb) {
* @param {?function(...)} cb Callback
*/
Gnubby.prototype.dfu = function(data, cb) {
- if (!cb) cb = Gnubby.defaultCallback;
+ if (!cb)
+ cb = Gnubby.defaultCallback;
this.exchange_(GnubbyDevice.CMD_DFU, data, Gnubby.NORMAL_TIMEOUT, cb);
};
@@ -783,7 +804,8 @@ Gnubby.prototype.dfu = function(data, cb) {
* @param {?function(...)} cb Callback
*/
Gnubby.prototype.ping = function(data, cb) {
- if (!cb) cb = Gnubby.defaultCallback;
+ if (!cb)
+ cb = Gnubby.defaultCallback;
if (typeof data == 'number') {
var d = new Uint8Array(data);
window.crypto.getRandomValues(d);
@@ -797,7 +819,8 @@ Gnubby.prototype.ping = function(data, cb) {
* @param {?function(...)} cb Callback
*/
Gnubby.prototype.apdu = function(data, cb) {
- if (!cb) cb = Gnubby.defaultCallback;
+ if (!cb)
+ cb = Gnubby.defaultCallback;
this.exchange_(GnubbyDevice.CMD_APDU, data, Gnubby.MAX_TIMEOUT, cb);
};
@@ -805,9 +828,10 @@ Gnubby.prototype.apdu = function(data, cb) {
* @param {?function(...)} cb Callback
*/
Gnubby.prototype.reset = function(cb) {
- if (!cb) cb = Gnubby.defaultCallback;
- this.exchange_(GnubbyDevice.CMD_ATR, new ArrayBuffer(0),
- Gnubby.MAX_TIMEOUT, cb);
+ if (!cb)
+ cb = Gnubby.defaultCallback;
+ this.exchange_(
+ GnubbyDevice.CMD_ATR, new ArrayBuffer(0), Gnubby.MAX_TIMEOUT, cb);
};
// byte args[3] = [delay-in-ms before disabling interrupts,
@@ -818,10 +842,11 @@ Gnubby.prototype.reset = function(cb) {
* @param {?function(...)} cb Callback
*/
Gnubby.prototype.usb_test = function(args, cb) {
- if (!cb) cb = Gnubby.defaultCallback;
+ if (!cb)
+ cb = Gnubby.defaultCallback;
var u8 = new Uint8Array(args);
- this.exchange_(GnubbyDevice.CMD_USB_TEST, u8.buffer,
- Gnubby.NORMAL_TIMEOUT, cb);
+ this.exchange_(
+ GnubbyDevice.CMD_USB_TEST, u8.buffer, Gnubby.NORMAL_TIMEOUT, cb);
};
/** APDU command with reply
@@ -830,7 +855,8 @@ Gnubby.prototype.usb_test = function(args, cb) {
* @param {boolean=} opt_nowink Do not wink
*/
Gnubby.prototype.apduReply = function(request, cb, opt_nowink) {
- if (!cb) cb = Gnubby.defaultCallback;
+ if (!cb)
+ cb = Gnubby.defaultCallback;
var self = this;
this.apdu(request, function(rc, data) {
@@ -846,7 +872,9 @@ Gnubby.prototype.apduReply = function(request, cb, opt_nowink) {
rc = r8[r8.length - 2] * 256 + r8[r8.length - 1];
// wink gnubby at hand if it needs touching.
if (rc == 0x6985 && !opt_nowink) {
- self.wink(function() { cb(rc); });
+ self.wink(function() {
+ cb(rc);
+ });
return;
}
}

Powered by Google App Engine
This is Rietveld 408576698