Skip to content

Commit 339373d

Browse files
committed
Rebase after identitypreimage refactor
1 parent 56383a2 commit 339373d

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

rolling-shutter/cmd/cryptocmd/jsontests.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
"github.com/shutter-network/shutter/shlib/shcrypto"
1717

18-
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/epochid"
18+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/identitypreimage"
1919
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/testkeygen"
2020
)
2121

@@ -181,11 +181,11 @@ const (
181181
)
182182

183183
type encryptionTest struct {
184-
Message hexutil.Bytes `json:"message"`
185-
EonPublicKey *shcrypto.EonPublicKey `json:"eon_public_key"`
186-
EpochID epochid.EpochID `json:"epoch_id"`
187-
Sigma shcrypto.Block `json:"sigma"`
188-
Expected *shcrypto.EncryptedMessage `json:"expected"`
184+
Message hexutil.Bytes `json:"message"`
185+
EonPublicKey *shcrypto.EonPublicKey `json:"eon_public_key"`
186+
EpochID identitypreimage.IdentityPreimage `json:"epoch_id"`
187+
Sigma shcrypto.Block `json:"sigma"`
188+
Expected *shcrypto.EncryptedMessage `json:"expected"`
189189
}
190190

191191
type decryptionTest struct {
@@ -195,10 +195,10 @@ type decryptionTest struct {
195195
}
196196

197197
type verificationTest struct {
198-
EpochSecretKey shcrypto.EpochSecretKey `json:"epoch_secret_key"`
199-
EonPublicKey shcrypto.EonPublicKey `json:"eon_public_key"`
200-
EpochID epochid.EpochID `json:"epoch_id"`
201-
Expected bool `json:"expected"`
198+
EpochSecretKey shcrypto.EpochSecretKey `json:"epoch_secret_key"`
199+
EonPublicKey shcrypto.EonPublicKey `json:"eon_public_key"`
200+
EpochID identitypreimage.IdentityPreimage `json:"epoch_id"`
201+
Expected bool `json:"expected"`
202202
}
203203

204204
func readTestcases(filename string) []error {
@@ -591,8 +591,8 @@ func testMarshalingRoundtrip(tc *testCase) error {
591591
if !bytes.Equal(marshaled, roundtrip) {
592592
println(len(marshaled))
593593
println(len(roundtrip))
594-
println("m:", string(marshaled))
595-
println("u:", string(roundtrip))
594+
println("before:", string(marshaled))
595+
println("after:", string(roundtrip))
596596
return errors.New("roundtrip marshaling failed")
597597
}
598598
return nil

rolling-shutter/medley/identitypreimage/identitypreimage.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,13 @@ func (e IdentityPreimage) String() string {
5050
func Equal(a, b IdentityPreimage) bool {
5151
return bytes.Equal(a.Bytes(), b.Bytes())
5252
}
53+
54+
func (e IdentityPreimage) MarshalText() ([]byte, error) { //nolint:unparam
55+
return []byte(e.Hex()), nil
56+
}
57+
58+
func (e *IdentityPreimage) UnmarshalText(input []byte) error {
59+
val, err := HexToIdentityPreimage(string(input))
60+
*e = val.Bytes()
61+
return err
62+
}

rolling-shutter/medley/testkeygen/testgenerator.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/shutter-network/shutter/shlib/shcrypto"
77

8-
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/epochid"
8+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/identitypreimage"
99
)
1010

1111
// KeyGenerator is a helper tool to generate secret and public eon and epoch keys and key
@@ -28,15 +28,15 @@ func NewKeyGenerator(numKeypers uint64, threshold uint64) *KeyGenerator {
2828

2929
// getEonIndex computes the index of the EON key to be used for the given epochID. We generate a new
3030
// eon key every eonInterval epochs.
31-
func (kg *KeyGenerator) getEonIndex(epochID epochid.EpochID) uint64 {
31+
func (kg *KeyGenerator) getEonIndex(epochID identitypreimage.IdentityPreimage) uint64 {
3232
if kg.eonInterval == 0 {
3333
return 0
3434
}
3535

3636
return epochID.Big().Uint64() / kg.eonInterval
3737
}
3838

39-
func (kg *KeyGenerator) EonKeysForEpoch(epochID epochid.EpochID) *EonKeys {
39+
func (kg *KeyGenerator) EonKeysForEpoch(epochID identitypreimage.IdentityPreimage) *EonKeys {
4040
eonIndex := kg.getEonIndex(epochID)
4141
res, ok := kg.eonKeyGen[eonIndex]
4242
var err error
@@ -54,40 +54,37 @@ func (kg *KeyGenerator) EonKeysForEpoch(epochID epochid.EpochID) *EonKeys {
5454
return res
5555
}
5656

57-
func (kg *KeyGenerator) EonPublicKeyShare(epochID epochid.EpochID, keyperIndex uint64) *shcrypto.EonPublicKeyShare {
57+
func (kg *KeyGenerator) EonPublicKeyShare(epochID identitypreimage.IdentityPreimage, keyperIndex uint64) *shcrypto.EonPublicKeyShare {
5858
return kg.EonKeysForEpoch(epochID).keyperShares[keyperIndex].eonPublicKeyShare
5959
}
6060

61-
func (kg *KeyGenerator) EonPublicKey(epochID epochid.EpochID) *shcrypto.EonPublicKey {
61+
func (kg *KeyGenerator) EonPublicKey(epochID identitypreimage.IdentityPreimage) *shcrypto.EonPublicKey {
6262
return kg.EonKeysForEpoch(epochID).publicKey
6363
}
6464

65-
func (kg *KeyGenerator) EonSecretKeyShare(epochID epochid.EpochID, keyperIndex uint64) *shcrypto.EonSecretKeyShare {
65+
func (kg *KeyGenerator) EonSecretKeyShare(epochID identitypreimage.IdentityPreimage, keyperIndex uint64) *shcrypto.EonSecretKeyShare {
6666
return kg.EonKeysForEpoch(epochID).keyperShares[keyperIndex].eonSecretKeyShare
6767
}
6868

69-
func (kg *KeyGenerator) EpochSecretKeyShare(epochID epochid.EpochID, keyperIndex uint64) *shcrypto.EpochSecretKeyShare {
69+
func (kg *KeyGenerator) EpochSecretKeyShare(epochID identitypreimage.IdentityPreimage, keyperIndex uint64) *shcrypto.EpochSecretKeyShare {
7070
return kg.EonKeysForEpoch(epochID).keyperShares[keyperIndex].ComputeEpochSecretKeyShare(epochID)
7171
}
7272

73-
func (kg *KeyGenerator) EpochSecretKey(epochID epochid.EpochID) *shcrypto.EpochSecretKey {
73+
func (kg *KeyGenerator) EpochSecretKey(epochID identitypreimage.IdentityPreimage) *shcrypto.EpochSecretKey {
7474
epochSecretKey, err := kg.EonKeysForEpoch(epochID).EpochSecretKey(epochID)
7575
if err != nil {
7676
panic(err)
7777
}
7878
return epochSecretKey
7979
}
8080

81-
func (kg *KeyGenerator) RandomEpochID(epochbytes []byte) epochid.EpochID {
81+
func (kg *KeyGenerator) RandomEpochID(epochbytes []byte) identitypreimage.IdentityPreimage {
8282
_, err := rand.Read(epochbytes)
8383
if err != nil {
8484
panic(err)
8585
}
8686

87-
epochID, err := epochid.BytesToEpochID(epochbytes)
88-
if err != nil {
89-
panic(err)
90-
}
87+
epochID := identitypreimage.IdentityPreimage(epochbytes)
9188
return epochID
9289
}
9390

0 commit comments

Comments
 (0)