add HMACData command

This commit is contained in:
Michael Stürmer 2024-04-23 18:21:39 +02:00
parent 895c4e69c6
commit 45fbc65642
2 changed files with 30 additions and 1 deletions

View File

@ -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")

View File

@ -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,