Example #1
0
func (sm *SigningMessage) UnmarshalBinary(data []byte) error {
	var cons = make(protobuf.Constructors)
	var point abstract.Point
	var secret abstract.Secret
	cons[reflect.TypeOf(&point).Elem()] = func() interface{} { return msgSuite.Point() }
	cons[reflect.TypeOf(&secret).Elem()] = func() interface{} { return msgSuite.Secret() }
	return protobuf.DecodeWithConstructors(data, sm, cons)
}
Example #2
0
func (v *Vote) UnmarshalBinary(data []byte) error {
	var cons = make(protobuf.Constructors)
	var point abstract.Point
	var secret abstract.Secret
	var suite = nist.NewAES128SHA256P256()
	cons[reflect.TypeOf(&point).Elem()] = func() interface{} { return suite.Point() }
	cons[reflect.TypeOf(&secret).Elem()] = func() interface{} { return suite.Secret() }
	return protobuf.DecodeWithConstructors(data, v, cons)
}
Example #3
0
func (sm *SigningMessage) UnmarshalBinarySuite(jdata *JSONdata) error {
	suite := GetSuite(jdata.Suite)
	var cons = make(protobuf.Constructors)
	var point abstract.Point
	var secret abstract.Secret
	cons[reflect.TypeOf(&point).Elem()] = func() interface{} { return suite.Point() }
	cons[reflect.TypeOf(&secret).Elem()] = func() interface{} { return suite.Secret() }
	return protobuf.DecodeWithConstructors(jdata.Data, sm, cons)
}
Example #4
0
func ProtobufDecodePointList(bytes []byte) []abstract.Point {
	var aPoint abstract.Point
	var tPoint = reflect.TypeOf(&aPoint).Elem()
	suite := nist.NewAES128SHA256QR512()
	cons := protobuf.Constructors{
		tPoint: func() interface{} { return suite.Point() },
	}

	var msg PointList
	if err := protobuf.DecodeWithConstructors(bytes, &msg, cons); err != nil {
		log.Fatal(err)
	}
	return msg.Points
}
Example #5
0
// UnmarshalRegisteredType returns the type, the data and an error trying to
// decode a message from a buffer.
// The type must be registered to the network library in order to be decodable.
func UnmarshalRegisteredType(buf []byte, constructors protobuf.Constructors) (MessageTypeID, Body, error) {
	b := bytes.NewBuffer(buf)
	var tID MessageTypeID
	if err := binary.Read(b, globalOrder, &tID); err != nil {
		return ErrorType, nil, err
	}
	typ, ok := registry.get(tID)
	if !ok {
		return ErrorType, nil, fmt.Errorf("Type %s not registered.",
			typ.Name())
	}
	ptrVal := reflect.New(typ)
	ptr := ptrVal.Interface()
	if err := protobuf.DecodeWithConstructors(b.Bytes(), ptr, constructors); err != nil {
		return tID, ptrVal.Elem().Interface(), err
	}
	return tID, ptrVal.Elem().Interface(), nil
}