fido_transport_protocol.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2018 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. #include "device/fido/fido_transport_protocol.h"
  5. namespace device {
  6. const char kUsbHumanInterfaceDevice[] = "usb";
  7. const char kNearFieldCommunication[] = "nfc";
  8. const char kBluetoothLowEnergy[] = "ble";
  9. const char kCable[] = "hybrid";
  10. const char kHybrid[] = "hybrid";
  11. const char kInternal[] = "internal";
  12. absl::optional<FidoTransportProtocol> ConvertToFidoTransportProtocol(
  13. base::StringPiece protocol) {
  14. if (protocol == kUsbHumanInterfaceDevice)
  15. return FidoTransportProtocol::kUsbHumanInterfaceDevice;
  16. else if (protocol == kNearFieldCommunication)
  17. return FidoTransportProtocol::kNearFieldCommunication;
  18. else if (protocol == kBluetoothLowEnergy)
  19. return FidoTransportProtocol::kBluetoothLowEnergy;
  20. else if (protocol == kHybrid)
  21. return FidoTransportProtocol::kHybrid;
  22. else if (protocol == kCable)
  23. // This is the old name for "hybrid".
  24. return FidoTransportProtocol::kHybrid;
  25. else if (protocol == kInternal)
  26. return FidoTransportProtocol::kInternal;
  27. else
  28. return absl::nullopt;
  29. }
  30. base::StringPiece ToString(FidoTransportProtocol protocol) {
  31. switch (protocol) {
  32. case FidoTransportProtocol::kUsbHumanInterfaceDevice:
  33. return kUsbHumanInterfaceDevice;
  34. case FidoTransportProtocol::kNearFieldCommunication:
  35. return kNearFieldCommunication;
  36. case FidoTransportProtocol::kBluetoothLowEnergy:
  37. return kBluetoothLowEnergy;
  38. case FidoTransportProtocol::kHybrid:
  39. return kHybrid;
  40. case FidoTransportProtocol::kInternal:
  41. return kInternal;
  42. case FidoTransportProtocol::kAndroidAccessory:
  43. // The Android accessory transport is not exposed to the outside world and
  44. // is considered a flavour of caBLE.
  45. return kHybrid;
  46. }
  47. }
  48. AuthenticatorAttachment AuthenticatorAttachmentFromTransport(
  49. FidoTransportProtocol transport) {
  50. switch (transport) {
  51. case FidoTransportProtocol::kInternal:
  52. return AuthenticatorAttachment::kPlatform;
  53. case FidoTransportProtocol::kUsbHumanInterfaceDevice:
  54. case FidoTransportProtocol::kNearFieldCommunication:
  55. case FidoTransportProtocol::kBluetoothLowEnergy:
  56. case FidoTransportProtocol::kHybrid:
  57. case FidoTransportProtocol::kAndroidAccessory:
  58. return AuthenticatorAttachment::kCrossPlatform;
  59. }
  60. }
  61. } // namespace device