github.com/dusk-network/dusk-crypto@v0.1.3/mlsag/pubkeys.go (about) 1 package mlsag 2 3 import ( 4 "encoding/binary" 5 "errors" 6 "io" 7 8 ristretto "github.com/bwesterb/go-ristretto" 9 ) 10 11 type PubKeys struct { 12 // Set to true if the set of pubKeys are decoys 13 decoy bool 14 // Vector of pubKeys 15 keys []ristretto.Point 16 } 17 18 func (p *PubKeys) Equals(other PubKeys) bool { 19 20 if len(p.keys) != len(other.keys) { 21 return false 22 } 23 24 for i := range p.keys { 25 ok := p.keys[i].Equals(&other.keys[i]) 26 if !ok { 27 return ok 28 } 29 } 30 31 return true 32 } 33 34 func (p PubKeys) Encode(w io.Writer) error { 35 for i := range p.keys { 36 err := binary.Write(w, binary.BigEndian, p.keys[i].Bytes()) 37 if err != nil { 38 return err 39 } 40 } 41 return nil 42 } 43 44 func (p *PubKeys) Decode(r io.Reader, numKeys uint32) error { 45 46 if p == nil { 47 return errors.New("struct is nil") 48 } 49 50 var xBytes [32]byte 51 var x ristretto.Point 52 for i := uint32(0); i < numKeys; i++ { 53 err := binary.Read(r, binary.BigEndian, &xBytes) 54 if err != nil { 55 return err 56 } 57 ok := x.SetBytes(&xBytes) 58 if !ok { 59 return errors.New("point not encodable") 60 } 61 p.AddPubKey(x) 62 } 63 return nil 64 } 65 func (p *PubKeys) AddPubKey(key ristretto.Point) { 66 p.keys = append(p.keys, key) 67 } 68 69 func (p *PubKeys) Len() int { 70 return len(p.keys) 71 } 72 73 func (p *PubKeys) OutputKey() ristretto.Point { 74 return p.keys[0] 75 }