ax(ueps): rename signature to hmacSignature for AX Principle 1 compliance
The variable name `signature` is ambiguous — any cryptographic operation produces a signature. `hmacSignature` is unambiguous and self-describing, consistent with the TagHMAC comment that already used `hmacSignature` as the example parameter name. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
c34e6da043
commit
729ad75d6f
2 changed files with 7 additions and 7 deletions
|
|
@ -88,10 +88,10 @@ func (builder *PacketBuilder) MarshalAndSign(sharedSecret []byte) ([]byte, error
|
|||
messageAuthCode := hmac.New(sha256.New, sharedSecret)
|
||||
messageAuthCode.Write(frameBuffer.Bytes())
|
||||
messageAuthCode.Write(builder.Payload)
|
||||
signature := messageAuthCode.Sum(nil)
|
||||
hmacSignature := messageAuthCode.Sum(nil)
|
||||
|
||||
// writeTLV(frameBuffer, TagHMAC, signature) → [0x06, 0x20, <32 bytes>]
|
||||
if err := writeTLV(frameBuffer, TagHMAC, signature); err != nil {
|
||||
// writeTLV(frameBuffer, TagHMAC, hmacSignature) → [0x06, 0x20, <32 bytes>]
|
||||
if err := writeTLV(frameBuffer, TagHMAC, hmacSignature); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ type ParsedPacket struct {
|
|||
func ReadAndVerify(reader *bufio.Reader, sharedSecret []byte) (*ParsedPacket, error) {
|
||||
var signedData bytes.Buffer
|
||||
header := UEPSHeader{}
|
||||
var signature []byte
|
||||
var hmacSignature []byte
|
||||
var payload []byte
|
||||
|
||||
for {
|
||||
|
|
@ -85,7 +85,7 @@ func ReadAndVerify(reader *bufio.Reader, sharedSecret []byte) (*ParsedPacket, er
|
|||
signedData.WriteByte(byte(tagLength))
|
||||
signedData.Write(tagValue)
|
||||
case TagHMAC:
|
||||
signature = tagValue
|
||||
hmacSignature = tagValue
|
||||
default:
|
||||
// signedData.WriteByte(unknownTag); signedData.Write(tagValue) — unknown tags contribute to HMAC, blocking injection
|
||||
signedData.WriteByte(tagByte)
|
||||
|
|
@ -94,7 +94,7 @@ func ReadAndVerify(reader *bufio.Reader, sharedSecret []byte) (*ParsedPacket, er
|
|||
}
|
||||
}
|
||||
|
||||
if len(signature) == 0 {
|
||||
if len(hmacSignature) == 0 {
|
||||
return nil, errMissingHMAC
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ func ReadAndVerify(reader *bufio.Reader, sharedSecret []byte) (*ParsedPacket, er
|
|||
messageAuthCode.Write(payload)
|
||||
expectedMessageAuthCode := messageAuthCode.Sum(nil)
|
||||
|
||||
if !hmac.Equal(signature, expectedMessageAuthCode) {
|
||||
if !hmac.Equal(hmacSignature, expectedMessageAuthCode) {
|
||||
return nil, errIntegrityViolation
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue