/**
 * Copyright 2013 Tim Whittington
 *
 * Licensed under the The Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.archie.groktls.impl.cipher;

import org.archie.groktls.cipher.Cipher;
import org.archie.groktls.cipher.CipherSuite;
import org.archie.groktls.cipher.KeyExchange;
import org.archie.groktls.cipher.Mac;

class CipherSuiteImpl implements CipherSuite {

    private final KeyExchange keyExchange;
    private final CipherImpl cipher;
    private final MacImpl mac;
    private final String name;
    private final boolean signalling;

    public CipherSuiteImpl(final String name, final KeyExchangeImpl keyExchange, final CipherImpl cipher, final MacImpl mac) {
        this.name = name;
        this.keyExchange = keyExchange;
        this.cipher = cipher;
        this.mac = mac;
        this.signalling = false;
    }

    public CipherSuiteImpl(final String signallingCipherSuite) {
        this.name = signallingCipherSuite;
        this.keyExchange = null;
        this.cipher = null;
        this.mac = null;
        this.signalling = true;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public boolean isSignalling() {
        return this.signalling;
    }

    @Override
    public KeyExchange getKeyExchange() {
        return this.keyExchange;
    }

    @Override
    public Cipher getCipher() {
        return this.cipher;
    }

    @Override
    public Mac getMac() {
        return this.mac;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = (prime * result) + ((this.name == null) ? 0 : this.name.hashCode());
        return result;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CipherSuiteImpl other = (CipherSuiteImpl) obj;
        if (this.name == null) {
            if (other.name != null) {
                return false;
            }
        } else if (!this.name.equals(other.name)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.name;
    }

}

@@ -996,24 +996,65 @@
 tring name;%0A
+    private final String normalisedName;%0A
     private 
@@ -1229,24 +1229,71 @@
 ame = name;%0A
+        this.normalisedName = normalise(name);%0A
         this
@@ -1410,24 +1410,219 @@
 lse;%0A    %7D%0A%0A
+    private static String normalise(final String name) %7B%0A        if (name.startsWith(%22SSL_%22)) %7B%0A            return %22TLS_%22 + name.substring(%22SSL_%22.length());%0A        %7D%0A        return name;%0A    %7D%0A%0A
     public C
@@ -1717,16 +1717,69 @@
 rSuite;%0A
+        this.normalisedName = signallingCipherSuite;%0A
         
@@ -2446,24 +2446,34 @@
 ) + ((this.n
+ormalisedN
 ame == null)
@@ -2481,24 +2481,34 @@
 ? 0 : this.n
+ormalisedN
 ame.hashCode
@@ -2882,24 +2882,34 @@
   if (this.n
+ormalisedN
 ame == null)
@@ -2934,16 +2934,26 @@
 (other.n
+ormalisedN
 ame != n
@@ -3033,26 +3033,56 @@
 is.n
-ame.equals(other.n
+ormalisedName.equalsIgnoreCase(other.normalisedN
 ame)

Normalise parsed names to comparisons of cipher-suites with non-standard prefixes work.