Пример #1
0
        private byte[] Decrypt(SessionRecord sessionRecord, SignalMessage ciphertext)
        {
            lock (SessionLock)
            {
                IEnumerator <SessionState> previousStates = sessionRecord.GetPreviousSessionStates().GetEnumerator();                //iterator
                LinkedList <Exception>     exceptions     = new LinkedList <Exception>();

                try
                {
                    SessionState sessionState = new SessionState(sessionRecord.GetSessionState());
                    byte[]       plaintext    = Decrypt(sessionState, ciphertext);

                    sessionRecord.SetState(sessionState);
                    return(plaintext);
                }
                catch (InvalidMessageException e)
                {
                    exceptions.AddLast(e);                     // add (java default behavioir addlast)
                }

                while (previousStates.MoveNext())                 //hasNext();
                {
                    try
                    {
                        SessionState promotedState = new SessionState(previousStates.Current);                         //.next()
                        byte[]       plaintext     = Decrypt(promotedState, ciphertext);

                        sessionRecord.GetPreviousSessionStates().Remove(previousStates.Current);                         // previousStates.remove()
                        sessionRecord.PromoteState(promotedState);

                        return(plaintext);
                    }
                    catch (InvalidMessageException e)
                    {
                        exceptions.AddLast(e);
                    }
                }

                throw new InvalidMessageException("No valid sessions.", exceptions);
            }
        }
Пример #2
0
        private byte[] Decrypt(SessionRecord sessionRecord, WhisperMessage ciphertext)
        {
            lock (SESSION_LOCK)
            {
                IEnumerator <SessionState> previousStates = sessionRecord.GetPreviousSessionStates().GetEnumerator();
                LinkedList <Exception>     exceptions     = new LinkedList <Exception>();

                try
                {
                    SessionState sessionState = new SessionState(sessionRecord.GetSessionState());
                    byte[]       plaintext    = Decrypt(sessionState, ciphertext);

                    sessionRecord.SetState(sessionState);
                    return(plaintext);
                }
                catch (InvalidMessageException e)
                {
                    exceptions.AddLast(e);
                }

                while (previousStates.MoveNext())
                {
                    try
                    {
                        SessionState promotedState = new SessionState(previousStates.Current);
                        byte[]       plaintext     = Decrypt(promotedState, ciphertext);

                        sessionRecord.GetPreviousSessionStates().Remove(previousStates.Current);
                        sessionRecord.PromoteState(promotedState);

                        return(plaintext);
                    }
                    catch (InvalidMessageException e)
                    {
                        exceptions.AddLast(e);
                    }
                }

                throw new InvalidMessageException("No valid sessions.", exceptions);
            }
        }