Skip to content

Commit

Permalink
macaddr: add Compare routine
Browse files Browse the repository at this point in the history
Add a routine to compare macaddr against a reference

Signed-off-by: Jagannathan Raman <[email protected]>
  • Loading branch information
jraman567 committed Feb 11, 2025
1 parent 5216f18 commit abee49f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion comid/macaddr.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright 2021-2024 Contributors to the Veraison project.
// Copyright 2021-2025 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0

package comid

import (
"bytes"
"encoding/json"
"fmt"
"net"
Expand All @@ -16,6 +17,24 @@ import (
// we need to create an alias type with a custom decoder.
type MACaddr net.HardwareAddr

func (o *MACaddr) Compare(r *MACaddr) error {
claim, err := o.MarshalJSON()
if err != nil {
return err
}

ref, err := r.MarshalJSON()
if err != nil {
return err
}

if bytes.Equal(claim, ref) {
return nil
}

return fmt.Errorf("macaddr mismatch")
}

// UnmarshalJSON deserialize a MAC address in textual form into the MACaddr
// target, e.g.:
//
Expand Down

0 comments on commit abee49f

Please sign in to comment.