Package com.yubico.yubikit.core.otp
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 YubiKeybyte[]
sendAndReceive(byte slot, byte[] data, CommandState state)
Sends a command to the YubiKey, and reads the response.
-
Constructor Details
-
OtpProtocol
- Throws:
java.io.IOException
-
-
Method Details
-
getVersion
-
close
public void close() throws java.io.IOException- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
sendAndReceive
public byte[] sendAndReceive(byte slot, @Nullable byte[] data, @Nullable CommandState state) throws java.io.IOException, CommandExceptionSends 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 todata
- the data payload to sendstate
- 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 errorCommandException
- in case the command failed
-
readStatus
public byte[] readStatus() throws java.io.IOExceptionReceive status bytes from YubiKey- Returns:
- status bytes (first 3 bytes are the firmware version)
- Throws:
java.io.IOException
- in case of communication error
-