Example #1
0
func (s *SharedSecret) toProto() *panda_proto.KeyExchange_SharedSecret {
	ret := new(panda_proto.KeyExchange_SharedSecret)
	if len(s.Secret) > 0 {
		ret.Secret = proto.String(s.Secret)
	}
	if s.Cards.NumDecks > 0 {
		ret.NumDecks = proto.Int32(int32(s.Cards.NumDecks))
		canonical := s.Cards.Canonicalise()
		ret.CardCount = canonical.counts[:]
	}
	if s.Year != 0 {
		ret.Time = &panda_proto.KeyExchange_SharedSecret_Time{
			Day:     proto.Int32(int32(s.Day)),
			Month:   proto.Int32(int32(s.Month)),
			Year:    proto.Int32(int32(s.Year)),
			Hours:   proto.Int32(int32(s.Hours)),
			Minutes: proto.Int32(int32(s.Minutes)),
		}
	}

	return ret
}
Example #2
0
func newSharedSecret(p *panda_proto.KeyExchange_SharedSecret) (*SharedSecret, bool) {
	ret := &SharedSecret{
		Secret:  p.GetSecret(),
		Day:     int(p.Time.GetDay()),
		Month:   int(p.Time.GetMonth()),
		Year:    int(p.Time.GetYear()),
		Hours:   int(p.Time.GetHours()),
		Minutes: int(p.Time.GetMinutes()),
	}
	ret.Cards.NumDecks = int(p.GetNumDecks())
	if ret.Cards.NumDecks > 0 {
		if len(p.CardCount) != numCards {
			return nil, false
		}
		copy(ret.Cards.counts[:], p.CardCount)
	} else {
		if len(ret.Secret) == 0 {
			return nil, false
		}
	}

	return ret, true
}