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

chore: Java interop PR #70

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
45 changes: 45 additions & 0 deletions common/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package common_test

import (
"bytes"
"encoding/hex"
"testing"

"github.com/crate-crypto/go-ipa/common"
)

func TestJavaRegressionOneEndian(t *testing.T) {
hexStr := "f6e31f7a565a390b48fdd24569ac10d43562d19de37ea951c7f9f250a339d059"
byteArray := hexStrToBytes(hexStr)
_scalar, err := common.ReadScalar(bytes.NewReader(byteArray))

if err == nil {
t.Fatalf("expected an error because the scalar is too large")
}
_ = _scalar
}
func TestJavaRegressionOtherEndian(t *testing.T) {
hexStr := "f6e31f7a565a390b48fdd24569ac10d43562d19de37ea951c7f9f250a339d059"
byteArray := hexStrToBytes(hexStr)
reverse(byteArray)
_scalar, err := common.ReadScalar(bytes.NewReader(byteArray))
if err == nil {
t.Fatalf("expected an error because the scalar is too large, even though we changed the endian")
}
_ = _scalar
}
Comment on lines +17 to +36
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the failing tests


func reverse(data []byte) {
for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
data[i], data[j] = data[j], data[i]
}
}

func hexStrToBytes(numStr string) []byte {

byteArray, err := hex.DecodeString(numStr)
if err != nil {
panic(err)
}
return byteArray
}