diff --git a/bson/encoding_cypher.go b/bson/encoding_cypher.go index 7452abe..aaaeeff 100644 --- a/bson/encoding_cypher.go +++ b/bson/encoding_cypher.go @@ -1,5 +1,3 @@ -// Package bson provides functions for serialization and deserialization between -// paillier objects and BSON package bson import ( @@ -11,7 +9,7 @@ import ( "gopkg.in/mgo.v2/bson" ) -type Cypher paillier.Cypher +type SerializableCypher paillier.Cypher // Serializes Cypher to BSON func SerializeCypher(cypher *paillier.Cypher) ([]byte, error) { @@ -20,7 +18,7 @@ func SerializeCypher(cypher *paillier.Cypher) ([]byte, error) { // Deserializes BSON to Cypher func DeserializeCypher(data []byte) (*paillier.Cypher, error) { - serializable := new(Cypher) + serializable := new(SerializableCypher) if err := bson.Unmarshal(data, serializable); err != nil { return nil, err } @@ -28,14 +26,12 @@ func DeserializeCypher(data []byte) (*paillier.Cypher, error) { return toOriginalCypher(serializable), nil } -// Changes original Cypher to serializable Cypher -func toSerializableCypher(cypher *paillier.Cypher) *Cypher { - serializable := Cypher(*cypher) +func toSerializableCypher(cypher *paillier.Cypher) *SerializableCypher { + serializable := SerializableCypher(*cypher) return &serializable } -// Changes serializable Cypher to original Cypher -func toOriginalCypher(serializable *Cypher) *paillier.Cypher { +func toOriginalCypher(serializable *SerializableCypher) *paillier.Cypher { original := paillier.Cypher(*serializable) return &original } @@ -44,11 +40,11 @@ type dbCypher struct { C string } -func (cypher *Cypher) GetBSON() (interface{}, error) { +func (cypher *SerializableCypher) GetBSON() (interface{}, error) { return &dbCypher{fmt.Sprintf("%x", cypher.C)}, nil } -func (cypher *Cypher) SetBSON(raw bson.Raw) error { +func (cypher *SerializableCypher) SetBSON(raw bson.Raw) error { c := dbCypher{} if err := raw.Unmarshal(&c); err != nil { return err diff --git a/bson/encoding_partialdecryptionzkp.go b/bson/encoding_partialdecryptionzkp.go index d592945..606f7ad 100644 --- a/bson/encoding_partialdecryptionzkp.go +++ b/bson/encoding_partialdecryptionzkp.go @@ -1,5 +1,3 @@ -// Package bson provides functions for serialization and deserialization between -// paillier objects and BSON package bson import ( @@ -12,7 +10,7 @@ import ( "gopkg.in/mgo.v2/bson" ) -type PartialDecryptionZKP paillier.PartialDecryptionZKP +type SerializablePartialDecryptionZKP paillier.PartialDecryptionZKP // Serializes PartialDecryptionZKP to BSON func SerializePartialDecryptionZKP(pdzkp *paillier.PartialDecryptionZKP) ([]byte, error) { @@ -21,7 +19,7 @@ func SerializePartialDecryptionZKP(pdzkp *paillier.PartialDecryptionZKP) ([]byte // Deserializes BSON to PartialDecryptionZKP func DeserializePartialDecryptionZKP(data []byte) (*paillier.PartialDecryptionZKP, error) { - serializable := new(PartialDecryptionZKP) + serializable := new(SerializablePartialDecryptionZKP) if err := bson.Unmarshal(data, serializable); err != nil { return nil, err } @@ -36,7 +34,7 @@ func JsonSerializePartialDecryptionZKP(pdzkp *paillier.PartialDecryptionZKP) ([] // Deserializes JSON to PartialDecryptionZKP func JsonDeserializePartialDecryptionZKP(data []byte) (*paillier.PartialDecryptionZKP, error) { - serializable := new(PartialDecryptionZKP) + serializable := new(SerializablePartialDecryptionZKP) if err := json.Unmarshal(data, serializable); err != nil { return nil, err } @@ -44,14 +42,12 @@ func JsonDeserializePartialDecryptionZKP(data []byte) (*paillier.PartialDecrypti return toOriginalPartialDecryptionZKP(serializable), nil } -// Changes original PartialDecryptionZKP to serializable PartialDecryptionZKP -func toSerializablePartialDecryptionZKP(pdzkp *paillier.PartialDecryptionZKP) *PartialDecryptionZKP { - serializable := PartialDecryptionZKP(*pdzkp) +func toSerializablePartialDecryptionZKP(pdzkp *paillier.PartialDecryptionZKP) *SerializablePartialDecryptionZKP { + serializable := SerializablePartialDecryptionZKP(*pdzkp) return &serializable } -// Changes serializable PartialDecryptionZKP to original PartialDecryptionZKP -func toOriginalPartialDecryptionZKP(serializable *PartialDecryptionZKP) *paillier.PartialDecryptionZKP { +func toOriginalPartialDecryptionZKP(serializable *SerializablePartialDecryptionZKP) *paillier.PartialDecryptionZKP { original := paillier.PartialDecryptionZKP(*serializable) return &original } @@ -69,13 +65,13 @@ type dbPartialDecryptionZKP struct { Threshold int `json:"threshold"` } -func (pdzkp *PartialDecryptionZKP) GetBSON() (interface{}, error) { +func (pdzkp *SerializablePartialDecryptionZKP) GetBSON() (interface{}, error) { db := new(dbPartialDecryptionZKP) db.fromPartialDecryptionZKP(pdzkp) return db, nil } -func (pdzkp *PartialDecryptionZKP) SetBSON(raw bson.Raw) error { +func (pdzkp *SerializablePartialDecryptionZKP) SetBSON(raw bson.Raw) error { db := new(dbPartialDecryptionZKP) if err := raw.Unmarshal(db); err != nil { return err @@ -83,7 +79,7 @@ func (pdzkp *PartialDecryptionZKP) SetBSON(raw bson.Raw) error { return db.toPartialDecryptionZKP(pdzkp) } -func (dbPDZKP *dbPartialDecryptionZKP) fromPartialDecryptionZKP(pdzkp *PartialDecryptionZKP) { +func (dbPDZKP *dbPartialDecryptionZKP) fromPartialDecryptionZKP(pdzkp *SerializablePartialDecryptionZKP) { dbPDZKP.Id = pdzkp.Id dbPDZKP.TotalNumberOfDecryptionServers = pdzkp.Key.TotalNumberOfDecryptionServers dbPDZKP.Threshold = pdzkp.Key.Threshold @@ -99,7 +95,7 @@ func (dbPDZKP *dbPartialDecryptionZKP) fromPartialDecryptionZKP(pdzkp *PartialDe } } -func (dbPDZKP *dbPartialDecryptionZKP) toPartialDecryptionZKP(pdzkp *PartialDecryptionZKP) error { +func (dbPDZKP *dbPartialDecryptionZKP) toPartialDecryptionZKP(pdzkp *SerializablePartialDecryptionZKP) error { pdzkp.Key = new(paillier.ThresholdPublicKey) var oks = make([]bool, 6) diff --git a/bson/encoding_privatekey.go b/bson/encoding_privatekey.go index 5e81996..f1cca88 100644 --- a/bson/encoding_privatekey.go +++ b/bson/encoding_privatekey.go @@ -1,5 +1,3 @@ -// Package bson provides functions for serialization and deserialization between -// paillier objects and BSON package bson import ( @@ -9,7 +7,7 @@ import ( "gopkg.in/mgo.v2/bson" ) -type PrivateKey paillier.PrivateKey +type SerializablePrivateKey paillier.PrivateKey // Serializes PrivateKey to BSON func SerializePrivateKey(key *paillier.PrivateKey) ([]byte, error) { @@ -18,7 +16,7 @@ func SerializePrivateKey(key *paillier.PrivateKey) ([]byte, error) { // Deserializes BSON to PrivateKey func DeserializePrivateKey(data []byte) (*paillier.PrivateKey, error) { - serializable := new(PrivateKey) + serializable := new(SerializablePrivateKey) if err := bson.Unmarshal(data, serializable); err != nil { return nil, err } @@ -26,14 +24,12 @@ func DeserializePrivateKey(data []byte) (*paillier.PrivateKey, error) { return toOriginalPrivateKey(serializable), nil } -// Changes original PrivateKey to serializable PrivateKey -func toSerializablePrivateKey(key *paillier.PrivateKey) *PrivateKey { - serializable := PrivateKey(*key) +func toSerializablePrivateKey(key *paillier.PrivateKey) *SerializablePrivateKey { + serializable := SerializablePrivateKey(*key) return &serializable } -// Changes serializable PrivateKey to original PrivateKey -func toOriginalPrivateKey(serializable *PrivateKey) *paillier.PrivateKey { +func toOriginalPrivateKey(serializable *SerializablePrivateKey) *paillier.PrivateKey { original := paillier.PrivateKey(*serializable) return &original } @@ -44,7 +40,7 @@ type dbPrivateKey struct { Mu string `bson:",omitempty"` } -func (privateKey *PrivateKey) GetBSON() (interface{}, error) { +func (privateKey *SerializablePrivateKey) GetBSON() (interface{}, error) { m := make(map[string]string) if privateKey.N != nil { @@ -56,7 +52,7 @@ func (privateKey *PrivateKey) GetBSON() (interface{}, error) { return m, nil } -func (privateKey *PrivateKey) SetBSON(raw bson.Raw) error { +func (privateKey *SerializablePrivateKey) SetBSON(raw bson.Raw) error { var err error = nil c := new(dbPrivateKey) raw.Unmarshal(c) diff --git a/bson/encoding_privatekey_test.go b/bson/encoding_privatekey_test.go index 9c777a7..8870bcc 100644 --- a/bson/encoding_privatekey_test.go +++ b/bson/encoding_privatekey_test.go @@ -7,7 +7,7 @@ import ( "github.com/keep-network/paillier" ) -func TestSetPrivateKeyBson(t *testing.T) { +func TestPrivateKeyBsonSerialization(t *testing.T) { key := &paillier.PrivateKey{ PublicKey: paillier.PublicKey{ N: (b(345)), diff --git a/bson/encoding_publickey.go b/bson/encoding_publickey.go index a44f623..1d4b930 100644 --- a/bson/encoding_publickey.go +++ b/bson/encoding_publickey.go @@ -1,5 +1,3 @@ -// Package bson provides functions for serialization and deserialization between -// paillier objects and BSON package bson import ( @@ -9,7 +7,7 @@ import ( "gopkg.in/mgo.v2/bson" ) -type PublicKey paillier.PublicKey +type SerializablePublicKey paillier.PublicKey // Serializes PublicKey to BSON func SerializePublicKey(publicKey *paillier.PublicKey) ([]byte, error) { @@ -18,7 +16,7 @@ func SerializePublicKey(publicKey *paillier.PublicKey) ([]byte, error) { // Deserializes BSON to PublicKey func DeserializePublicKey(data []byte) (*paillier.PublicKey, error) { - serializable := new(PublicKey) + serializable := new(SerializablePublicKey) if err := bson.Unmarshal(data, serializable); err != nil { return nil, err } @@ -26,14 +24,12 @@ func DeserializePublicKey(data []byte) (*paillier.PublicKey, error) { return toOriginalPublicKey(serializable), nil } -// Changes original PublicKey to serializable PublicKey -func toSerializablePublicKey(publicKey *paillier.PublicKey) *PublicKey { - serializable := PublicKey(*publicKey) +func toSerializablePublicKey(publicKey *paillier.PublicKey) *SerializablePublicKey { + serializable := SerializablePublicKey(*publicKey) return &serializable } -// Changes serializable PublicKey to original PublicKey -func toOriginalPublicKey(serializable *PublicKey) *paillier.PublicKey { +func toOriginalPublicKey(serializable *SerializablePublicKey) *paillier.PublicKey { original := paillier.PublicKey(*serializable) return &original } @@ -42,13 +38,13 @@ type dbPublicKey struct { N string `bson:",omitempty"` } -func (publicKey *PublicKey) GetBSON() (interface{}, error) { +func (publicKey *SerializablePublicKey) GetBSON() (interface{}, error) { m := make(map[string]string) m["n"] = fmt.Sprintf("%x", publicKey.N) return m, nil } -func (publicKey *PublicKey) SetBSON(raw bson.Raw) error { +func (publicKey *SerializablePublicKey) SetBSON(raw bson.Raw) error { var err error = nil c := new(dbPublicKey) raw.Unmarshal(c) diff --git a/bson/encoding_publickey_test.go b/bson/encoding_publickey_test.go index b777e2b..130e22b 100644 --- a/bson/encoding_publickey_test.go +++ b/bson/encoding_publickey_test.go @@ -7,7 +7,7 @@ import ( "github.com/keep-network/paillier" ) -func TestSetPublicKeyBson(t *testing.T) { +func TestPublicKeyBsonSerialization(t *testing.T) { key := &paillier.PublicKey{ N: (b(345)), } diff --git a/bson/encoding_thresholdpublickey.go b/bson/encoding_thresholdpublickey.go index b2317db..5af5c89 100644 --- a/bson/encoding_thresholdpublickey.go +++ b/bson/encoding_thresholdpublickey.go @@ -1,5 +1,3 @@ -// Package bson provides functions for serialization and deserialization between -// paillier objects and BSON package bson import ( @@ -11,7 +9,7 @@ import ( "gopkg.in/mgo.v2/bson" ) -type ThresholdPublicKey paillier.ThresholdPublicKey +type SerializableThresholdPublicKey paillier.ThresholdPublicKey // Serializes ThresholdPublicKey to BSON func SerializeThresholdPublicKey(key *paillier.ThresholdPublicKey) ([]byte, error) { @@ -20,7 +18,7 @@ func SerializeThresholdPublicKey(key *paillier.ThresholdPublicKey) ([]byte, erro // Deserializes BSON to ThresholdPublicKey func DeserializeThresholdPublicKey(data []byte) (*paillier.ThresholdPublicKey, error) { - serializable := new(ThresholdPublicKey) + serializable := new(SerializableThresholdPublicKey) if err := bson.Unmarshal(data, serializable); err != nil { return nil, err } @@ -28,25 +26,23 @@ func DeserializeThresholdPublicKey(data []byte) (*paillier.ThresholdPublicKey, e return toOriginalThresholdPublicKey(serializable), nil } -// Changes original ThresholdPublicKey to serializable ThresholdPublicKey -func toSerializableThresholdPublicKey(key *paillier.ThresholdPublicKey) *ThresholdPublicKey { - serializable := ThresholdPublicKey(*key) +func toSerializableThresholdPublicKey(key *paillier.ThresholdPublicKey) *SerializableThresholdPublicKey { + serializable := SerializableThresholdPublicKey(*key) return &serializable } -// Changes serializable ThresholdPublicKey to original ThresholdPublicKey -func toOriginalThresholdPublicKey(serializable *ThresholdPublicKey) *paillier.ThresholdPublicKey { +func toOriginalThresholdPublicKey(serializable *SerializableThresholdPublicKey) *paillier.ThresholdPublicKey { original := paillier.ThresholdPublicKey(*serializable) return &original } -func (thresholdPublicKey *ThresholdPublicKey) GetBSON() (interface{}, error) { +func (thresholdPublicKey *SerializableThresholdPublicKey) GetBSON() (interface{}, error) { r := new(dbThresholdKey) r.fromThresholdPublicKey(thresholdPublicKey) return r, nil } -func (thresholdPublicKey *ThresholdPublicKey) SetBSON(raw bson.Raw) error { +func (thresholdPublicKey *SerializableThresholdPublicKey) SetBSON(raw bson.Raw) error { r := new(dbThresholdKey) if err := raw.Unmarshal(r); err != nil { return err @@ -62,7 +58,7 @@ type dbThresholdKey struct { N string } -func (dbThresholdKey *dbThresholdKey) fromThresholdPublicKey(key *ThresholdPublicKey) { +func (dbThresholdKey *dbThresholdKey) fromThresholdPublicKey(key *SerializableThresholdPublicKey) { dbThresholdKey.TotalNumberOfDecryptionServers = key.TotalNumberOfDecryptionServers dbThresholdKey.Threshold = key.Threshold dbThresholdKey.V = fmt.Sprintf("%x", key.V) @@ -73,7 +69,7 @@ func (dbThresholdKey *dbThresholdKey) fromThresholdPublicKey(key *ThresholdPubli } } -func (dbThresholdKey *dbThresholdKey) toThresholdPublicKey(key *ThresholdPublicKey) error { +func (dbThresholdKey *dbThresholdKey) toThresholdPublicKey(key *SerializableThresholdPublicKey) error { key.TotalNumberOfDecryptionServers = dbThresholdKey.TotalNumberOfDecryptionServers key.Threshold = dbThresholdKey.Threshold oks := make([]bool, 2) diff --git a/bson/encoding_thresholdpublickey_test.go b/bson/encoding_thresholdpublickey_test.go index c5fbe74..93d8fe3 100644 --- a/bson/encoding_thresholdpublickey_test.go +++ b/bson/encoding_thresholdpublickey_test.go @@ -8,7 +8,7 @@ import ( "github.com/keep-network/paillier" ) -func TestThresholdKeyBSON(t *testing.T) { +func TestThresholdKeySerialization(t *testing.T) { key := &paillier.ThresholdPublicKey{ PublicKey: paillier.PublicKey{b(9)}, TotalNumberOfDecryptionServers: 7,