Skip to content

Commit

Permalink
Added secp256k1 keygen/sign, delete
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdev53 committed Dec 5, 2018
1 parent 8a73cfa commit 0717d04
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions commands/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ func CreateGetPubKeyCommand(keyID uint16) (*CommandMessage, error) {
return command, nil
}

func CreateDeleteObjectCommand(objID uint16, objType uint8) (*CommandMessage, error) {
command := &CommandMessage{
CommandType: CommandTypeDeleteObject,
}

payload := bytes.NewBuffer([]byte{})
binary.Write(payload, binary.BigEndian, objID)
binary.Write(payload, binary.BigEndian, objType)
command.Data = payload.Bytes()

return command, nil
}

func CreateEchoCommand(data []byte) (*CommandMessage, error) {
command := &CommandMessage{
CommandType: CommandTypeEcho,
Expand Down
10 changes: 10 additions & 0 deletions commands/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ func ParseResponse(data []byte) (Response, error) {
return parseCreateAsymmetricKeyResponse(payload)
case CommandTypeSignDataEddsa:
return parseSignDataEddsaResponse(payload)
case CommandTypeSignDataEcdsa:
return parseSignDataEcdsaResponse(payload)
case CommandTypePutAsymmetric:
return parsePutAsymmetricKeyResponse(payload)
case CommandTypeCloseSession:
return nil, nil
case CommandTypeGetPubKey:
return parseGetPubKeyResponse(payload)
case CommandTypeDeleteObject:
return nil, nil
case CommandTypeEcho:
return parseEchoResponse(payload)
case ErrorResponseCode:
Expand Down Expand Up @@ -153,6 +157,12 @@ func parseSignDataEddsaResponse(payload []byte) (Response, error) {
}, nil
}

func parseSignDataEcdsaResponse(payload []byte) (Response, error) {
return &SignDataEcdsaResponse{
Signature: payload,
}, nil
}

func parsePutAsymmetricKeyResponse(payload []byte) (Response, error) {
if len(payload) != 2 {
return nil, errors.New("invalid response payload length")
Expand Down
9 changes: 9 additions & 0 deletions commands/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,13 @@ const (
Domain14 uint16 = 0x2000
Domain15 uint16 = 0x4000
Domain16 uint16 = 0x8000

// object types
ObjectTypeOpaque uint8 = 0x01
ObjectTypeAuthenticationKey uint8 = 0x02
ObjectTypeAsymmetricKey uint8 = 0x03
ObjectTypeWrapKey uint8 = 0x04
ObjectTypeHmacKey uint8 = 0x05
ObjectTypeTemplate uint8 = 0x06
ObjectTypeOtpAeadKey uint8 = 0x07
)

0 comments on commit 0717d04

Please sign in to comment.