Let to pass an arbitrary number of cyphers to PublicKey.Add
`PublicKey.Add` accepts now an arbitrary number of `*Cypher`s. Previously, it was possible to add only two `*Cypher*` instances and it was quite unwieldy for a lot of use cases. The current implementation is backward compatible. It's still possible to pass just two `*Cypher` arguments, so every project referencing the library will observe no compilation issues.
This commit is contained in:
2 files changed
+27
-13
No files matched your search
+12
-8
@@ -64,13 +64,17 @@ func TestEncryptDecryptSmall(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddCypher(t *testing.T) {
|
||||
privateKey := CreatePrivateKey(big.NewInt(13), big.NewInt(11))
|
||||
cypher1, _ := privateKey.Encrypt(big.NewInt(12), rand.Reader)
|
||||
cypher2, _ := privateKey.Encrypt(big.NewInt(13), rand.Reader)
|
||||
cypher3 := privateKey.Add(cypher1, cypher2)
|
||||
m := privateKey.Decrypt(cypher3)
|
||||
if !reflect.DeepEqual(m, big.NewInt(25)) {
|
||||
t.Error(m)
|
||||
func TestAddCyphers(t *testing.T) {
|
||||
privateKey := CreatePrivateKey(big.NewInt(17), big.NewInt(13))
|
||||
|
||||
cypher1, _ := privateKey.Encrypt(big.NewInt(5), rand.Reader)
|
||||
cypher2, _ := privateKey.Encrypt(big.NewInt(6), rand.Reader)
|
||||
cypher3, _ := privateKey.Encrypt(big.NewInt(7), rand.Reader)
|
||||
cypher4, _ := privateKey.Encrypt(big.NewInt(8), rand.Reader)
|
||||
cypher5 := privateKey.Add(cypher1, cypher2, cypher3, cypher4)
|
||||
|
||||
m := privateKey.Decrypt(cypher5)
|
||||
if !reflect.DeepEqual(m, big.NewInt(26)) {
|
||||
t.Errorf("Unexpected decrypted value [%v]", m)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user