示例#1
0
        private byte[] decrypt(SessionRecord sessionRecord, WhisperMessage ciphertext)
        {
            lock (SESSION_LOCK)
            {
                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, SignalMessage 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);
            }
        }