diff --git a/commands/constructors.go b/commands/constructors.go index 5ec39b7..887393f 100644 --- a/commands/constructors.go +++ b/commands/constructors.go @@ -9,7 +9,6 @@ import ( "github.com/certusone/yubihsm-go/authkey" ) - func CreateDeviceInfoCommand() (*CommandMessage, error) { command := &CommandMessage{ CommandType: CommandTypeDeviceInfo, @@ -117,6 +116,20 @@ func CreateSignDataPkcs1Command(keyID uint16, data []byte) (*CommandMessage, err return command, nil } +func CreateHMACDataCommand(keyID uint16, data []byte) (*CommandMessage, error) { + command := &CommandMessage{ + CommandType: CommandTypeHMACData, + } + + payload := bytes.NewBuffer([]byte{}) + binary.Write(payload, binary.BigEndian, keyID) + payload.Write(data) + + command.Data = payload.Bytes() + + return command, nil +} + func CreatePutAsymmetricKeyCommand(keyID uint16, label []byte, domains uint16, capabilities uint64, algorithm Algorithm, keyPart1 []byte, keyPart2 []byte) (*CommandMessage, error) { if len(label) > LabelLength { return nil, errors.New("label is too long") diff --git a/commands/response.go b/commands/response.go index f8f1a2e..476c566 100644 --- a/commands/response.go +++ b/commands/response.go @@ -76,6 +76,10 @@ type ( Signature []byte } + HMACDataResponse struct { + Data []byte + } + SignDataEcdsaResponse struct { Signature []byte } @@ -185,6 +189,8 @@ func ParseResponse(data []byte) (Response, error) { return parseSignDataEcdsaResponse(payload) case CommandTypeSignDataPkcs1: return parseSignDataPkcs1Response(payload) + case CommandTypeHMACData: + return parseHMACDataResponse(payload) case CommandTypePutAsymmetric: return parsePutAsymmetricKeyResponse(payload) case CommandTypeListObjects: @@ -314,6 +320,16 @@ func parseSignDataPkcs1Response(payload []byte) (Response, error) { }, nil } +func parseHMACDataResponse(payload []byte) (Response, error) { + if len(payload) < 1 { + return nil, errors.New("invalid response payload length") + } + + return &HMACDataResponse{ + Data: payload, + }, nil +} + func parseSignDataEcdsaResponse(payload []byte) (Response, error) { return &SignDataEcdsaResponse{ Signature: payload,