add HMACData command
This commit is contained in:
parent
895c4e69c6
commit
45fbc65642
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/certusone/yubihsm-go/authkey"
|
"github.com/certusone/yubihsm-go/authkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func CreateDeviceInfoCommand() (*CommandMessage, error) {
|
func CreateDeviceInfoCommand() (*CommandMessage, error) {
|
||||||
command := &CommandMessage{
|
command := &CommandMessage{
|
||||||
CommandType: CommandTypeDeviceInfo,
|
CommandType: CommandTypeDeviceInfo,
|
||||||
|
@ -117,6 +116,20 @@ func CreateSignDataPkcs1Command(keyID uint16, data []byte) (*CommandMessage, err
|
||||||
return command, nil
|
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) {
|
func CreatePutAsymmetricKeyCommand(keyID uint16, label []byte, domains uint16, capabilities uint64, algorithm Algorithm, keyPart1 []byte, keyPart2 []byte) (*CommandMessage, error) {
|
||||||
if len(label) > LabelLength {
|
if len(label) > LabelLength {
|
||||||
return nil, errors.New("label is too long")
|
return nil, errors.New("label is too long")
|
||||||
|
|
|
@ -76,6 +76,10 @@ type (
|
||||||
Signature []byte
|
Signature []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HMACDataResponse struct {
|
||||||
|
Data []byte
|
||||||
|
}
|
||||||
|
|
||||||
SignDataEcdsaResponse struct {
|
SignDataEcdsaResponse struct {
|
||||||
Signature []byte
|
Signature []byte
|
||||||
}
|
}
|
||||||
|
@ -185,6 +189,8 @@ func ParseResponse(data []byte) (Response, error) {
|
||||||
return parseSignDataEcdsaResponse(payload)
|
return parseSignDataEcdsaResponse(payload)
|
||||||
case CommandTypeSignDataPkcs1:
|
case CommandTypeSignDataPkcs1:
|
||||||
return parseSignDataPkcs1Response(payload)
|
return parseSignDataPkcs1Response(payload)
|
||||||
|
case CommandTypeHMACData:
|
||||||
|
return parseHMACDataResponse(payload)
|
||||||
case CommandTypePutAsymmetric:
|
case CommandTypePutAsymmetric:
|
||||||
return parsePutAsymmetricKeyResponse(payload)
|
return parsePutAsymmetricKeyResponse(payload)
|
||||||
case CommandTypeListObjects:
|
case CommandTypeListObjects:
|
||||||
|
@ -314,6 +320,16 @@ func parseSignDataPkcs1Response(payload []byte) (Response, error) {
|
||||||
}, nil
|
}, 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) {
|
func parseSignDataEcdsaResponse(payload []byte) (Response, error) {
|
||||||
return &SignDataEcdsaResponse{
|
return &SignDataEcdsaResponse{
|
||||||
Signature: payload,
|
Signature: payload,
|
||||||
|
|
Loading…
Reference in New Issue