public void SetSenderChainKey(ChainKey nextChainKey)
        {
            SessionStructure.Types.Chain.Types.ChainKey chainKey = new SessionStructure.Types.Chain.Types.ChainKey
            {
                Key   = ByteString.CopyFrom(nextChainKey.GetKey()),
                Index = nextChainKey.GetIndex()
            };

            _sessionStructure.SenderChain.ChainKey = chainKey;
        }
        public void SetReceiverChainKey(IEcPublicKey senderEphemeral, ChainKey chainKey)
        {
            Pair <SessionStructure.Types.Chain, uint> chainAndIndex = GetReceiverChain(senderEphemeral);

            SessionStructure.Types.Chain chain = chainAndIndex.First();

            SessionStructure.Types.Chain.Types.ChainKey chainKeyStructure = new SessionStructure.Types.Chain.Types.ChainKey
            {
                Key   = ByteString.CopyFrom(chainKey.GetKey()),
                Index = chainKey.GetIndex()
            };

            chain.ChainKey = chainKeyStructure;

            _sessionStructure.ReceiverChains[(int)chainAndIndex.Second()] = chain;
        }
        public void SetSenderChain(EcKeyPair senderRatchetKeyPair, ChainKey chainKey)
        {
            SessionStructure.Types.Chain.Types.ChainKey chainKeyStructure = new SessionStructure.Types.Chain.Types.ChainKey
            {
                Key   = ByteString.CopyFrom(chainKey.GetKey()),
                Index = chainKey.GetIndex()
            };

            SessionStructure.Types.Chain senderChain = new SessionStructure.Types.Chain
            {
                SenderRatchetKey        = ByteString.CopyFrom(senderRatchetKeyPair.GetPublicKey().Serialize()),
                SenderRatchetKeyPrivate = ByteString.CopyFrom(senderRatchetKeyPair.GetPrivateKey().Serialize()),
                ChainKey = chainKeyStructure
            };

            _sessionStructure.SenderChain = senderChain;
        }
        public void AddReceiverChain(IEcPublicKey senderRatchetKey, ChainKey chainKey)
        {
            SessionStructure.Types.Chain.Types.ChainKey chainKeyStructure = new SessionStructure.Types.Chain.Types.ChainKey
            {
                Key   = ByteString.CopyFrom(chainKey.GetKey()),
                Index = chainKey.GetIndex()
            };

            SessionStructure.Types.Chain chain = new SessionStructure.Types.Chain
            {
                ChainKey         = chainKeyStructure,
                SenderRatchetKey = ByteString.CopyFrom(senderRatchetKey.Serialize())
            };
            _sessionStructure.ReceiverChains.Add(chain);

            while (_sessionStructure.ReceiverChains.Count > 5)
            {
                _sessionStructure.ReceiverChains.RemoveAt(0); //TODO why was here a TODO?
            }
        }
 public ChainKey GetSenderChainKey()
 {
     SessionStructure.Types.Chain.Types.ChainKey chainKeyStructure = _sessionStructure.SenderChain.ChainKey;
     return(new ChainKey(Hkdf.CreateFor(GetSessionVersion()),
                         chainKeyStructure.Key.ToByteArray(), chainKeyStructure.Index));
 }