Added zapping of slots.
Dain Nilsson
8 years ago
94 | 94 | """ |
95 | 95 | Base class for configuration of all current types of YubiKeys. |
96 | 96 | """ |
97 | def __init__(self, ykver=None, capabilities=None, update=False, swap=False): | |
97 | def __init__(self, ykver=None, capabilities=None, update=False, swap=False, | |
98 | zap=False): | |
98 | 99 | """ |
99 | 100 | `ykver' is a tuple (major, minor) with the version number of the key |
100 | 101 | you are planning to apply this configuration to. Not mandated, but |
110 | 111 | |
111 | 112 | YubiKey >= 2.3 also supports swapping the configurations, making |
112 | 113 | slot 1 be slot 2 and vice versa. Set swap=True for this. |
114 | ||
115 | YubiKeys support deleting a configuration, setting it in an | |
116 | unprogrammed state. Set zap=True for this. | |
113 | 117 | """ |
114 | 118 | if capabilities is None: |
115 | 119 | self.capabilities = yubikey_base.YubiKeyCapabilities(default_answer = True) |
135 | 139 | self._require_version(major=2, minor=3) |
136 | 140 | self._update_config = update |
137 | 141 | self._swap_slots = swap |
142 | self._zap = zap | |
138 | 143 | |
139 | 144 | return None |
140 | 145 | |
141 | 146 | def __repr__(self): |
142 | return '<%s instance at %s: mode %s, v=%s/%s, lf=%i, lu=%i, lk=%i, lac=%i, tf=%x, cf=%x, ef=%x, lu=%i, up=%s, sw=%s>' % ( | |
147 | return '<%s instance at %s: mode %s, v=%s/%s, lf=%i, lu=%i, lk=%i, lac=%i, tf=%x, cf=%x, ef=%x, lu=%i, up=%s, sw=%s, z=%s>' % ( | |
143 | 148 | self.__class__.__name__, |
144 | 149 | hex(id(self)), |
145 | 150 | self._mode, |
154 | 159 | len(self.unlock_code), |
155 | 160 | self._update_config, |
156 | 161 | self._swap_slots, |
162 | self._zap | |
157 | 163 | ) |
158 | 164 | |
159 | 165 | def version_required(self): |
468 | 474 | if self._swap_slots: |
469 | 475 | command = SLOT_SWAP |
470 | 476 | |
477 | if self._zap: | |
478 | payload = b'' | |
479 | ||
471 | 480 | return yubikey_frame.YubiKeyFrame(command=command, payload=payload) |
472 | 481 | |
473 | 482 | def _require_version(self, major, minor=0): |