replace byte cast with hex.DecodeString()

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2023-09-07 10:09:06 +02:00
parent 3e18324004
commit 311a3596c2
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
3 changed files with 2 additions and 17 deletions

View File

@ -110,7 +110,7 @@ func Asset(sk string) (string, string) {
skBytes, _ := hex.DecodeString(sk)
privKey := &secp256k1.PrivKey{Key: skBytes}
cid_bytes := []byte(cid)
cid_bytes, _ := hex.DecodeString(cid)
sign, _ := privKey.Sign(cid_bytes)
signatureHex := hex.EncodeToString(sign)

View File

@ -7,21 +7,6 @@ import (
)
func ValidateSignature(message string, signature string, publicKey string) bool {
// Convert the message, signature, and public key from hex to bytes
messageBytes := []byte(message)
signatureBytes, _ := hex.DecodeString(signature)
publicKeyBytes, _ := hex.DecodeString(publicKey)
// Create a secp256k1 public key object
pubKey := &secp256k1.PubKey{Key: publicKeyBytes}
// Verify the signature
isValid := pubKey.VerifySignature(messageBytes, signatureBytes)
return isValid
}
func ValidateSignature_hexstring(message string, signature string, publicKey string) bool {
// Convert the message, signature, and public key from hex to bytes
messageBytes, _ := hex.DecodeString(message)
signatureBytes, _ := hex.DecodeString(signature)

View File

@ -33,7 +33,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
return nil, errors.New("trust anchor has already been used for attestation")
}
isValidMachineId := util.ValidateSignature_hexstring(msg.Machine.MachineId, msg.Machine.MachineIdSignature, msg.Machine.MachineId)
isValidMachineId := util.ValidateSignature(msg.Machine.MachineId, msg.Machine.MachineIdSignature, msg.Machine.MachineId)
if !isValidMachineId {
return nil, errors.New("invalid machine id")
}