Пример #1
0
            public Task <HandOverToPhase2> Phase1Async(HandOverToPhase1 fromPhaseOne)
            {
                if (this.Phase != PhaseState.Phase1)
                {
                    throw new InvalidOperationException();
                }
                this.Phase = PhaseState.Phase2;

                return(Task.Run(() =>
                {
                    if (!fromPhaseOne.Map.DeepEquals(this.parent.PrototypeMap))
                    {
                        throw new ArgumentException("Using diferent Maps");
                    }

                    var result = new HandOverToPhase2()
                    {
                        Nodes = new NodeToPhase2[fromPhaseOne.Nodes.Length]
                    };

                    for (int i = 0; i < result.Nodes.Length; i++)
                    {
                        var item = fromPhaseOne.Nodes[i];
                        var cn = this.parent.prototypeIdLookup[item.PrototypeIdNode];
                        var ownExponented = cn.TrueNode.Initilize.Phase1(item.Value);
                        result.Nodes[i] = new NodeToPhase2()
                        {
                            OtherExponented = ownExponented, PrototypeIdNode = cn.PrototypeNode.id
                        };
                    }
                    return result;
                }));
            }
Пример #2
0
            public Task Phase2Async(HandOverToPhase2 fromPhaseTwo)
            {
                if (this.Phase != PhaseState.Phase2)
                {
                    throw new InvalidOperationException();
                }

                return(Task.Run(() =>
                {
                    foreach (var item in fromPhaseTwo.Nodes)
                    {
                        var cn = this.parent.prototypeIdLookup[item.PrototypeIdNode];
                        cn.TrueNode.Initilize.Phase2(item.OtherExponented);
                    }
                    this.parent.CryptoLookup = this.parent.generatedCryptoNodes.ToDictionary(x => x.TrueNode.Z);

                    this.Phase = PhaseState.Finished;
                }));
            }