keyringAddHardwareSlot method

Future<int> keyringAddHardwareSlot(
  1. Pointer<Void> kr,
  2. HardwareKey key
)

Adds a slot the hardware key wraps; returns the slot index. The keyring must be unlocked.

Implementation

Future<int> keyringAddHardwareSlot(Pointer<Void> kr, HardwareKey key) async {
  final factor = SecretBytes.take(keyringBeginHardwareSlot(kr, key.keyId));
  final index = keyringSlotCount(kr) - 1;
  try {
    final blob = await key.wrap(factor);
    if (!keyringSetHardwareBlob(kr, index, blob)) {
      throw const HardwareKeyException(
        'failed',
        'could not store the wrapped factor',
      );
    }
    return index;
  } finally {
    factor.wipe();
  }
}