Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for MAC and IP addresses in Measurement.Valid method #143

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ravjot07
Copy link

  • Implemented validation for MAC and IP addresses in the Measurement.Valid method, addressing the TODO comment: "MAC addr & friends."
  • Ensured the method correctly validates the format and presence of MAC and IP addresses where applicable.
  • Added test cases to verify the behavior of the validation logic.

This PR close #18

Copy link
Contributor

@thomas-fossati thomas-fossati left a comment

Choose a reason for hiding this comment

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

@ravjot07 thanks again for your contribution.

I have left a comment about supporting EUI-64 which should be easy to fix.

Comment on lines 464 to 469
// Validate MAC Address
if o.MACAddr != nil {
if len(*o.MACAddr) != 6 { // MAC address must be exactly 6 bytes
return fmt.Errorf("invalid MAC address length: expected 6 bytes, got %d", len(*o.MACAddr))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The CoRIM spec allows for {MAC,EUI}-48 as well as EUI-64 formatted MAC addresses:

mac-addr-type-choice = eui48-addr-type / eui64-addr-type
eui48-addr-type = bytes .size 6
eui64-addr-type = bytes .size 8

Therefore, 8 is acceptable too.

Copy link
Author

Choose a reason for hiding this comment

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

@thomas-fossati i have updated MAC address validation to allow EUI-48 and EUI-64 formats

comid/measurement_test.go Show resolved Hide resolved
Signed-off-by: Ravjot Singh <[email protected]>
@@ -26,7 +26,7 @@ var (
})
TestOID = "2.5.2.8192"
TestRegID = "https://acme.example"
TestMACaddr, _ = net.ParseMAC("02:00:5e:10:00:00:00:01")
Copy link
Contributor

Choose a reason for hiding this comment

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

Last thing, I promise ;-)

If you revert this, the diff is smaller since the change to comid/example_test.go becomes unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate binary MAC and IP addresses
2 participants