| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview A single gnubby signer wraps the process of opening a gnubby, | 6 * @fileoverview A single gnubby signer wraps the process of opening a gnubby, |
| 7 * signing each challenge in an array of challenges until a success condition | 7 * signing each challenge in an array of challenges until a success condition |
| 8 * is satisfied, and finally yielding the gnubby upon success. | 8 * is satisfied, and finally yielding the gnubby upon success. |
| 9 * | 9 * |
| 10 */ | 10 */ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 this.state_ = SingleGnubbySigner.State.INIT; | 58 this.state_ = SingleGnubbySigner.State.INIT; |
| 59 /** @private {boolean} */ | 59 /** @private {boolean} */ |
| 60 this.forEnroll_ = forEnroll; | 60 this.forEnroll_ = forEnroll; |
| 61 /** @private {function(SingleSignerResult)} */ | 61 /** @private {function(SingleSignerResult)} */ |
| 62 this.completeCb_ = completeCb; | 62 this.completeCb_ = completeCb; |
| 63 /** @private {Countdown} */ | 63 /** @private {Countdown} */ |
| 64 this.timer_ = timer; | 64 this.timer_ = timer; |
| 65 /** @private {string|undefined} */ | 65 /** @private {string|undefined} */ |
| 66 this.logMsgUrl_ = opt_logMsgUrl; | 66 this.logMsgUrl_ = opt_logMsgUrl; |
| 67 | 67 |
| 68 /** @private {!Array.<!SignHelperChallenge>} */ | 68 /** @private {!Array<!SignHelperChallenge>} */ |
| 69 this.challenges_ = []; | 69 this.challenges_ = []; |
| 70 /** @private {number} */ | 70 /** @private {number} */ |
| 71 this.challengeIndex_ = 0; | 71 this.challengeIndex_ = 0; |
| 72 /** @private {boolean} */ | 72 /** @private {boolean} */ |
| 73 this.challengesSet_ = false; | 73 this.challengesSet_ = false; |
| 74 | 74 |
| 75 /** @private {!Object.<string, number>} */ | 75 /** @private {!Object<string, number>} */ |
| 76 this.cachedError_ = []; | 76 this.cachedError_ = []; |
| 77 } | 77 } |
| 78 | 78 |
| 79 /** @enum {number} */ | 79 /** @enum {number} */ |
| 80 SingleGnubbySigner.State = { | 80 SingleGnubbySigner.State = { |
| 81 /** Initial state. */ | 81 /** Initial state. */ |
| 82 INIT: 0, | 82 INIT: 0, |
| 83 /** The signer is attempting to open a gnubby. */ | 83 /** The signer is attempting to open a gnubby. */ |
| 84 OPENING: 1, | 84 OPENING: 1, |
| 85 /** The signer's gnubby opened, but is busy. */ | 85 /** The signer's gnubby opened, but is busy. */ |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 * Called when this signer's gnubby is closed. | 131 * Called when this signer's gnubby is closed. |
| 132 * @private | 132 * @private |
| 133 */ | 133 */ |
| 134 SingleGnubbySigner.prototype.closed_ = function() { | 134 SingleGnubbySigner.prototype.closed_ = function() { |
| 135 this.gnubby_ = null; | 135 this.gnubby_ = null; |
| 136 this.state_ = SingleGnubbySigner.State.CLOSED; | 136 this.state_ = SingleGnubbySigner.State.CLOSED; |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 /** | 139 /** |
| 140 * Begins signing the given challenges. | 140 * Begins signing the given challenges. |
| 141 * @param {Array.<SignHelperChallenge>} challenges The challenges to sign. | 141 * @param {Array<SignHelperChallenge>} challenges The challenges to sign. |
| 142 * @return {boolean} Whether the challenges were accepted. | 142 * @return {boolean} Whether the challenges were accepted. |
| 143 */ | 143 */ |
| 144 SingleGnubbySigner.prototype.doSign = function(challenges) { | 144 SingleGnubbySigner.prototype.doSign = function(challenges) { |
| 145 if (this.challengesSet_) { | 145 if (this.challengesSet_) { |
| 146 // Can't add new challenges once they've been set. | 146 // Can't add new challenges once they've been set. |
| 147 return false; | 147 return false; |
| 148 } | 148 } |
| 149 | 149 |
| 150 if (challenges) { | 150 if (challenges) { |
| 151 console.log(this.gnubby_); | 151 console.log(this.gnubby_); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 result['challenge'] = opt_challenge; | 467 result['challenge'] = opt_challenge; |
| 468 } | 468 } |
| 469 if (opt_info) { | 469 if (opt_info) { |
| 470 result['info'] = opt_info; | 470 result['info'] = opt_info; |
| 471 } | 471 } |
| 472 } | 472 } |
| 473 this.completeCb_(result); | 473 this.completeCb_(result); |
| 474 // this.gnubby_ is now owned by completeCb_. | 474 // this.gnubby_ is now owned by completeCb_. |
| 475 this.gnubby_ = null; | 475 this.gnubby_ = null; |
| 476 }; | 476 }; |
| OLD | NEW |