Home | History | Annotate | Download | only in cryptotoken
      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
      3 // found in the LICENSE file.
      4 
      5 /**
      6  * @fileoverview Contains a simple factory for creating and opening Gnubby
      7  * instances.
      8  */
      9 'use strict';
     10 
     11 /**
     12  * @param {Gnubbies} gnubbies Gnubbies singleton instance
     13  * @constructor
     14  * @implements {GnubbyFactory}
     15  */
     16 function UsbGnubbyFactory(gnubbies) {
     17   /** @private {Gnubbies} */
     18   this.gnubbies_ = gnubbies;
     19   Gnubby.setGnubbies(gnubbies);
     20 }
     21 
     22 /**
     23  * Creates a new gnubby object, and opens the gnubby with the given index.
     24  * @param {GnubbyDeviceId} which The device to open.
     25  * @param {boolean} forEnroll Whether this gnubby is being opened for enrolling.
     26  * @param {FactoryOpenCallback} cb Called with result of opening the gnubby.
     27  * @param {string=} logMsgUrl the url to post log messages to
     28  * @override
     29  */
     30 UsbGnubbyFactory.prototype.openGnubby =
     31     function(which, forEnroll, cb, logMsgUrl) {
     32   var gnubby = new Gnubby();
     33   gnubby.open(which, function(rc) {
     34     if (rc) {
     35       cb(rc, gnubby);
     36       return;
     37     }
     38     gnubby.sync(function(rc) {
     39       cb(rc, gnubby);
     40     });
     41   });
     42 };
     43 
     44 /**
     45  * Enumerates gnubbies.
     46  * @param {function(number, Array.<GnubbyDeviceId>)} cb Enumerate callback
     47  */
     48 UsbGnubbyFactory.prototype.enumerate = function(cb) {
     49   this.gnubbies_.enumerate(cb);
     50 };
     51 
     52 /**
     53  * No-op prerequisite check.
     54  * @param {Gnubby} gnubby The not-enrolled gnubby.
     55  * @param {string} appIdHash The base64-encoded hash of the app id for which
     56  *     the gnubby being enrolled.
     57  * @param {FactoryOpenCallback} cb Called with the result of the prerequisite
     58  *     check. (A non-zero status indicates failure.)
     59  */
     60 UsbGnubbyFactory.prototype.notEnrolledPrerequisiteCheck =
     61     function(gnubby, appIdHash, cb) {
     62   cb(DeviceStatusCodes.OK_STATUS, gnubby);
     63 };
     64