Skip to content

Commit

Permalink
reuse json group decoder and remove comment
Browse files Browse the repository at this point in the history
Signed-off-by: bytemare <[email protected]>
  • Loading branch information
bytemare committed Oct 7, 2024
1 parent 423322f commit 6fcca60
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 43 deletions.
1 change: 0 additions & 1 deletion coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func (c *Configuration) AggregateSignatures(
// Verify the final signature. Failure is unlikely to happen, as the signature is valid if the signature shares are.
if verify {
if err = VerifySignature(c.Ciphersuite, message, signature, c.GroupPublicKey); err != nil {
// difficult to reach, because if all shares are valid, the final signature is valid.
return nil, err

Check warning on line 81 in coordinator.go

View check run for this annotation

Codecov / codecov/patch

coordinator.go#L81

Added line #L81 was not covered by tests
}
}
Expand Down
45 changes: 3 additions & 42 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ import (
"encoding/json"
"errors"
"fmt"
"regexp"
"strconv"

"github.com/bytemare/ecc"
"github.com/bytemare/secret-sharing/keys"

"github.com/bytemare/ecc/encoding"
"github.com/bytemare/frost/internal"
"github.com/bytemare/secret-sharing/keys"
)

const (
Expand Down Expand Up @@ -755,44 +752,8 @@ func (s *signatureShadow) init(g ecc.Group) {
s.Z = g.NewScalar()
}

func jsonReGetField(key, s, catch string) (string, error) {
r := fmt.Sprintf(`%q:%s`, key, catch)
re := regexp.MustCompile(r)
matches := re.FindStringSubmatch(s)

if len(matches) != 2 {
return "", internal.ErrEncodingInvalidJSONEncoding
}

return matches[1], nil
}

// jsonReGetGroup attempts to find the Ciphersuite JSON encoding in s.
func jsonReGetGroup(s string) (ecc.Group, error) {
f, err := jsonReGetField("group", s, `(\w+)`)
if err != nil {
return 0, err
}

g, err := strconv.Atoi(f)
if err != nil {
return 0, fmt.Errorf("failed to read Group: %w", err)
}

if g < 0 || g > 63 {
return 0, errInvalidCiphersuite
}

c := Ciphersuite(g)
if !c.Available() {
return 0, errInvalidCiphersuite
}

return ecc.Group(g), nil
}

func unmarshalJSON(data []byte, target shadowInit) error {
g, err := jsonReGetGroup(string(data))
g, err := encoding.JSONReGetGroup(string(data))
if err != nil {
return err

Check failure on line 758 in encoding.go

View workflow job for this annotation

GitHub Actions / Lint / GolangCI-Lint

error returned from external package is unwrapped: sig: func github.com/bytemare/ecc/encoding.JSONReGetGroup(s string) (github.com/bytemare/ecc.Group, error) (wrapcheck)

Check warning on line 758 in encoding.go

View check run for this annotation

Codecov / codecov/patch

encoding.go#L758

Added line #L758 was not covered by tests
}
Expand Down

0 comments on commit 6fcca60

Please sign in to comment.