public SenderKeyDistributionMessage(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.SenderKeyDistributionMessage distributionMessage = WhisperProtos.SenderKeyDistributionMessage.ParseFrom(message); if (!distributionMessage.HasId || !distributionMessage.HasIteration || !distributionMessage.HasChainKey || !distributionMessage.HasSigningKey) { throw new InvalidMessageException("Incomplete message."); } this.serialized = serialized; this.id = distributionMessage.Id; this.iteration = distributionMessage.Iteration; this.chainKey = distributionMessage.ChainKey.ToByteArray(); this.signatureKey = Curve.decodePoint(distributionMessage.SigningKey.ToByteArray(), 0); } catch (Exception e) { //InvalidProtocolBufferException | InvalidKey throw new InvalidMessageException(e); } }
public SenderKeyDistributionMessage(UInt32 id, UInt32 iteration, byte[] chainKey, ECPublicKey signatureKey) { byte[] version = { ByteUtil.IntsToByteHighAndLow(CURRENT_VERSION, CURRENT_VERSION) }; var protobufObject = new WhisperProtos.SenderKeyDistributionMessage { id = id, iteration = iteration, chainKey = chainKey, signingKey = signatureKey.Serialize() }; byte[] protobuf; using(var stream = new MemoryStream()) { Serializer.Serialize<WhisperProtos.SenderKeyDistributionMessage>(stream, protobufObject); protobuf = stream.ToArray(); } Id = id; Iteration = iteration; ChainKey = chainKey; SignatureKey = signatureKey; _serialized = ByteUtil.Combine(version, protobuf); }