Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions v3/smcrypto/sm_crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ func SM2PubBytes(pub *ecdsa.PublicKey) []byte {
return nil
}
pubBytes := make([]byte, publicKeyLength)
copy(pubBytes[:], pub.X.Bytes())
copy(pubBytes[publicKeyLength/2:], pub.Y.Bytes())
// 确保X坐标长度固定,不足时在前端补0
xBytes := pub.X.Bytes()
copy(pubBytes[:publicKeyLength/2-(len(xBytes))], make([]byte, publicKeyLength/2-len(xBytes)))
Copy link

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The padding logic for both X and Y coordinates is similar. Consider extracting this repeated logic into a helper function to enhance maintainability.

Copilot uses AI. Check for mistakes.
copy(pubBytes[publicKeyLength/2-len(xBytes):publicKeyLength/2], xBytes)

// 确保Y坐标长度固定,不足时在前端补0
yBytes := pub.Y.Bytes()
copy(pubBytes[publicKeyLength/2:publicKeyLength-(len(yBytes))], make([]byte, publicKeyLength/2-len(yBytes)))
copy(pubBytes[publicKeyLength-len(yBytes):], yBytes)

return pubBytes
}

Expand Down
Loading