Class OtpProtocol

java.lang.Object
com.yubico.yubikit.core.otp.OtpProtocol
All Implemented Interfaces:
java.io.Closeable, java.lang.AutoCloseable

public class OtpProtocol
extends java.lang.Object
implements java.io.Closeable
  • Constructor Summary

    Constructors 
    Constructor Description
    OtpProtocol​(OtpConnection connection)  
  • Method Summary

    Modifier and Type Method Description
    void close()  
    Version getVersion()  
    byte[] readStatus()
    Receive status bytes from YubiKey
    byte[] sendAndReceive​(byte slot, byte[] data, CommandState state)
    Sends a command to the YubiKey, and reads the response.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getVersion

      public Version getVersion()
    • close

      public void close() throws java.io.IOException
      Specified by:
      close in interface java.lang.AutoCloseable
      Specified by:
      close in interface java.io.Closeable
      Throws:
      java.io.IOException
    • sendAndReceive

      public byte[] sendAndReceive​(byte slot, @Nullable byte[] data, @Nullable CommandState state) throws java.io.IOException, CommandException
      Sends a command to the YubiKey, and reads the response. If the command results in a configuration update, the programming sequence number is verified and the updated status bytes are returned.
      Parameters:
      slot - the slot to send to
      data - the data payload to send
      state - optional CommandState for listening for user presence requirement and for cancelling a command
      Returns:
      response data (including CRC) in the case of data, or an updated status struct
      Throws:
      java.io.IOException - in case of communication error
      CommandException - in case the command failed
    • readStatus

      public byte[] readStatus() throws java.io.IOException
      Receive status bytes from YubiKey
      Returns:
      status bytes (first 3 bytes are the firmware version)
      Throws:
      java.io.IOException - in case of communication error