public SenderKeyDistributionMessage(uint id, uint iteration, byte[] chainKey, ECPublicKey signatureKey) { byte[] version = { ByteUtil.intsToByteHighAndLow((int)CURRENT_VERSION, (int)CURRENT_VERSION) }; byte[] protobuf = new SenderKeyDistributionMessage { Id = id, Iteration = iteration, ChainKey = ByteString.CopyFrom(chainKey), SigningKey = ByteString.CopyFrom(signatureKey.serialize()) }.ToByteArray(); this.id = id; this.iteration = iteration; this.chainKey = chainKey; this.signatureKey = signatureKey; this.serialized = ByteUtil.combine(version, protobuf); }
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)); } SenderKeyDistributionMessage distributionMessage = SenderKeyDistributionMessage.Parser.ParseFrom(message); if (distributionMessage.IdOneofCase == IdOneofOneofCase.None || distributionMessage.IterationOneofCase == IterationOneofOneofCase.None || distributionMessage.ChainKeyOneofCase == ChainKeyOneofOneofCase.None || distributionMessage.SigningKeyOneofCase == SigningKeyOneofOneofCase.None) { 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); } }