/** @private {boolean} */
this.challengesSet_ = false;
- /** @private {!Array.<string>} */
- this.notForMe_ = [];
+ /** @private {!Object.<string, number>} */
+ this.cachedError_ = [];
}
/** @enum {number} */
// TODO: This won't be confused with success, but should it be
// part of the same namespace as the other error codes, which are
// always in DeviceStatusCodes.*?
- this.goToError_(rc);
+ this.goToError_(rc, true);
}
};
*/
SingleGnubbySigner.prototype.versionCallback_ = function(rc, opt_data) {
if (rc) {
- this.goToError_(rc);
+ this.goToError_(rc, true);
return;
}
this.state_ = SingleGnubbySigner.State.IDLE;
var challengeHash = challenge.challengeHash;
var appIdHash = challenge.appIdHash;
var keyHandle = challenge.keyHandle;
- if (this.notForMe_.indexOf(keyHandle) != -1) {
+ if (this.cachedError_.hasOwnProperty(keyHandle)) {
// Cache hit: return wrong data again.
- this.signCallback_(challengeIndex, DeviceStatusCodes.WRONG_DATA_STATUS);
+ this.signCallback_(challengeIndex, this.cachedError_[keyHandle]);
} else if (challenge.version && challenge.version != this.version_) {
// Sign challenge for a different version of gnubby: return wrong data.
this.signCallback_(challengeIndex, DeviceStatusCodes.WRONG_DATA_STATUS);
return;
}
- // Cache wrong data result, re-asking the gnubby to sign it won't produce
- // different results.
- if (code == DeviceStatusCodes.WRONG_DATA_STATUS) {
+ // Cache wrong data or wrong length results, re-asking the gnubby to sign it
+ // won't produce different results.
+ if (code == DeviceStatusCodes.WRONG_DATA_STATUS ||
+ code == DeviceStatusCodes.WRONG_LENGTH_STATUS) {
if (challengeIndex < this.challenges_.length) {
var challenge = this.challenges_[challengeIndex];
- if (this.notForMe_.indexOf(challenge.keyHandle) == -1) {
- this.notForMe_.push(challenge.keyHandle);
+ if (!this.cachedError_.hasOwnProperty(challenge.keyHandle)) {
+ this.cachedError_[challenge.keyHandle] = code;
}
}
}
break;
case DeviceStatusCodes.WRONG_DATA_STATUS:
+ case DeviceStatusCodes.WRONG_LENGTH_STATUS:
if (this.challengeIndex_ < this.challenges_.length - 1) {
this.doSign_(++this.challengeIndex_);
} else if (this.forEnroll_) {
default:
if (this.forEnroll_) {
- this.goToError_(code);
+ this.goToError_(code, true);
} else if (this.challengeIndex_ < this.challenges_.length - 1) {
this.doSign_(++this.challengeIndex_);
} else {
- this.goToError_(code);
+ this.goToError_(code, true);
}
}
};
/**
* Switches to the error state, and notifies caller.
* @param {number} code Error code
+ * @param {boolean=} opt_warn Whether to warn in the console about the error.
* @private
*/
-SingleGnubbySigner.prototype.goToError_ = function(code) {
+SingleGnubbySigner.prototype.goToError_ = function(code, opt_warn) {
this.state_ = SingleGnubbySigner.State.COMPLETE;
- console.log(UTIL_fmt('failed (' + code.toString(16) + ')'));
+ var logFn = opt_warn ? console.warn.bind(console) : console.log.bind(console);
+ logFn(UTIL_fmt('failed (' + code.toString(16) + ')'));
// Since this gnubby can no longer produce a useful result, go ahead and
// close it.
this.close();