Esempio n. 1
0
        public SenderMessageKey RemoveSenderMessageKey(uint iteration)
        {
            LinkedList <SenderKeyStateStructure.Types.SenderMessageKey>  keys     = new LinkedList <SenderKeyStateStructure.Types.SenderMessageKey>(senderKeyStateStructure.SenderMessageKeysList);
            IEnumerator <SenderKeyStateStructure.Types.SenderMessageKey> iterator = keys.GetEnumerator(); // iterator();

            SenderKeyStateStructure.Types.SenderMessageKey result = null;

            while (iterator.MoveNext())                                                             // hastNext
            {
                SenderKeyStateStructure.Types.SenderMessageKey senderMessageKey = iterator.Current; // next();

                if (senderMessageKey.Iteration == iteration)                                        //senderMessageKey.getIteration()
                {
                    result = senderMessageKey;
                    keys.Remove(senderMessageKey); //iterator.remove();
                    break;
                }
            }

            this.senderKeyStateStructure = this.senderKeyStateStructure.ToBuilder()
                                           .ClearSenderMessageKeys()
                                           //.AddAllSenderMessageKeys(keys)
                                           .AddRangeSenderMessageKeys(keys)
                                           .Build();

            if (result != null)
            {
                return(new SenderMessageKey(result.Iteration, result.Seed.ToByteArray()));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        private SenderKeyState(uint id, uint iteration, byte[] chainKey,
                               ECPublicKey signatureKeyPublic,
                               May <ECPrivateKey> signatureKeyPrivate)
        {
            SenderKeyStateStructure.Types.SenderChainKey senderChainKeyStructure =
                SenderKeyStateStructure.Types.SenderChainKey.CreateBuilder()
                .SetIteration(iteration)
                .SetSeed(ByteString.CopyFrom(chainKey))
                .Build();

            SenderKeyStateStructure.Types.SenderSigningKey.Builder signingKeyStructure =
                SenderKeyStateStructure.Types.SenderSigningKey.CreateBuilder()
                .SetPublic(ByteString.CopyFrom(signatureKeyPublic.Serialize()));

            if (signatureKeyPrivate.HasValue)
            {
                signingKeyStructure.SetPrivate(ByteString.CopyFrom(signatureKeyPrivate.ForceGetValue().Serialize()));
            }

            this.senderKeyStateStructure = SenderKeyStateStructure.CreateBuilder()
                                           .SetSenderKeyId(id)
                                           .SetSenderChainKey(senderChainKeyStructure)
                                           .SetSenderSigningKey(signingKeyStructure)
                                           .Build();
        }
Esempio n. 3
0
        private SenderKeyState(uint id, uint iteration, byte[] chainKey,
                              ECPublicKey signatureKeyPublic,
                              May<ECPrivateKey> signatureKeyPrivate)
        {
            SenderKeyStateStructure.Types.SenderChainKey senderChainKeyStructure =
                SenderKeyStateStructure.Types.SenderChainKey.CreateBuilder()
                                                      .SetIteration(iteration)
                                                      .SetSeed(ByteString.CopyFrom(chainKey))
                                                      .Build();

            SenderKeyStateStructure.Types.SenderSigningKey.Builder signingKeyStructure =
                SenderKeyStateStructure.Types.SenderSigningKey.CreateBuilder()
                                                        .SetPublic(ByteString.CopyFrom(signatureKeyPublic.serialize()));

            if (signatureKeyPrivate.HasValue)
            {
                signingKeyStructure.SetPrivate(ByteString.CopyFrom(signatureKeyPrivate.ForceGetValue().serialize()));
            }

            this.senderKeyStateStructure = SenderKeyStateStructure.CreateBuilder()
                                                                  .SetSenderKeyId(id)
                                                                  .SetSenderChainKey(senderChainKeyStructure)
                                                                  .SetSenderSigningKey(signingKeyStructure)
                                                                  .Build();
        }
        private SenderKeyState(uint id, uint iteration, byte[] chainKey,
                               IEcPublicKey signatureKeyPublic,
                               May <IEcPrivateKey> signatureKeyPrivate)
        {
            SenderKeyStateStructure.Types.SenderChainKey senderChainKeyStructure = new SenderKeyStateStructure.Types.SenderChainKey
            {
                Iteration = iteration,
                Seed      = ByteString.CopyFrom(chainKey)
            };

            SenderKeyStateStructure.Types.SenderSigningKey signingKeyStructure = new SenderKeyStateStructure.Types.SenderSigningKey
            {
                Public = ByteString.CopyFrom(signatureKeyPublic.Serialize())
            };

            if (signatureKeyPrivate.HasValue)
            {
                signingKeyStructure.Private = ByteString.CopyFrom(signatureKeyPrivate.ForceGetValue().Serialize());
            }

            _senderKeyStateStructure = new SenderKeyStateStructure
            {
                SenderKeyId      = id,
                SenderChainKey   = senderChainKeyStructure,
                SenderSigningKey = signingKeyStructure
            };
        }
Esempio n. 5
0
        public void SetSenderChainKey(SenderChainKey chainKey)
        {
            SenderKeyStateStructure.Types.SenderChainKey senderChainKeyStructure =
                SenderKeyStateStructure.Types.SenderChainKey.CreateBuilder()
                .SetIteration(chainKey.GetIteration())
                .SetSeed(ByteString.CopyFrom(chainKey.GetSeed()))
                .Build();

            this.senderKeyStateStructure = senderKeyStateStructure.ToBuilder()
                                           .SetSenderChainKey(senderChainKeyStructure)
                                           .Build();
        }
Esempio n. 6
0
        public void addSenderMessageKey(SenderMessageKey senderMessageKey)
        {
            SenderKeyStateStructure.Types.SenderMessageKey senderMessageKeyStructure =
                SenderKeyStateStructure.Types.SenderMessageKey.CreateBuilder()
                .SetIteration(senderMessageKey.getIteration())
                .SetSeed(ByteString.CopyFrom(senderMessageKey.getSeed()))
                .Build();

            this.senderKeyStateStructure = this.senderKeyStateStructure.ToBuilder()
                                           .AddSenderMessageKeys(senderMessageKeyStructure)
                                           .Build();
        }
Esempio n. 7
0
        public void setSenderChainKey(SenderChainKey chainKey)
        {
            SenderKeyStateStructure.Types.SenderChainKey senderChainKeyStructure =
                SenderKeyStateStructure.Types.SenderChainKey.CreateBuilder()
                                                      .SetIteration(chainKey.getIteration())
                                                      .SetSeed(ByteString.CopyFrom(chainKey.getSeed()))
                                                      .Build();

            this.senderKeyStateStructure = senderKeyStateStructure.ToBuilder()
                                                                  .SetSenderChainKey(senderChainKeyStructure)
                                                                  .Build();
        }
Esempio n. 8
0
        public void AddSenderMessageKey(SenderMessageKey senderMessageKey)
        {
            SenderKeyStateStructure.Types.SenderMessageKey senderMessageKeyStructure =
                SenderKeyStateStructure.Types.SenderMessageKey.CreateBuilder()
                .SetIteration(senderMessageKey.GetIteration())
                .SetSeed(ByteString.CopyFrom(senderMessageKey.GetSeed()))
                .Build();

            SenderKeyStateStructure.Builder builder = this.senderKeyStateStructure.ToBuilder();
            builder.AddSenderMessageKeys(senderMessageKeyStructure);

            if (builder.SenderMessageKeysList.Count > MAX_MESSAGE_KEYS)
            {
                builder.SenderMessageKeysList.RemoveAt(0);
            }
            this.senderKeyStateStructure = builder.Build();
        }
Esempio n. 9
0
 public SenderKeyState(SenderKeyStateStructure senderKeyStateStructure)
 {
     this.senderKeyStateStructure = senderKeyStateStructure;
 }
Esempio n. 10
0
 public SenderKeyState(SenderKeyStateStructure senderKeyStateStructure)
 {
     this.senderKeyStateStructure = senderKeyStateStructure;
 }
Esempio n. 11
0
        public SenderMessageKey removeSenderMessageKey(uint iteration)
        {
            LinkedList<SenderKeyStateStructure.Types.SenderMessageKey> keys = new LinkedList<SenderKeyStateStructure.Types.SenderMessageKey>(senderKeyStateStructure.SenderMessageKeysList);
            IEnumerator<SenderKeyStateStructure.Types.SenderMessageKey> iterator = keys.GetEnumerator(); // iterator();

            SenderKeyStateStructure.Types.SenderMessageKey result = null;

            while (iterator.MoveNext()) // hastNext
            {
                SenderKeyStateStructure.Types.SenderMessageKey senderMessageKey = iterator.Current; // next();

                if (senderMessageKey.Iteration == iteration) //senderMessageKey.getIteration()
                {
                    result = senderMessageKey;
                    keys.Remove(senderMessageKey); //iterator.remove();
                    break;
                }
            }

            this.senderKeyStateStructure = this.senderKeyStateStructure.ToBuilder()
                                                                       .ClearSenderMessageKeys()
                                                                       //.AddAllSenderMessageKeys(keys)
                                                                       .AddRangeSenderMessageKeys(keys)
                                                                       .Build();

            if (result != null)
            {
                return new SenderMessageKey(result.Iteration, result.Seed.ToByteArray());
            }
            else
            {
                return null;
            }
        }
Esempio n. 12
0
        public void addSenderMessageKey(SenderMessageKey senderMessageKey)
        {
            SenderKeyStateStructure.Types.SenderMessageKey senderMessageKeyStructure =
                SenderKeyStateStructure.Types.SenderMessageKey.CreateBuilder()
                                                        .SetIteration(senderMessageKey.getIteration())
                                                        .SetSeed(ByteString.CopyFrom(senderMessageKey.getSeed()))
                                                        .Build();

            this.senderKeyStateStructure = this.senderKeyStateStructure.ToBuilder()
                                                                       .AddSenderMessageKeys(senderMessageKeyStructure)
                                                                       .Build();
        }
		public void addSenderMessageKey(SenderMessageKey senderMessageKey)
		{
			SenderKeyStateStructure.Types.SenderMessageKey senderMessageKeyStructure =
				SenderKeyStateStructure.Types.SenderMessageKey.CreateBuilder()
														.SetIteration(senderMessageKey.getIteration())
														.SetSeed(ByteString.CopyFrom(senderMessageKey.getSeed()))
														.Build();

			SenderKeyStateStructure.Builder builder = this.senderKeyStateStructure.ToBuilder();
			builder.AddSenderMessageKeys(senderMessageKeyStructure);

			if (builder.SenderMessageKeysList.Count > MAX_MESSAGE_KEYS)
			{
				builder.SenderMessageKeysList.RemoveAt(0);
			}
			this.senderKeyStateStructure = builder.Build();
		}