예제 #1
0
        public SenderKeyGroupData(byte[] serialized)
        {
            try
            {
                byte[][] messageParts = ByteUtil.Split(serialized, 1, serialized.Length - 1);
                byte     version      = messageParts[0][0];
                byte[]   message      = messageParts[1];

                if (ByteUtil.HighBitsToInt(version) < CipherTextMessage.CURRENT_VERSION)
                {
                    throw new LegacyMessageException("Legacy message: " + ByteUtil.HighBitsToInt(version));
                }

                if (ByteUtil.HighBitsToInt(version) > CURRENT_VERSION)
                {
                    throw new InvalidMessageException("Unknown version: " + ByteUtil.HighBitsToInt(version));
                }

                WhisperProtos.SenderKeyGroupData senderKeyGroupMessage = WhisperProtos.SenderKeyGroupData.ParseFrom(message);

                if (!senderKeyGroupMessage.HasMessage ||
                    !senderKeyGroupMessage.HasSenderKey)
                {
                    throw new InvalidMessageException("Incomplete message.");
                }

                this.serialized = serialized;
                this.message    = senderKeyGroupMessage.Message.ToByteArray();
                this.senderKey  = new SenderKeyGroupMessage(senderKeyGroupMessage.SenderKey.ToByteArray());
            }
            catch (Exception e)
            {
                throw new InvalidMessageException(e);
            }
        }
예제 #2
0
        public SenderKeyGroupData(byte[] message, SenderKeyGroupMessage senderKey)
        {
            byte[] version = { ByteUtil.IntsToByteHighAndLow((int)CURRENT_VERSION, (int)CURRENT_VERSION) };

            WhisperProtos.SenderKeyGroupMessage wSenderKey = WhisperProtos.SenderKeyGroupMessage.CreateBuilder()
                                                             .SetGroupId(ByteString.CopyFrom(senderKey.GetGroupId()))
                                                             .SetSenderKey(ByteString.CopyFrom(senderKey.GetSenderKey()))
                                                             .Build();

            byte[] protobuf = WhisperProtos.SenderKeyGroupData.CreateBuilder()
                              .SetMessage(ByteString.CopyFrom(message))
                              .SetSenderKey(wSenderKey)
                              .Build().ToByteArray();

            this.message    = message;
            this.senderKey  = senderKey;
            this.serialized = ByteUtil.Combine(version, protobuf);
        }